cargo-ament-build: v0.1.8

This commit is contained in:
Jeremy Kolb 2024-09-17 11:58:42 -04:00 committed by Ben Wolsieffer
parent dabd41fd0d
commit 90a80fe3dc
2 changed files with 161 additions and 94 deletions

View file

@ -1,5 +1,5 @@
# This file was @generated by crate2nix 0.10.0 with the command:
# This file was @generated by crate2nix 0.14.1 with the command:
# "generate"
# See https://github.com/kolloch/crate2nix for more info.
@ -7,17 +7,15 @@
, pkgs ? import nixpkgs { config = {}; }
, lib ? pkgs.lib
, stdenv ? pkgs.stdenv
, buildRustCrateForPkgs ? if buildRustCrate != null
then lib.warn "crate2nix: Passing `buildRustCrate` as argument to Cargo.nix is deprecated. If you don't customize `buildRustCrate`, replace `callPackage ./Cargo.nix {}` by `import ./Cargo.nix { inherit pkgs; }`, and if you need to customize `buildRustCrate`, use `buildRustCrateForPkgs` instead." (_: buildRustCrate)
else pkgs: pkgs.buildRustCrate
# Deprecated
, buildRustCrate ? null
, buildRustCrateForPkgs ? pkgs: pkgs.buildRustCrate
# This is used as the `crateOverrides` argument for `buildRustCrate`.
, defaultCrateOverrides ? pkgs.defaultCrateOverrides
# The features to enable for the root_crate or the workspace_members.
, rootFeatures ? [ "default" ]
# If true, throw errors instead of issueing deprecation warnings.
, strictDeprecation ? false
# Elements to add to the `-C target-feature=` argument passed to `rustc`
# (separated by `,`, prefixed with `+`).
# Used for conditional compilation based on CPU feature detection.
, targetFeatures ? []
# Whether to perform release builds: longer compile times, faster binaries.
@ -89,9 +87,9 @@ rec {
crates = {
"anyhow" = rec {
crateName = "anyhow";
version = "1.0.66";
version = "1.0.89";
edition = "2018";
sha256 = "1xj3ahmwjlbiqsajhkaa0q6hqwb4l3l5rkfxa7jk1498r3fn2qi1";
sha256 = "1xh1vg89n56h6nqikcmgbpmkixjds33492klrp9m96xrbmhgizc6";
authors = [
"David Tolnay <dtolnay@gmail.com>"
];
@ -103,9 +101,9 @@ rec {
};
"autocfg" = rec {
crateName = "autocfg";
version = "1.1.0";
version = "1.3.0";
edition = "2015";
sha256 = "1ylp3cb47ylzabimazvbz9ms6ap784zhb6syaz6c1jqpmcmq0s6l";
sha256 = "1c3njkfzpil03k92q0mij5y1pkhhfr4j3bf0h53bgl2vs85lsjqc";
authors = [
"Josh Stone <cuviper@gmail.com>"
];
@ -113,10 +111,14 @@ rec {
};
"cargo-ament-build" = rec {
crateName = "cargo-ament-build";
version = "0.1.6";
version = "0.1.8";
edition = "2021";
crateBin = [
{ name = "cargo-ament-build"; path = "src/main.rs"; }
{
name = "cargo-ament-build";
path = "src/main.rs";
requiredFeatures = [ ];
}
];
src = lib.cleanSourceWith { filter = sourceFilter; src = ./.; };
authors = [
@ -188,9 +190,9 @@ rec {
};
"indexmap" = rec {
crateName = "indexmap";
version = "1.9.1";
version = "1.9.3";
edition = "2021";
sha256 = "07nli1wcz7m81svvig8l5j6vjycjnv9va46lwblgy803ffbmm8qh";
sha256 = "16dxmy7yvk51wvnih3a3im6fp5lmx0wx76i03n06wyak6cwhw1xx";
dependencies = [
{
name = "hashbrown";
@ -206,6 +208,8 @@ rec {
}
];
features = {
"arbitrary" = [ "dep:arbitrary" ];
"quickcheck" = [ "dep:quickcheck" ];
"rayon" = [ "dep:rayon" ];
"rustc-rayon" = [ "dep:rustc-rayon" ];
"serde" = [ "dep:serde" ];
@ -227,9 +231,10 @@ rec {
};
"proc-macro2" = rec {
crateName = "proc-macro2";
version = "1.0.47";
edition = "2018";
sha256 = "09g7alc7mlbycsadfh7lwskr1qfxbiic9qp9z751cqz3n04dk8sy";
version = "1.0.86";
edition = "2021";
sha256 = "0xrv22p8lqlfdf1w0pj4si8n2ws4aw0kilmziwf0vpv5ys6rwway";
libName = "proc_macro2";
authors = [
"David Tolnay <dtolnay@gmail.com>"
"Alex Crichton <alex@alexcrichton.com>"
@ -243,13 +248,13 @@ rec {
features = {
"default" = [ "proc-macro" ];
};
resolvedDefaultFeatures = [ "default" "proc-macro" ];
resolvedDefaultFeatures = [ "proc-macro" ];
};
"quote" = rec {
crateName = "quote";
version = "1.0.21";
version = "1.0.37";
edition = "2018";
sha256 = "0yai5cyd9h95n7hkwjcx8ig3yv0hindmz5gm60g9dmm7fzrlir5v";
sha256 = "1brklraw2g34bxy9y4q1nbrccn7bv36ylihv12c9vlcii55x7fdm";
authors = [
"David Tolnay <dtolnay@gmail.com>"
];
@ -264,17 +269,35 @@ rec {
"default" = [ "proc-macro" ];
"proc-macro" = [ "proc-macro2/proc-macro" ];
};
resolvedDefaultFeatures = [ "default" "proc-macro" ];
resolvedDefaultFeatures = [ "proc-macro" ];
};
"serde" = rec {
crateName = "serde";
version = "1.0.147";
edition = "2015";
sha256 = "0rc9jj8bbhf3lkf07ln8kyljigyzc4kk90nzg4dc2gwqmsdxd4yi";
version = "1.0.210";
edition = "2018";
sha256 = "0flc0z8wgax1k4j5bf2zyq48bgzyv425jkd5w0i6wbh7f8j5kqy8";
authors = [
"Erick Tryzelaar <erick.tryzelaar@gmail.com>"
"David Tolnay <dtolnay@gmail.com>"
];
dependencies = [
{
name = "serde_derive";
packageId = "serde_derive";
optional = true;
}
{
name = "serde_derive";
packageId = "serde_derive";
target = { target, features }: false;
}
];
devDependencies = [
{
name = "serde_derive";
packageId = "serde_derive";
}
];
features = {
"default" = [ "std" ];
"derive" = [ "serde_derive" ];
@ -284,9 +307,9 @@ rec {
};
"serde_derive" = rec {
crateName = "serde_derive";
version = "1.0.147";
version = "1.0.210";
edition = "2015";
sha256 = "0ln8rqbybpxmk4fvh6lgm75acs1d8x90fi44fhx3x77wm0n3c7ag";
sha256 = "07yzy4wafk79ps0hmbqmsqh5xjna4pm4q57wc847bb8gl3nh4f94";
procMacro = true;
authors = [
"Erick Tryzelaar <erick.tryzelaar@gmail.com>"
@ -296,14 +319,20 @@ rec {
{
name = "proc-macro2";
packageId = "proc-macro2";
usesDefaultFeatures = false;
features = [ "proc-macro" ];
}
{
name = "quote";
packageId = "quote";
usesDefaultFeatures = false;
features = [ "proc-macro" ];
}
{
name = "syn";
packageId = "syn";
usesDefaultFeatures = false;
features = [ "clone-impls" "derive" "parsing" "printing" "proc-macro" ];
}
];
features = {
@ -312,9 +341,9 @@ rec {
};
"syn" = rec {
crateName = "syn";
version = "1.0.103";
edition = "2018";
sha256 = "0pa4b6g938drphblgdhmjnzclp7gcbf4zdgkmfaxlfhk54i08r58";
version = "2.0.77";
edition = "2021";
sha256 = "1vbkwfp9ymmi0fsyyjsqfvnv7gm8vjgl4pzprbk7p3pxc7gvqdcz";
authors = [
"David Tolnay <dtolnay@gmail.com>"
];
@ -337,18 +366,17 @@ rec {
];
features = {
"default" = [ "derive" "parsing" "printing" "clone-impls" "proc-macro" ];
"printing" = [ "quote" ];
"proc-macro" = [ "proc-macro2/proc-macro" "quote/proc-macro" ];
"quote" = [ "dep:quote" ];
"printing" = [ "dep:quote" ];
"proc-macro" = [ "proc-macro2/proc-macro" "quote?/proc-macro" ];
"test" = [ "syn-test-suite/all-features" ];
};
resolvedDefaultFeatures = [ "clone-impls" "default" "derive" "parsing" "printing" "proc-macro" "quote" ];
resolvedDefaultFeatures = [ "clone-impls" "derive" "parsing" "printing" "proc-macro" ];
};
"toml" = rec {
crateName = "toml";
version = "0.5.9";
version = "0.5.11";
edition = "2018";
sha256 = "1mr40c0x3ma0dbzh4v43bfn4sj3k9ihpgq6fz1js88l6fnky30ld";
sha256 = "0d2266nx8b3n22c7k24x4428z6di8n83a9n466jm7a2hipfz1xzl";
authors = [
"Alex Crichton <alex@alexcrichton.com>"
];
@ -371,9 +399,10 @@ rec {
};
"unicode-ident" = rec {
crateName = "unicode-ident";
version = "1.0.5";
version = "1.0.13";
edition = "2018";
sha256 = "1wznr6ax3jl09vxkvj4a62vip2avfgif13js9sflkjg4b6fv7skc";
sha256 = "1zm1xylzsdfvm2a5ib9li3g5pp7qnkv4amhspydvgbmd9k6mc6z9";
libName = "unicode_ident";
authors = [
"David Tolnay <dtolnay@gmail.com>"
];
@ -388,26 +417,22 @@ rec {
/* Target (platform) data for conditional dependencies.
This corresponds roughly to what buildRustCrate is setting.
*/
defaultTarget = {
unix = true;
windows = false;
makeDefaultTarget = platform: {
unix = platform.isUnix;
windows = platform.isWindows;
fuchsia = true;
test = false;
# This doesn't appear to be officially documented anywhere yet.
# See https://github.com/rust-lang-nursery/rust-forge/issues/101.
os =
if stdenv.hostPlatform.isDarwin
then "macos"
else stdenv.hostPlatform.parsed.kernel.name;
arch = stdenv.hostPlatform.parsed.cpu.name;
family = "unix";
inherit (platform.rust.platform)
arch
os
vendor;
family = platform.rust.platform.target-family;
env = "gnu";
endian =
if stdenv.hostPlatform.parsed.cpu.significantByte.name == "littleEndian"
if platform.parsed.cpu.significantByte.name == "littleEndian"
then "little" else "big";
pointer_width = toString stdenv.hostPlatform.parsed.cpu.bits;
vendor = stdenv.hostPlatform.parsed.vendor.name;
pointer_width = toString platform.parsed.cpu.bits;
debug_assertions = false;
};
@ -496,14 +521,25 @@ rec {
inherit testCrateFlags;
buildInputs = testInputs;
} ''
set -ex
set -e
export RUST_BACKTRACE=1
# recreate a file hierarchy as when running tests with cargo
# the source for test data
${pkgs.xorg.lndir}/bin/lndir ${crate.src}
# It's necessary to locate the source in $NIX_BUILD_TOP/source/
# instead of $NIX_BUILD_TOP/
# because we compiled those test binaries in the former and not the latter.
# So all paths will expect source tree to be there and not in the build top directly.
# For example: $NIX_BUILD_TOP := /build in general, if you ask yourself.
# NOTE: There could be edge cases if `crate.sourceRoot` does exist but
# it's very hard to reason about them.
# Open a bug if you run into this!
mkdir -p source/
cd source/
${pkgs.buildPackages.xorg.lndir}/bin/lndir ${crate.src}
# build outputs
testRoot=target/debug
@ -533,10 +569,12 @@ rec {
passthru = (crate.passthru or { }) // {
inherit test;
};
} ''
echo tested by ${test}
${lib.concatMapStringsSep "\n" (output: "ln -s ${crate.${output}} ${"$"}${output}") crate.outputs}
'';
}
(lib.optionalString (stdenv.buildPlatform.canExecute stdenv.hostPlatform) ''
echo tested by ${test}
'' + ''
${lib.concatMapStringsSep "\n" (output: "ln -s ${crate.${output}} ${"$"}${output}") crate.outputs}
'');
/* A restricted overridable version of builtRustCratesWithFeatures. */
buildRustCrateWithFeatures =
@ -610,12 +648,12 @@ rec {
, crateConfigs ? crates
, buildRustCrateForPkgsFunc
, runTests
, target ? defaultTarget
, makeTarget ? makeDefaultTarget
} @ args:
assert (builtins.isAttrs crateConfigs);
assert (builtins.isString packageId);
assert (builtins.isList features);
assert (builtins.isAttrs target);
assert (builtins.isAttrs (makeTarget stdenv.hostPlatform));
assert (builtins.isBool runTests);
let
rootPackageId = packageId;
@ -623,7 +661,7 @@ rec {
(
args // {
inherit rootPackageId;
target = target // { test = runTests; };
target = makeTarget stdenv.hostPlatform // { test = runTests; };
}
);
# Memoize built packages so that reappearing packages are only built once.
@ -632,6 +670,7 @@ rec {
let
self = {
crates = lib.mapAttrs (packageId: value: buildByPackageIdForPkgsImpl self pkgs packageId) crateConfigs;
target = makeTarget stdenv.hostPlatform;
build = mkBuiltByPackageIdByPkgs pkgs.buildPackages;
};
in
@ -648,7 +687,8 @@ rec {
(crateConfig'.devDependencies or [ ]);
dependencies =
dependencyDerivations {
inherit features target;
inherit features;
inherit (self) target;
buildByPackageId = depPackageId:
# proc_macro crates must be compiled for the build architecture
if crateConfigs.${depPackageId}.procMacro or false
@ -660,24 +700,26 @@ rec {
};
buildDependencies =
dependencyDerivations {
inherit features target;
inherit features;
inherit (self.build) target;
buildByPackageId = depPackageId:
self.build.crates.${depPackageId};
dependencies = crateConfig.buildDependencies or [ ];
};
filterEnabledDependenciesForThis = dependencies: filterEnabledDependencies {
inherit dependencies features target;
};
dependenciesWithRenames =
lib.filter (d: d ? "rename")
(
filterEnabledDependenciesForThis
(
(crateConfig.buildDependencies or [ ])
++ (crateConfig.dependencies or [ ])
++ devDependencies
)
);
let
buildDeps = filterEnabledDependencies {
inherit features;
inherit (self) target;
dependencies = crateConfig.dependencies or [ ] ++ devDependencies;
};
hostDeps = filterEnabledDependencies {
inherit features;
inherit (self.build) target;
dependencies = crateConfig.buildDependencies or [ ];
};
in
lib.filter (d: d ? "rename") (hostDeps ++ buildDeps);
# Crate renames have the form:
#
# {
@ -696,9 +738,9 @@ rec {
let
package = crateConfigs."${dep.packageId}";
in
{ inherit (dep) rename; version = package.version; };
{ inherit (dep) rename; inherit (package) version; };
in
lib.mapAttrs (name: choices: builtins.map versionAndRename choices) grouped;
lib.mapAttrs (name: builtins.map versionAndRename) grouped;
in
buildRustCrateForPkgsFunc pkgs
(
@ -744,7 +786,7 @@ rec {
*/
sanitizeForJson = val:
if builtins.isAttrs val
then lib.mapAttrs (n: v: sanitizeForJson v) val
then lib.mapAttrs (n: sanitizeForJson) val
else if builtins.isList val
then builtins.map sanitizeForJson val
else if builtins.isFunction val
@ -752,7 +794,7 @@ rec {
else val;
/* Returns various tools to debug a crate. */
debugCrate = { packageId, target ? defaultTarget }:
debugCrate = { packageId, target ? makeDefaultTarget stdenv.hostPlatform }:
assert (builtins.isString packageId);
let
debug = rec {
@ -853,7 +895,7 @@ rec {
enabledFeatures = enableFeatures (crateConfig.dependencies or [ ]) expandedFeatures;
depWithResolvedFeatures = dependency:
let
packageId = dependency.packageId;
inherit (dependency) packageId;
features = dependencyFeatures enabledFeatures dependency;
in
{ inherit packageId features; };
@ -928,15 +970,14 @@ rec {
dependencies;
/* Returns whether the given feature should enable the given dependency. */
doesFeatureEnableDependency = { name, rename ? null, ... }: feature:
doesFeatureEnableDependency = dependency: feature:
let
name = dependency.rename or dependency.name;
prefix = "${name}/";
len = builtins.stringLength prefix;
startsWithPrefix = builtins.substring 0 len feature == prefix;
in
(rename == null && feature == name)
|| (rename != null && rename == feature)
|| startsWithPrefix;
feature == name || feature == "dep:" + name || startsWithPrefix;
/* Returns the expanded features for the given inputFeatures by applying the
rules in featureMap.
@ -948,10 +989,24 @@ rec {
assert (builtins.isAttrs featureMap);
assert (builtins.isList inputFeatures);
let
expandFeature = feature:
assert (builtins.isString feature);
[ feature ] ++ (expandFeatures featureMap (featureMap."${feature}" or [ ]));
outFeatures = lib.concatMap expandFeature inputFeatures;
expandFeaturesNoCycle = oldSeen: inputFeatures:
if inputFeatures != [ ]
then
let
# The feature we're currently expanding.
feature = builtins.head inputFeatures;
# All the features we've seen/expanded so far, including the one
# we're currently processing.
seen = oldSeen // { ${feature} = 1; };
# Expand the feature but be careful to not re-introduce a feature
# that we've already seen: this can easily cause a cycle, see issue
# #209.
enables = builtins.filter (f: !(seen ? "${f}")) (featureMap."${feature}" or [ ]);
in
[ feature ] ++ (expandFeaturesNoCycle seen (builtins.tail inputFeatures ++ enables))
# No more features left, nothing to expand to.
else [ ];
outFeatures = expandFeaturesNoCycle { } inputFeatures;
in
sortedUnique outFeatures;
@ -971,7 +1026,9 @@ rec {
let
enabled = builtins.any (doesFeatureEnableDependency dependency) features;
in
if (dependency.optional or false) && enabled then [ dependency.name ] else [ ]
if (dependency.optional or false) && enabled
then [ (dependency.rename or dependency.name) ]
else [ ]
)
dependencies;
in
@ -993,11 +1050,21 @@ rec {
explicitFeatures = dependency.features or [ ];
additionalDependencyFeatures =
let
dependencyPrefix = (dependency.rename or dependency.name) + "/";
dependencyFeatures =
builtins.filter (f: lib.hasPrefix dependencyPrefix f) features;
name = dependency.rename or dependency.name;
stripPrefixMatch = prefix: s:
if lib.hasPrefix prefix s
then lib.removePrefix prefix s
else null;
extractFeature = feature: lib.findFirst
(f: f != null)
null
(map (prefix: stripPrefixMatch prefix feature) [
(name + "/")
(name + "?/")
]);
dependencyFeatures = lib.filter (f: f != null) (map extractFeature features);
in
builtins.map (lib.removePrefix dependencyPrefix) dependencyFeatures;
dependencyFeatures;
in
defaultOrNil ++ explicitFeatures ++ additionalDependencyFeatures;

View file

@ -8,8 +8,8 @@
src = fetchFromGitHub {
owner = "ros2-rust";
repo = "cargo-ament-build";
rev = "60a9bd267b0849f5c17b9e1f159428b04a68b649";
hash = "sha256-/oB51UXasc+bwp2jXT6gPZR4nCD4leUDvY+T9Ymb1Mk=";
rev = "v0.1.8";
hash = "sha256-P3HX3LXQLA2NvFeV3B1baGrl0CaPWAn4Yzh+aAgUuBM=";
};
};
};