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

build-support/rust: add cargoPurityFlag parameter #187838

Closed
wants to merge 3 commits into from
Closed
Show file tree
Hide file tree
Changes from 1 commit
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
6 changes: 6 additions & 0 deletions pkgs/build-support/rust/build-rust-package/default.nix
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
, cacert
, git
, cargoBuildHook
, cargoBuildHookOffline
, cargoCheckHook
, cargoInstallHook
, cargoNextestHook
Expand Down Expand Up @@ -43,6 +44,7 @@
, checkFeatures ? buildFeatures
, useNextest ? false
, depsExtraArgs ? {}
, cargoPurityFlag ? "--frozen"

# Toggles whether a custom sysroot is created when the target is a .json file.
, __internal_dontAddSysroot ? false
Expand Down Expand Up @@ -119,6 +121,10 @@ stdenv.mkDerivation ((removeAttrs args [ "depsExtraArgs" "cargoUpdateHook" "carg
cacert
git
cargoBuildHook
({ "--frozen" = cargoBuildHook;
"--offline" = cargoBuildHookOffline;
}.${cargoPurityFlag}
or (throw "unrecognized cargoPurityFlag \"${cargoPurityFlag}\""))
(if useNextest then cargoNextestHook else cargoCheckHook)
cargoInstallHook
cargoSetupHook
Expand Down
2 changes: 1 addition & 1 deletion pkgs/build-support/rust/hooks/cargo-build-hook.sh
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ cargoBuildHook() {
"CXX_@rustTargetPlatform@=@cxxForHost@" \
cargo build -j $NIX_BUILD_CORES \
--target @rustTargetPlatformSpec@ \
--frozen \
@cargoPurityFlag@ \
${cargoBuildProfileFlag} \
${cargoBuildNoDefaultFeaturesFlag} \
${cargoBuildFeaturesFlag} \
Expand Down
19 changes: 16 additions & 3 deletions pkgs/build-support/rust/hooks/default.nix
Original file line number Diff line number Diff line change
Expand Up @@ -27,16 +27,29 @@ let
rustBuildPlatform = rust.toRustTarget stdenv.buildPlatform;
rustTargetPlatform = rust.toRustTarget stdenv.hostPlatform;
rustTargetPlatformSpec = rust.toRustTargetSpec stdenv.hostPlatform;
in {
cargoBuildHook = callPackage ({ }:
cargoBuildHookFlexible = { cargoPurityFlag }: callPackage ({ }:
makeSetupHook {
name = "cargo-build-hook.sh";
deps = [ cargo ];
substitutions = {
inherit ccForBuild ccForHost cxxForBuild cxxForHost
inherit ccForBuild ccForHost cxxForBuild cxxForHost cargoPurityFlag
rustBuildPlatform rustTargetPlatform rustTargetPlatformSpec;
};
} ./cargo-build-hook.sh) {};
in {

# "requires that the Cargo.lock file is up-to-date. If the lock file
# is missing, or it needs to be updated, Cargo will exit with an
# error. The --frozen flag also prevents Cargo from attempting to
# access the network to determine if it is out-of-date."
cargoBuildHook = cargoBuildHookFlexible { cargoPurityFlag = "--frozen"; };

# "Prevents Cargo from accessing the network for any reason. Beware
# that this may result in different dependency resolution than
# online mode. Cargo will restrict itself to crates that are
# downloaded locally, even if there might be a newer version as
# indicated in the local copy of the index."
cargoBuildHookOffline = cargoBuildHookFlexible { cargoPurityFlag = "--offline"; };

cargoCheckHook = callPackage ({ }:
makeSetupHook {
Expand Down
4 changes: 2 additions & 2 deletions pkgs/development/compilers/rust/make-rust-platform.nix
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ rec {

buildRustPackage = callPackage ../../../build-support/rust/build-rust-package {
git = buildPackages.gitMinimal;
inherit stdenv cargoBuildHook cargoCheckHook cargoInstallHook cargoNextestHook cargoSetupHook
inherit stdenv cargoBuildHook cargoBuildHookOffline cargoCheckHook cargoInstallHook cargoNextestHook cargoSetupHook
fetchCargoTarball importCargoLock rustc;
};

Expand All @@ -31,5 +31,5 @@ rec {
# Hooks
inherit (callPackage ../../../build-support/rust/hooks {
inherit stdenv cargo rustc;
}) cargoBuildHook cargoCheckHook cargoInstallHook cargoNextestHook cargoSetupHook maturinBuildHook bindgenHook;
}) cargoBuildHook cargoBuildHookOffline cargoCheckHook cargoInstallHook cargoNextestHook cargoSetupHook maturinBuildHook bindgenHook;
}