Carnix: 0.7.2 -> 0.8.10 (#40587)
Carnix: splits input into two parts: creates from creates.io and local ones
This commit is contained in:
parent
a3e367ff4b
commit
ae3b4655a4
@ -2,7 +2,7 @@
|
|||||||
{ crateName,
|
{ crateName,
|
||||||
dependencies,
|
dependencies,
|
||||||
crateFeatures, libName, release, libPath,
|
crateFeatures, libName, release, libPath,
|
||||||
crateType, metadata, crateBin,
|
crateType, metadata, crateBin, hasCrateBin,
|
||||||
extraRustcOpts, verbose, colors }:
|
extraRustcOpts, verbose, colors }:
|
||||||
|
|
||||||
let
|
let
|
||||||
@ -13,6 +13,17 @@
|
|||||||
(if release then "-C opt-level=3" else "-C debuginfo=2")
|
(if release then "-C opt-level=3" else "-C debuginfo=2")
|
||||||
(["-C codegen-units=1"] ++ extraRustcOpts);
|
(["-C codegen-units=1"] ++ extraRustcOpts);
|
||||||
rustcMeta = "-C metadata=${metadata} -C extra-filename=-${metadata}";
|
rustcMeta = "-C metadata=${metadata} -C extra-filename=-${metadata}";
|
||||||
|
|
||||||
|
# Some platforms have different names for rustc.
|
||||||
|
rustPlatform =
|
||||||
|
with stdenv.hostPlatform.parsed;
|
||||||
|
let cpu_ = if cpu.name == "armv7a" then "armv7"
|
||||||
|
else cpu.name;
|
||||||
|
vendor_ = vendor.name;
|
||||||
|
kernel_ = kernel.name;
|
||||||
|
abi_ = abi.name;
|
||||||
|
in
|
||||||
|
"${cpu_}-${vendor_}-${kernel_}-${abi_}";
|
||||||
in ''
|
in ''
|
||||||
runHook preBuild
|
runHook preBuild
|
||||||
norm=""
|
norm=""
|
||||||
@ -32,7 +43,8 @@
|
|||||||
lib_src=$1
|
lib_src=$1
|
||||||
echo_build_heading $lib_src ${libName}
|
echo_build_heading $lib_src ${libName}
|
||||||
|
|
||||||
noisily rustc --crate-name $CRATE_NAME $lib_src --crate-type ${crateType} \
|
noisily rustc --crate-name $CRATE_NAME $lib_src \
|
||||||
|
${lib.strings.concatStrings (map (x: " --crate-type ${x}") crateType)} \
|
||||||
${rustcOpts} ${rustcMeta} ${crateFeatures} --out-dir target/lib \
|
${rustcOpts} ${rustcMeta} ${crateFeatures} --out-dir target/lib \
|
||||||
--emit=dep-info,link -L dependency=target/deps ${deps} --cap-lints allow \
|
--emit=dep-info,link -L dependency=target/deps ${deps} --cap-lints allow \
|
||||||
$BUILD_OUT_DIR $EXTRA_BUILD $EXTRA_FEATURES --color ${colors}
|
$BUILD_OUT_DIR $EXTRA_BUILD $EXTRA_FEATURES --color ${colors}
|
||||||
@ -54,7 +66,8 @@
|
|||||||
noisily rustc --crate-name $crate_name_ $main_file --crate-type bin ${rustcOpts}\
|
noisily rustc --crate-name $crate_name_ $main_file --crate-type bin ${rustcOpts}\
|
||||||
${crateFeatures} --out-dir target/bin --emit=dep-info,link -L dependency=target/deps \
|
${crateFeatures} --out-dir target/bin --emit=dep-info,link -L dependency=target/deps \
|
||||||
$LINK ${deps}$EXTRA_LIB --cap-lints allow \
|
$LINK ${deps}$EXTRA_LIB --cap-lints allow \
|
||||||
$BUILD_OUT_DIR $EXTRA_BUILD $EXTRA_FEATURES --color ${colors}
|
$BUILD_OUT_DIR $EXTRA_BUILD $EXTRA_FEATURES --color ${colors} \
|
||||||
|
${if stdenv.hostPlatform != stdenv.buildPlatform then "--target ${rustPlatform} -C linker=${stdenv.hostPlatform.config}-gcc" else ""}
|
||||||
if [ "$crate_name_" != "$crate_name" ]; then
|
if [ "$crate_name_" != "$crate_name" ]; then
|
||||||
mv target/bin/$crate_name_ target/bin/$crate_name
|
mv target/bin/$crate_name_ target/bin/$crate_name
|
||||||
fi
|
fi
|
||||||
@ -103,9 +116,9 @@
|
|||||||
tr '\n' ' ' < target/link > target/link_
|
tr '\n' ' ' < target/link > target/link_
|
||||||
LINK=$(cat target/link_)
|
LINK=$(cat target/link_)
|
||||||
fi
|
fi
|
||||||
|
${lib.optionalString (crateBin != "") ''
|
||||||
mkdir -p target/bin
|
|
||||||
printf "%s\n" "${crateBin}" | head -n1 | tr -s ',' '\n' | while read -r BIN_NAME BIN_PATH; do
|
printf "%s\n" "${crateBin}" | head -n1 | tr -s ',' '\n' | while read -r BIN_NAME BIN_PATH; do
|
||||||
|
mkdir -p target/bin
|
||||||
# filter empty entries / empty "lines"
|
# filter empty entries / empty "lines"
|
||||||
if [[ -z "$BIN_NAME" ]]; then
|
if [[ -z "$BIN_NAME" ]]; then
|
||||||
continue
|
continue
|
||||||
@ -141,13 +154,15 @@
|
|||||||
fi
|
fi
|
||||||
build_bin "$BIN_NAME" "$BIN_PATH"
|
build_bin "$BIN_NAME" "$BIN_PATH"
|
||||||
done
|
done
|
||||||
|
''}
|
||||||
|
|
||||||
|
${lib.optionalString (crateBin == "" && !hasCrateBin) ''
|
||||||
${lib.optionalString (crateBin == "") ''
|
|
||||||
if [[ -e src/main.rs ]]; then
|
if [[ -e src/main.rs ]]; then
|
||||||
|
mkdir -p target/bin
|
||||||
build_bin ${crateName} src/main.rs
|
build_bin ${crateName} src/main.rs
|
||||||
fi
|
fi
|
||||||
for i in src/bin/*.rs; do #*/
|
for i in src/bin/*.rs; do #*/
|
||||||
|
mkdir -p target/bin
|
||||||
build_bin "$(basename $i .rs)" "$i"
|
build_bin "$(basename $i .rs)" "$i"
|
||||||
done
|
done
|
||||||
''}
|
''}
|
||||||
|
@ -4,7 +4,7 @@
|
|||||||
# This can be useful for deploying packages with NixOps, and to share
|
# This can be useful for deploying packages with NixOps, and to share
|
||||||
# binary dependencies between projects.
|
# binary dependencies between projects.
|
||||||
|
|
||||||
{ lib, stdenv, defaultCrateOverrides, fetchCrate, ncurses, rustc }:
|
{ lib, stdenv, defaultCrateOverrides, fetchCrate, rustc }:
|
||||||
|
|
||||||
let
|
let
|
||||||
# This doesn't appear to be officially documented anywhere yet.
|
# This doesn't appear to be officially documented anywhere yet.
|
||||||
@ -16,7 +16,7 @@ let
|
|||||||
makeDeps = dependencies:
|
makeDeps = dependencies:
|
||||||
(lib.concatMapStringsSep " " (dep:
|
(lib.concatMapStringsSep " " (dep:
|
||||||
let extern = lib.strings.replaceStrings ["-"] ["_"] dep.libName; in
|
let extern = lib.strings.replaceStrings ["-"] ["_"] dep.libName; in
|
||||||
(if dep.crateType == "lib" then
|
(if lib.lists.any (x: x == "lib") dep.crateType then
|
||||||
" --extern ${extern}=${dep.out}/lib/lib${extern}-${dep.metadata}.rlib"
|
" --extern ${extern}=${dep.out}/lib/lib${extern}-${dep.metadata}.rlib"
|
||||||
else
|
else
|
||||||
" --extern ${extern}=${dep.out}/lib/lib${extern}-${dep.metadata}${stdenv.hostPlatform.extensions.sharedLibrary}")
|
" --extern ${extern}=${dep.out}/lib/lib${extern}-${dep.metadata}${stdenv.hostPlatform.extensions.sharedLibrary}")
|
||||||
@ -86,7 +86,8 @@ stdenv.mkDerivation (rec {
|
|||||||
else
|
else
|
||||||
fetchCrate { inherit (crate) crateName version sha256; };
|
fetchCrate { inherit (crate) crateName version sha256; };
|
||||||
name = "rust_${crate.crateName}-${crate.version}";
|
name = "rust_${crate.crateName}-${crate.version}";
|
||||||
buildInputs = [ rust ncurses ] ++ (crate.buildInputs or []) ++ buildInputs_;
|
depsBuildBuild = [ rust stdenv.cc ];
|
||||||
|
buildInputs = (crate.buildInputs or []) ++ buildInputs_;
|
||||||
dependencies =
|
dependencies =
|
||||||
builtins.map
|
builtins.map
|
||||||
(dep: dep.override { rust = rust; release = release; verbose = verbose; crateOverrides = crateOverrides; })
|
(dep: dep.override { rust = rust; release = release; verbose = verbose; crateOverrides = crateOverrides; })
|
||||||
@ -122,15 +123,16 @@ stdenv.mkDerivation (rec {
|
|||||||
|
|
||||||
) "" crate.crateBin
|
) "" crate.crateBin
|
||||||
else "";
|
else "";
|
||||||
|
hasCrateBin = crate ? crateBin;
|
||||||
|
|
||||||
build = crate.build or "";
|
build = crate.build or "";
|
||||||
workspace_member = crate.workspace_member or ".";
|
workspace_member = crate.workspace_member or ".";
|
||||||
crateVersion = crate.version;
|
crateVersion = crate.version;
|
||||||
crateAuthors = if crate ? authors && lib.isList crate.authors then crate.authors else [];
|
crateAuthors = if crate ? authors && lib.isList crate.authors then crate.authors else [];
|
||||||
crateType =
|
crateType =
|
||||||
if lib.attrByPath ["procMacro"] false crate then "proc-macro" else
|
if lib.attrByPath ["procMacro"] false crate then ["proc-macro"] else
|
||||||
if lib.attrByPath ["plugin"] false crate then "dylib" else
|
if lib.attrByPath ["plugin"] false crate then ["dylib"] else
|
||||||
(crate.type or "lib");
|
(crate.type or ["lib"]);
|
||||||
colors = lib.attrByPath [ "colors" ] "always" crate;
|
colors = lib.attrByPath [ "colors" ] "always" crate;
|
||||||
extraLinkFlags = builtins.concatStringsSep " " (crate.extraLinkFlags or []);
|
extraLinkFlags = builtins.concatStringsSep " " (crate.extraLinkFlags or []);
|
||||||
configurePhase = configureCrate {
|
configurePhase = configureCrate {
|
||||||
@ -143,7 +145,7 @@ stdenv.mkDerivation (rec {
|
|||||||
buildPhase = buildCrate {
|
buildPhase = buildCrate {
|
||||||
inherit crateName dependencies
|
inherit crateName dependencies
|
||||||
crateFeatures libName release libPath crateType
|
crateFeatures libName release libPath crateType
|
||||||
metadata crateBin verbose colors
|
metadata crateBin hasCrateBin verbose colors
|
||||||
extraRustcOpts;
|
extraRustcOpts;
|
||||||
};
|
};
|
||||||
installPhase = installCrate crateName metadata;
|
installPhase = installCrate crateName metadata;
|
||||||
|
24
pkgs/build-support/rust/build-rust-crate/helpers.nix
Normal file
24
pkgs/build-support/rust/build-rust-crate/helpers.nix
Normal file
@ -0,0 +1,24 @@
|
|||||||
|
{stdenv, lib}:
|
||||||
|
{
|
||||||
|
kernel = stdenv.hostPlatform.parsed.kernel.name;
|
||||||
|
abi = stdenv.hostPlatform.parsed.abi.name;
|
||||||
|
updateFeatures = f: up: functions: builtins.deepSeq f (lib.lists.foldl' (features: fun: fun features) (lib.attrsets.recursiveUpdate f up) functions);
|
||||||
|
mapFeatures = features: map (fun: fun { features = features; });
|
||||||
|
mkFeatures = feat: lib.lists.foldl (features: featureName:
|
||||||
|
if feat.${featureName} or false then
|
||||||
|
[ featureName ] ++ features
|
||||||
|
else
|
||||||
|
features
|
||||||
|
) [] (builtins.attrNames feat);
|
||||||
|
include = includedFiles: src: builtins.filterSource (path: type:
|
||||||
|
lib.lists.any (f:
|
||||||
|
let p = toString (src + ("/" + f)); in
|
||||||
|
(path == p) || (type == "directory" && lib.strings.hasPrefix path p)
|
||||||
|
) includedFiles
|
||||||
|
) src;
|
||||||
|
exclude = excludedFiles: src: builtins.filterSource (path: type:
|
||||||
|
lib.lists.all (f:
|
||||||
|
!lib.strings.hasPrefix (toString (src + ("/" + f))) path
|
||||||
|
) excludedFiles
|
||||||
|
) src;
|
||||||
|
}
|
File diff suppressed because it is too large
Load Diff
2050
pkgs/build-support/rust/crates-io.nix
Normal file
2050
pkgs/build-support/rust/crates-io.nix
Normal file
File diff suppressed because it is too large
Load Diff
@ -7343,8 +7343,9 @@ with pkgs;
|
|||||||
inherit (rust) cargo rustc;
|
inherit (rust) cargo rustc;
|
||||||
|
|
||||||
buildRustCrate = callPackage ../build-support/rust/build-rust-crate { };
|
buildRustCrate = callPackage ../build-support/rust/build-rust-crate { };
|
||||||
|
buildRustCrateHelpers = callPackage ../build-support/rust/build-rust-crate/helpers.nix { };
|
||||||
buildRustCrateTests = recurseIntoAttrs (callPackage ../build-support/rust/build-rust-crate/test { }).tests;
|
buildRustCrateTests = recurseIntoAttrs (callPackage ../build-support/rust/build-rust-crate/test { }).tests;
|
||||||
|
cratesIO = callPackage ../build-support/rust/crates-io.nix { };
|
||||||
cargo-vendor = callPackage ../build-support/rust/cargo-vendor { };
|
cargo-vendor = callPackage ../build-support/rust/cargo-vendor { };
|
||||||
|
|
||||||
cargo-web = callPackage ../development/tools/cargo-web {
|
cargo-web = callPackage ../development/tools/cargo-web {
|
||||||
|
Loading…
x
Reference in New Issue
Block a user