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:
Pierre-Etienne Meunier 2018-10-28 00:06:29 +01:00 committed by Joachim Schiele
parent a3e367ff4b
commit ae3b4655a4
6 changed files with 2353 additions and 1454 deletions

View File

@ -2,7 +2,7 @@
{ crateName,
dependencies,
crateFeatures, libName, release, libPath,
crateType, metadata, crateBin,
crateType, metadata, crateBin, hasCrateBin,
extraRustcOpts, verbose, colors }:
let
@ -13,6 +13,17 @@
(if release then "-C opt-level=3" else "-C debuginfo=2")
(["-C codegen-units=1"] ++ extraRustcOpts);
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 ''
runHook preBuild
norm=""
@ -32,7 +43,8 @@
lib_src=$1
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 \
--emit=dep-info,link -L dependency=target/deps ${deps} --cap-lints allow \
$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}\
${crateFeatures} --out-dir target/bin --emit=dep-info,link -L dependency=target/deps \
$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
mv target/bin/$crate_name_ target/bin/$crate_name
fi
@ -103,9 +116,9 @@
tr '\n' ' ' < target/link > target/link_
LINK=$(cat target/link_)
fi
mkdir -p target/bin
${lib.optionalString (crateBin != "") ''
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"
if [[ -z "$BIN_NAME" ]]; then
continue
@ -141,13 +154,15 @@
fi
build_bin "$BIN_NAME" "$BIN_PATH"
done
''}
${lib.optionalString (crateBin == "") ''
${lib.optionalString (crateBin == "" && !hasCrateBin) ''
if [[ -e src/main.rs ]]; then
mkdir -p target/bin
build_bin ${crateName} src/main.rs
fi
for i in src/bin/*.rs; do #*/
mkdir -p target/bin
build_bin "$(basename $i .rs)" "$i"
done
''}

View File

@ -4,7 +4,7 @@
# This can be useful for deploying packages with NixOps, and to share
# binary dependencies between projects.
{ lib, stdenv, defaultCrateOverrides, fetchCrate, ncurses, rustc }:
{ lib, stdenv, defaultCrateOverrides, fetchCrate, rustc }:
let
# This doesn't appear to be officially documented anywhere yet.
@ -16,7 +16,7 @@ let
makeDeps = dependencies:
(lib.concatMapStringsSep " " (dep:
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"
else
" --extern ${extern}=${dep.out}/lib/lib${extern}-${dep.metadata}${stdenv.hostPlatform.extensions.sharedLibrary}")
@ -86,7 +86,8 @@ stdenv.mkDerivation (rec {
else
fetchCrate { inherit (crate) crateName version sha256; };
name = "rust_${crate.crateName}-${crate.version}";
buildInputs = [ rust ncurses ] ++ (crate.buildInputs or []) ++ buildInputs_;
depsBuildBuild = [ rust stdenv.cc ];
buildInputs = (crate.buildInputs or []) ++ buildInputs_;
dependencies =
builtins.map
(dep: dep.override { rust = rust; release = release; verbose = verbose; crateOverrides = crateOverrides; })
@ -122,15 +123,16 @@ stdenv.mkDerivation (rec {
) "" crate.crateBin
else "";
hasCrateBin = crate ? crateBin;
build = crate.build or "";
workspace_member = crate.workspace_member or ".";
crateVersion = crate.version;
crateAuthors = if crate ? authors && lib.isList crate.authors then crate.authors else [];
crateType =
if lib.attrByPath ["procMacro"] false crate then "proc-macro" else
if lib.attrByPath ["plugin"] false crate then "dylib" else
(crate.type or "lib");
if lib.attrByPath ["procMacro"] false crate then ["proc-macro"] else
if lib.attrByPath ["plugin"] false crate then ["dylib"] else
(crate.type or ["lib"]);
colors = lib.attrByPath [ "colors" ] "always" crate;
extraLinkFlags = builtins.concatStringsSep " " (crate.extraLinkFlags or []);
configurePhase = configureCrate {
@ -143,7 +145,7 @@ stdenv.mkDerivation (rec {
buildPhase = buildCrate {
inherit crateName dependencies
crateFeatures libName release libPath crateType
metadata crateBin verbose colors
metadata crateBin hasCrateBin verbose colors
extraRustcOpts;
};
installPhase = installCrate crateName metadata;

View 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

File diff suppressed because it is too large Load Diff

View File

@ -7343,8 +7343,9 @@ with pkgs;
inherit (rust) cargo rustc;
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;
cratesIO = callPackage ../build-support/rust/crates-io.nix { };
cargo-vendor = callPackage ../build-support/rust/cargo-vendor { };
cargo-web = callPackage ../development/tools/cargo-web {