-
Notifications
You must be signed in to change notification settings - Fork 89
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
WIP: add support for cross-compilation #152
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -7,7 +7,6 @@ | |
, pkgs ? import nixpkgs { config = {}; } | ||
, lib ? pkgs.lib | ||
, stdenv ? pkgs.stdenv | ||
, buildRustCrate ? 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. | ||
|
@@ -2291,7 +2290,6 @@ rec { | |
{ packageId | ||
, features ? rootFeatures | ||
, crateOverrides ? defaultCrateOverrides | ||
, buildRustCrateFunc ? null | ||
, runTests ? false | ||
, testCrateFlags ? [ ] | ||
, testInputs ? [ ] | ||
|
@@ -2305,26 +2303,18 @@ rec { | |
, testInputs | ||
}: | ||
let | ||
buildRustCrateFuncOverriden = | ||
if buildRustCrateFunc != null | ||
then buildRustCrateFunc | ||
else | ||
( | ||
if crateOverrides == pkgs.defaultCrateOverrides | ||
then buildRustCrate | ||
else | ||
buildRustCrate.override { | ||
defaultCrateOverrides = crateOverrides; | ||
} | ||
); | ||
buildRustCrateOverrides = | ||
if crateOverrides == pkgs.defaultCrateOverrides | ||
then { } | ||
else { | ||
defaultCrateOverrides = crateOverrides; | ||
}; | ||
builtRustCrates = builtRustCratesWithFeatures { | ||
inherit packageId features; | ||
buildRustCrateFunc = buildRustCrateFuncOverriden; | ||
inherit packageId features buildRustCrateOverrides; | ||
runTests = false; | ||
}; | ||
builtTestRustCrates = builtRustCratesWithFeatures { | ||
inherit packageId features; | ||
buildRustCrateFunc = buildRustCrateFuncOverriden; | ||
inherit packageId features buildRustCrateOverrides; | ||
runTests = true; | ||
}; | ||
drv = builtRustCrates.${packageId}; | ||
|
@@ -2350,7 +2340,7 @@ rec { | |
{ packageId | ||
, features | ||
, crateConfigs ? crates | ||
, buildRustCrateFunc | ||
, buildRustCrateOverrides | ||
, runTests | ||
, target ? defaultTarget | ||
} @ args: | ||
|
@@ -2368,13 +2358,10 @@ rec { | |
target = target // { test = runTests; }; | ||
} | ||
); | ||
buildByPackageId = packageId: buildByPackageIdImpl packageId; | ||
|
||
# Memoize built packages so that reappearing packages are only built once. | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Maybe we can do this again now that the hash thing has been changed in NixOS/nixpkgs#105305? On the other hand, isn't the comment wrong? I would assume this is just saving eval time, and the derivations will be identical and thus deduplicated either way. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. My understanding was also that this was an eval optimization. I don't think that PR affects this. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. OK fair point, then I think it might be nice to do the same corecursive stuff we do in nixpkgs? let
buildByPackageIdForPkgsMemo = mkBuildByPackageIdForPkgsMemo pkgs;
mkBuildByPackageIdForPkgsMemo = pkgs: {
crates = lib.mapAttrs (packageId: value: buildByPackageIdForPkgs pkgs packageId) crateConfigs;
build = mkBuildByPackageIdForPkgsMemo pkgs.buildPackages;
}; It's fine that this contains too much stuff, again cause lazy eval: a good time for space tradeoff. You use |
||
builtByPackageId = | ||
lib.mapAttrs (packageId: value: buildByPackageId packageId) crateConfigs; | ||
buildByPackageIdImpl = packageId: | ||
buildByPackageIdForPkgs = pkgs: packageId: | ||
let | ||
# proc_macro crates must be compiled for the build architecture | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I love that you specify the reason here in a comment. |
||
cratePkgs = if crateConfig.procMacro or false then pkgs.buildPackages else pkgs; | ||
features = mergedFeatures."${packageId}" or [ ]; | ||
crateConfig' = crateConfigs."${packageId}"; | ||
crateConfig = | ||
|
@@ -2385,14 +2372,16 @@ rec { | |
(crateConfig'.devDependencies or [ ]); | ||
dependencies = | ||
dependencyDerivations { | ||
inherit builtByPackageId features target; | ||
inherit features target; | ||
buildByPackageId = buildByPackageIdForPkgs cratePkgs; | ||
dependencies = | ||
(crateConfig.dependencies or [ ]) | ||
++ devDependencies; | ||
}; | ||
buildDependencies = | ||
dependencyDerivations { | ||
inherit builtByPackageId features target; | ||
inherit features target; | ||
buildByPackageId = buildByPackageIdForPkgs cratePkgs.buildPackages; | ||
dependencies = crateConfig.buildDependencies or [ ]; | ||
}; | ||
filterEnabledDependenciesForThis = dependencies: filterEnabledDependencies { | ||
|
@@ -2424,13 +2413,13 @@ rec { | |
dependenciesWithRenames; | ||
versionAndRename = dep: | ||
let | ||
package = builtByPackageId."${dep.packageId}"; | ||
package = crateConfigs."${dep.packageId}"; | ||
in | ||
{ inherit (dep) rename; version = package.version; }; | ||
in | ||
lib.mapAttrs (name: choices: builtins.map versionAndRename choices) grouped; | ||
in | ||
buildRustCrateFunc | ||
cratePkgs.buildRustCrate.override buildRustCrateOverrides | ||
( | ||
crateConfig // { | ||
src = crateConfig.src or ( | ||
|
@@ -2449,24 +2438,23 @@ rec { | |
} | ||
); | ||
in | ||
builtByPackageId; | ||
lib.mapAttrs (packageId: value: buildByPackageIdForPkgs pkgs packageId) crateConfigs; | ||
|
||
/* Returns the actual derivations for the given dependencies. */ | ||
dependencyDerivations = | ||
{ builtByPackageId | ||
{ buildByPackageId | ||
, features | ||
, dependencies | ||
, target | ||
}: | ||
assert (builtins.isAttrs builtByPackageId); | ||
assert (builtins.isList features); | ||
assert (builtins.isList dependencies); | ||
assert (builtins.isAttrs target); | ||
let | ||
enabledDependencies = filterEnabledDependencies { | ||
inherit dependencies features target; | ||
}; | ||
depDerivation = dependency: builtByPackageId.${dependency.packageId}; | ||
depDerivation = dependency: buildByPackageId dependency.packageId; | ||
in | ||
map depDerivation enabledDependencies; | ||
|
||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is it necessary to remove this argument? If yes, why?
[I just like to keep top-level interface changes minimally, and for whatever reason I made this a top-level argument.]
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@kolloch see what @lopsided98 said in the PR description:
I can attest that this makes sense from the usual cross perspective.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We can do
if you prefer, @kolloch. That will work.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
and
buildRustCrate
could be deprecated and given anull
default, so we can migrate withWith
traceDeprecatedMessage
left as a bikeshed to the reader :).