Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Include a release artifact for nls #2139

Merged
merged 1 commit into from
Jan 22, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions .github/workflows/release-artifacts.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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: |
Expand Down
68 changes: 41 additions & 27 deletions flake.nix
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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;
};
Expand Down
Loading