Skip to content

Commit

Permalink
Merge pull request #6942 from roc-lang/roc-nix-debug
Browse files Browse the repository at this point in the history
expose roc debug compiler in nix
  • Loading branch information
Anton-4 committed Jul 30, 2024
2 parents 5eba26e + 0b9c6ff commit c59de3c
Show file tree
Hide file tree
Showing 5 changed files with 103 additions and 87 deletions.
10 changes: 5 additions & 5 deletions devtools/flake.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 3 additions & 0 deletions flake.nix
Original file line number Diff line number Diff line change
Expand Up @@ -150,7 +150,10 @@
full = rocBuild.roc-full;
# only the CLI crate = executable provided in nightly releases
cli = rocBuild.roc-cli;
cli-debug = rocBuild.roc-cli-debug;

lang-server = rocBuild.roc-lang-server;
lang-server-debug = rocBuild.roc-lang-server-debug;
};

apps = {
Expand Down
162 changes: 84 additions & 78 deletions nix/builder.nix
Original file line number Diff line number Diff line change
Expand Up @@ -5,92 +5,98 @@ let
subPackagePath = if subPackage != null then "crates/${subPackage}" else null;
mainBin = if subPackage == "language_server" then "roc_language_server" else "roc";
filteredSource = pkgs.callPackage ./fileFilter.nix { };
in
rustPlatform.buildRustPackage {
pname = "roc" + lib.optionalString (subPackage != null) "_${subPackage}";
version = "0.0.1";
buildRoc = buildTypeStr:
rustPlatform.buildRustPackage {
pname = "roc" + lib.optionalString (subPackage != null) "_${subPackage}";
version = "0.0.1";
buildType = buildTypeStr;

buildAndTestSubdir = subPackagePath;
buildAndTestSubdir = subPackagePath;

src = filteredSource;
src = filteredSource;

cargoLock = {
lockFile = ../Cargo.lock;
outputHashes = {
"criterion-0.3.5" = "sha256-+FibPQGiR45g28xCHcM0pMN+C+Q8gO8206Wb5fiTy+k=";
"inkwell-0.2.0" = "sha256-VhTapYGonoSQ4hnDoLl4AAgj0BppAhPNA+UPuAJSuAU=";
"plotters-0.3.1" = "sha256-noy/RSjoEPZZbOJTZw1yxGcX5S+2q/7mxnUrzDyxOFw=";
"rustyline-9.1.1" = "sha256-aqQqz6nSp+Qn44gm3jXmmQUO6/fYTx7iLph2tbA24Bs=";
};
};
cargoLock = {
lockFile = ../Cargo.lock;
outputHashes = {
"criterion-0.3.5" = "sha256-+FibPQGiR45g28xCHcM0pMN+C+Q8gO8206Wb5fiTy+k=";
"inkwell-0.2.0" = "sha256-VhTapYGonoSQ4hnDoLl4AAgj0BppAhPNA+UPuAJSuAU=";
"plotters-0.3.1" = "sha256-noy/RSjoEPZZbOJTZw1yxGcX5S+2q/7mxnUrzDyxOFw=";
"rustyline-9.1.1" = "sha256-aqQqz6nSp+Qn44gm3jXmmQUO6/fYTx7iLph2tbA24Bs=";
};
};

shellHook = ''
export LLVM_SYS_${llvmMajorMinorStr}_PREFIX="${llvmPkgs.llvm.dev}"
'';
shellHook = ''
export LLVM_SYS_${llvmMajorMinorStr}_PREFIX="${llvmPkgs.llvm.dev}"
'';

# required for zig
XDG_CACHE_HOME =
"xdg_cache"; # prevents zig AccessDenied error github.com/ziglang/zig/issues/6810
# want to see backtrace in case of failure
RUST_BACKTRACE = 1;
# required for zig
XDG_CACHE_HOME =
"xdg_cache"; # prevents zig AccessDenied error github.com/ziglang/zig/issues/6810
# want to see backtrace in case of failure
RUST_BACKTRACE = 1;

# skip running rust tests, problems:
# building of example platforms requires network: Could not resolve host
# zig AccessDenied error github.com/ziglang/zig/issues/6810
# Once instance has previously been poisoned ??
doCheck = false;
# skip running rust tests, problems:
# building of example platforms requires network: Could not resolve host
# zig AccessDenied error github.com/ziglang/zig/issues/6810
# Once instance has previously been poisoned ??
doCheck = false;

nativeBuildInputs = (with pkgs; [
cmake
git
pkg-config
python3
llvmPkgs.clang
llvmPkgs.llvm.dev
llvmPkgs.bintools-unwrapped # contains lld
zigPkg
]);
nativeBuildInputs = (with pkgs; [
cmake
git
pkg-config
python3
llvmPkgs.clang
llvmPkgs.llvm.dev
llvmPkgs.bintools-unwrapped # contains lld
zigPkg
]);

buildInputs = (with pkgs;
[
libffi
libxml2
ncurses
zlib
cargo
makeWrapper # necessary for postBuild wrapProgram
] ++ lib.optionals pkgs.stdenv.isDarwin
(with pkgs.darwin.apple_sdk.frameworks;
[
AppKit
CoreFoundation
CoreServices
Foundation
Security
]));
buildInputs = (with pkgs;
[
libffi
libxml2
ncurses
zlib
cargo
makeWrapper # necessary for postBuild wrapProgram
] ++ lib.optionals pkgs.stdenv.isDarwin
(with pkgs.darwin.apple_sdk.frameworks;
[
AppKit
CoreFoundation
CoreServices
Foundation
Security
]));

# cp: to copy str.zig,list.zig...
# wrapProgram pkgs.stdenv.cc: to make ld available for compiler/build/src/link.rs
postInstall =
let
binPath =
lib.makeBinPath [ pkgs.stdenv.cc ];
linuxArgs = lib.optionalString pkgs.stdenv.isLinux
"--set NIX_GLIBC_PATH ${glibcPath} --set NIX_LIBGCC_S_PATH ${libGccSPath}";
rocPath = "$out/bin/roc";
wrapRoc = "wrapProgram ${rocPath} ${linuxArgs} --prefix PATH : ${binPath}";
in
# need to check if roc bin exists since it might not if subPackage is set
''
if test -f ${rocPath}; then
${wrapRoc}
fi
'';
# cp: to copy str.zig,list.zig...
# wrapProgram pkgs.stdenv.cc: to make ld available for compiler/build/src/link.rs
postInstall =
let
binPath =
lib.makeBinPath [ pkgs.stdenv.cc ];
linuxArgs = lib.optionalString pkgs.stdenv.isLinux
"--set NIX_GLIBC_PATH ${glibcPath} --set NIX_LIBGCC_S_PATH ${libGccSPath}";
rocPath = "$out/bin/roc";
wrapRoc = "wrapProgram ${rocPath} ${linuxArgs} --prefix PATH : ${binPath}";
in
# need to check if roc bin exists since it might not if subPackage is set
''
if test -f ${rocPath}; then
${wrapRoc}
fi
'';

# https://ryantm.github.io/nixpkgs/stdenv/meta/
meta = {
homepage = "https://www.roc-lang.org/";
license = lib.licenses.upl;
mainProgram = mainBin;
};
# https://ryantm.github.io/nixpkgs/stdenv/meta/
meta = {
homepage = "https://www.roc-lang.org/";
license = lib.licenses.upl;
mainProgram = mainBin;
};
};
in
{
roc-debug = buildRoc "debug";
roc-release = buildRoc "release";
}
13 changes: 9 additions & 4 deletions nix/default.nix
Original file line number Diff line number Diff line change
Expand Up @@ -16,11 +16,16 @@ let
rust-shell =
(rustVersion.override { extensions = [ "rust-src" "rust-analyzer" ]; });

# all rust crates in workspace.members of Cargo.toml
roc-full = callPackage ./builder.nix { };
roc-lang-server = callPackage ./builder.nix { subPackage = "language_server"; };
# contains all rust crates in workspace.members of Cargo.toml
roc-full = (callPackage ./builder.nix { }).roc-release;
roc-full-debug = (callPackage ./builder.nix { }).roc-debug;

roc-lang-server = (callPackage ./builder.nix { subPackage = "language_server"; }).roc-release;
roc-lang-server-debug = (callPackage ./builder.nix { subPackage = "language_server"; }).roc-debug;

# only the CLI crate = executable provided in nightly releases
roc-cli = callPackage ./builder.nix { subPackage = "cli"; };
roc-cli = (callPackage ./builder.nix { subPackage = "cli"; }).roc-release;
roc-cli-debug = (callPackage ./builder.nix { subPackage = "cli"; }).roc-debug;
};

in
Expand Down
2 changes: 2 additions & 0 deletions nix/fileFilter.nix
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,8 @@ let
../Cargo.toml
../Cargo.lock
../version.txt
../rust-toolchain.toml
../.cargo/config.toml
onlyCratesFolder
];

Expand Down

0 comments on commit c59de3c

Please sign in to comment.