diff --git a/.github/workflows/release-artifacts.yaml b/.github/workflows/release-artifacts.yaml index 54e149e39..4e23e2cb2 100644 --- a/.github/workflows/release-artifacts.yaml +++ b/.github/workflows/release-artifacts.yaml @@ -103,12 +103,15 @@ jobs: run: | nix build --log-format raw-with-logs .#nickel-static cp ./result/bin/nickel nickel-${{ matrix.os.architecture }}-linux + nix build --log-format raw-with-logs .#nickel-lang-lsp-static + cp ./result/bin/nls nls-${{ matrix.os.architecture }}-linux - name: "Upload static binary as release asset" env: GH_TOKEN: ${{ github.token }} RELEASE_TAG: ${{ github.event_name == 'release' && github.event.release.tag_name || github.event.inputs.release_tag }} run: | gh release upload --clobber $RELEASE_TAG nickel-${{ matrix.os.architecture }}-linux + gh release upload --clobber $RELEASE_TAG nls-${{ matrix.os.architecture }}-linux - id: build-image name: "Build docker image" run: | diff --git a/flake.nix b/flake.nix index 9a8a7abc2..a56af7a4c 100644 --- a/flake.nix +++ b/flake.nix @@ -360,6 +360,31 @@ cargoExtraArgs = "${cargoBuildExtraArgs} ${extraBuildArgs} --package ${cargoPackage}"; } // extraArgs); + # To build Nickel and its dependencies statically we use the musl + # libc and clang with libc++ to build C and C++ dependencies. We + # tried building with libstdc++ but without success. + buildStaticPackage = { pnameSuffix, cargoPackage, extraBuildArgs ? "", extraArgs ? { } }: + (buildPackage { + inherit pnameSuffix cargoPackage; + extraArgs = { + inherit env; + CARGO_BUILD_TARGET = pkgs.pkgsMusl.stdenv.hostPlatform.rust.rustcTarget; + # For some reason, the rust build doesn't pick up the paths + # to `libcxx`. So we specify them explicitly. + # + # We also explicitly add `libc` because of + # https://github.com/rust-lang/rust/issues/89626. + RUSTFLAGS = "-L${pkgs.pkgsMusl.llvmPackages.libcxx}/lib -lstatic=c++abi -C link-arg=-lc"; + # Explain to `cc-rs` that it should use the `libcxx` C++ + # standard library, and a static version of it, when building + # C++ libraries. The `cc-rs` crate is typically used in + # upstream build.rs scripts. + CXXSTDLIB = "static=c++"; + stdenv = pkgs.pkgsMusl.libcxxStdenv; + doCheck = false; + } // extraArgs; + }); + # In addition to external dependencies, we build the lalrpop file in a # separate derivation because it's expensive to build but needs to be # rebuilt infrequently. @@ -412,32 +437,21 @@ if pkgs.stdenv.hostPlatform.isMacOS then nickel-lang-cli else - # To build Nickel and its dependencies statically we use the musl - # libc and clang with libc++ to build C and C++ dependencies. We - # tried building with libstdc++ but without success. - fixupGitRevision - (buildPackage { - cargoPackage = "nickel-lang-cli"; - pnameSuffix = "-static"; - extraArgs = { - inherit env; - CARGO_BUILD_TARGET = pkgs.pkgsMusl.stdenv.hostPlatform.rust.rustcTarget; - # For some reason, the rust build doesn't pick up the paths - # to `libcxx`. So we specify them explicitly. - # - # We also explicitly add `libc` because of - # https://github.com/rust-lang/rust/issues/89626. - RUSTFLAGS = "-L${pkgs.pkgsMusl.llvmPackages.libcxx}/lib -lstatic=c++abi -C link-arg=-lc"; - # Explain to `cc-rs` that it should use the `libcxx` C++ - # standard library, and a static version of it, when building - # C++ libraries. The `cc-rs` crate is typically used in - # upstream build.rs scripts. - CXXSTDLIB = "static=c++"; - stdenv = pkgs.pkgsMusl.libcxxStdenv; - doCheck = false; - meta.mainProgram = "nickel"; - }; - }); + fixupGitRevision (buildStaticPackage { + cargoPackage = "nickel-lang-cli"; + pnameSuffix = "-static"; + extraArgs = { meta.mainProgram = "nickel"; }; + }); + + nickel-lang-lsp-static = + if pkgs.stdenv.hostPlatform.isMacOS + then nickel-lang-lsp + else + fixupGitRevision (buildStaticPackage { + cargoPackage = "nickel-lang-lsp"; + pnameSuffix = "-static"; + extraArgs = { meta.mainProgram = "nls"; }; + }); benchmarks = craneLib.mkCargoDerivation { inherit pname src version cargoArtifacts env; @@ -695,7 +709,7 @@ stdlibMarkdown = stdlibDoc "markdown"; stdlibJson = stdlibDoc "json"; } // pkgs.lib.optionalAttrs (!pkgs.stdenv.hostPlatform.isDarwin) { - inherit (mkCraneArtifacts { }) nickel-static; + inherit (mkCraneArtifacts { }) nickel-static nickel-lang-lsp-static; # Use the statically linked binary for the docker image if we're not on MacOS. dockerImage = buildDocker packages.nickel-static; };