setup sub package builds

This commit is contained in:
John Murray 2023-11-14 22:47:43 -05:00
parent 3179773d90
commit 07e06e60f5
No known key found for this signature in database
3 changed files with 22 additions and 14 deletions

View file

@ -156,10 +156,10 @@
# You can build this package (the roc CLI) with the `nix build` command. # You can build this package (the roc CLI) with the `nix build` command.
packages = { packages = {
default = rocBuild.roc-cli; default = rocBuild.roc-full;
full = rocBuild.roc-full;
cli = rocBuild.roc-cli; cli = rocBuild.roc-cli;
lang-server = rocBuild.roc-lang-server; lang-server = rocBuild.roc-lang-server;
}; };
}); });

View file

@ -1,12 +1,14 @@
{ pkgs, rustPlatform, compile-deps, subPackage ? null }: { pkgs, lib, rustPlatform, compile-deps, subPackage ? null }:
let let
inherit (compile-deps) zigPkg llvmPkgs llvmVersion llvmMajorMinorStr glibcPath libGccSPath; inherit (compile-deps) zigPkg llvmPkgs llvmVersion llvmMajorMinorStr glibcPath libGccSPath;
subPackagePath = if subPackage != null then "crates/${subPackage}" else null;
in in
rustPlatform.buildRustPackage { rustPlatform.buildRustPackage {
pname = "roc"; pname = "roc" + lib.optionalString (subPackage != null) "_${subPackage}";
version = "0.0.1"; version = "0.0.1";
buildAndTestSubdir = subPackage; buildAndTestSubdir = subPackagePath;
src = pkgs.nix-gitignore.gitignoreSource [ ] ../.; src = pkgs.nix-gitignore.gitignoreSource [ ] ../.;
@ -68,13 +70,18 @@ rustPlatform.buildRustPackage {
# cp: to copy str.zig,list.zig... # cp: to copy str.zig,list.zig...
# wrapProgram pkgs.stdenv.cc: to make ld available for compiler/build/src/link.rs # wrapProgram pkgs.stdenv.cc: to make ld available for compiler/build/src/link.rs
postInstall = postInstall =
if pkgs.stdenv.isLinux then '' let
wrapProgram $out/bin/roc --set NIX_GLIBC_PATH ${glibcPath} --set NIX_LIBGCC_S_PATH ${libGccSPath} --prefix PATH : ${ binPath =
pkgs.lib.makeBinPath [ pkgs.stdenv.cc ] lib.makeBinPath [ pkgs.stdenv.cc ];
} linuxArgs = lib.optionalString pkgs.stdenv.isLinux
'' else '' "--set NIX_GLIBC_PATH ${glibcPath} --set NIX_LIBGCC_S_PATH ${libGccSPath}";
wrapProgram $out/bin/roc --prefix PATH : ${ rocPath = "$out/bin/roc";
pkgs.lib.makeBinPath [ pkgs.stdenv.cc ] 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
''; '';
} }

View file

@ -16,8 +16,9 @@ let
rust-shell = rust-shell =
(rustVersion.override { extensions = [ "rust-src" "rust-analyzer" ]; }); (rustVersion.override { extensions = [ "rust-src" "rust-analyzer" ]; });
roc-cli = callPackage ./builder.nix { }; # TODO: this builds the language server as `roc_ls` roc-full = callPackage ./builder.nix { };
roc-lang-server = callPackage ./builder.nix { subPackage = "lang_srv"; }; roc-lang-server = callPackage ./builder.nix { subPackage = "lang_srv"; };
roc-cli = callPackage ./builder.nix { subPackage = "cli"; };
}; };
in in