-
Describe the bug Making a system to flag a workspace dependency as not available on the WASM32 target may be required. Reproduction {
description = "Build a cargo workspace";
inputs = {
nixpkgs.url = "github:NixOS/nixpkgs/nixpkgs-unstable";
crane.url = "github:ipetkov/crane";
flake-utils.url = "github:numtide/flake-utils";
advisory-db = {
url = "github:rustsec/advisory-db";
flake = false;
};
};
outputs =
{
self,
nixpkgs,
crane,
flake-utils,
advisory-db,
...
}:
flake-utils.lib.eachDefaultSystem (
system:
let
pkgs = nixpkgs.legacyPackages.${system};
inherit (pkgs) lib;
craneLib = crane.mkLib pkgs;
src = craneLib.cleanCargoSource ./.;
commonArgs = {
# >>> Here is the cross compilation to WASM32 set
CARGO_BUILD_TARGET = "wasm32-unknown-unknown";
inherit src;
strictDeps = true;
buildInputs =
[
# Add additional build inputs here
]
++ lib.optionals pkgs.stdenv.isDarwin [
# Additional darwin specific inputs can be set here
pkgs.libiconv
];
};
cargoArtifacts = craneLib.buildDepsOnly commonArgs;
individualCrateArgs = commonArgs // {
inherit cargoArtifacts;
inherit (craneLib.crateNameFromCargoToml { inherit src; }) version;
doCheck = false;
};
fileSetForCrate =
crate:
lib.fileset.toSource {
root = ./.;
fileset = lib.fileset.unions [
./Cargo.toml
./Cargo.lock
(craneLib.fileset.commonCargoSources ./crates/my-common)
(craneLib.fileset.commonCargoSources ./crates/my-workspace-hack)
(craneLib.fileset.commonCargoSources crate)
];
};
my-cli = craneLib.buildPackage (
individualCrateArgs
// {
pname = "my-cli";
cargoExtraArgs = "-p my-cli";
src = fileSetForCrate ./crates/my-cli;
}
);
in
{
packages = {
inherit my-cli;
};
}
);
} Cargo.toml [workspace]
resolver = "2"
members = ["crates/*"]
[workspace.package]
version = "0.1.0"
edition = "2021"
[workspace.metadata.crane]
name = "my-workspace"
[workspace.dependencies]
cmd_lib = "1.9.6" |
Beta Was this translation helpful? Give feedback.
Replies: 3 comments 1 reply
-
Hi @kutu-dev thanks for the report! Could you please provide a full working example/reproduction of the issue? it can be a sample repo or even a gist, so long as all the files are present and I can run
Based on this bit of information I want to see a full reproduction to rule out any potential project misconfiguration. Normally individual crates should be defining platform-specific dependencies where appropriate (e.g. something like |
Beta Was this translation helpful? Give feedback.
-
Here is a minimal reproducible example: https://github.com/kutu-dev/reproduce-crane-issue-873 If you run either I would be useful, given that there is no way to gate workspace dependencies to only a set of targets, to have some sort of As a side note in the Rust RFC2906 it is explicitly written that:
So we're out of luck of requesting this to the upstream. Thanks for this great library! |
Beta Was this translation helpful? Give feedback.
-
Ah thank you for the full reproduction! So the solution here is what I hinted at above: using a platform-specific dependency in the crate which consumes the workspace-defined dependency; by applying this diff, all three derivations successfully build in your flake: diff --git a/crates/my-cli/Cargo.toml b/crates/my-cli/Cargo.toml
index 9787a50..1f6a5d1 100644
--- a/crates/my-cli/Cargo.toml
+++ b/crates/my-cli/Cargo.toml
@@ -3,5 +3,5 @@ name = "my-cli"
edition.workspace = true
publish = false
-[dependencies]
+[target.'cfg(not(target_arch = "wasm32"))'.dependencies]
cmd_lib.workspace = true Even though workspace dependencies do not support per-platform granularity, the crates which have to consume them can define that conditional dependency. In this case
Hope this helps! |
Beta Was this translation helpful? Give feedback.
Ah thank you for the full reproduction!
So the solution here is what I hinted at above: using a platform-specific dependency in the crate which consumes the workspace-defined dependency; by applying this diff, all three derivations successfully build in your flake:
Even though workspace dependencies do not support per-platform granularity, the crates which have…