-
Notifications
You must be signed in to change notification settings - Fork 98
Add support for cross-compilation, with backcompat #160
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
Merged
Merged
Changes from all commits
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -5,6 +5,9 @@ | |
, lib | ||
, stdenv | ||
, buildRustCrate | ||
, buildRustCrateForPkgs ? if buildRustCrate != null | ||
then lib.warn "`buildRustCrate` is deprecated, use `buildRustCrateForPkgs` instead" (_: buildRustCrate) | ||
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 really dig this user guidance, thank you 👍 |
||
else pkgs: pkgs.buildRustCrate | ||
, defaultCrateOverrides | ||
, strictDeprecation ? true | ||
, crates ? { } | ||
|
@@ -162,7 +165,7 @@ rec { | |
{ packageId | ||
, features ? rootFeatures | ||
, crateOverrides ? defaultCrateOverrides | ||
, buildRustCrateFunc ? null | ||
, buildRustCrateForPkgsFunc ? null | ||
, runTests ? false | ||
, testCrateFlags ? [ ] | ||
, testInputs ? [ ] | ||
|
@@ -176,30 +179,30 @@ rec { | |
, testInputs | ||
}: | ||
let | ||
buildRustCrateFuncOverriden = | ||
if buildRustCrateFunc != null | ||
then buildRustCrateFunc | ||
buildRustCrateForPkgsFuncOverriden = | ||
if buildRustCrateForPkgsFunc != null | ||
then buildRustCrateForPkgsFunc | ||
else | ||
( | ||
if crateOverrides == pkgs.defaultCrateOverrides | ||
then buildRustCrate | ||
then buildRustCrateForPkgs | ||
else | ||
buildRustCrate.override { | ||
pkgs: (buildRustCrateForPkgs pkgs).override { | ||
defaultCrateOverrides = crateOverrides; | ||
} | ||
); | ||
builtRustCrates = builtRustCratesWithFeatures { | ||
inherit packageId features; | ||
buildRustCrateFunc = buildRustCrateFuncOverriden; | ||
buildRustCrateForPkgsFunc = buildRustCrateForPkgsFuncOverriden; | ||
runTests = false; | ||
}; | ||
builtTestRustCrates = builtRustCratesWithFeatures { | ||
inherit packageId features; | ||
buildRustCrateFunc = buildRustCrateFuncOverriden; | ||
buildRustCrateForPkgsFunc = buildRustCrateForPkgsFuncOverriden; | ||
runTests = true; | ||
}; | ||
drv = builtRustCrates.${packageId}; | ||
testDrv = builtTestRustCrates.${packageId}; | ||
drv = builtRustCrates.crates.${packageId}; | ||
testDrv = builtTestRustCrates.crates.${packageId}; | ||
derivation = | ||
if runTests then | ||
crateWithTest | ||
|
@@ -214,14 +217,14 @@ rec { | |
) | ||
{ inherit features crateOverrides runTests testCrateFlags testInputs; }; | ||
|
||
/* Returns an attr set with packageId mapped to the result of buildRustCrateFunc | ||
/* Returns an attr set with packageId mapped to the result of buildRustCrateForPkgsFunc | ||
for the corresponding crate. | ||
*/ | ||
builtRustCratesWithFeatures = | ||
{ packageId | ||
, features | ||
, crateConfigs ? crates | ||
, buildRustCrateFunc | ||
, buildRustCrateForPkgsFunc | ||
, runTests | ||
, target ? defaultTarget | ||
} @ args: | ||
|
@@ -239,12 +242,17 @@ rec { | |
target = target // { test = runTests; }; | ||
} | ||
); | ||
buildByPackageId = packageId: buildByPackageIdImpl packageId; | ||
|
||
# Memoize built packages so that reappearing packages are only built once. | ||
builtByPackageId = | ||
lib.mapAttrs (packageId: value: buildByPackageId packageId) crateConfigs; | ||
buildByPackageIdImpl = packageId: | ||
builtByPackageIdByPkgs = mkBuiltByPackageIdByPkgs pkgs; | ||
mkBuiltByPackageIdByPkgs = pkgs: | ||
let | ||
self = { | ||
crates = lib.mapAttrs (packageId: value: buildByPackageIdForPkgsImpl self pkgs packageId) crateConfigs; | ||
build = mkBuiltByPackageIdByPkgs pkgs.buildPackages; | ||
}; | ||
in | ||
self; | ||
buildByPackageIdForPkgsImpl = self: pkgs: packageId: | ||
let | ||
features = mergedFeatures."${packageId}" or [ ]; | ||
crateConfig' = crateConfigs."${packageId}"; | ||
|
@@ -256,14 +264,21 @@ rec { | |
(crateConfig'.devDependencies or [ ]); | ||
dependencies = | ||
dependencyDerivations { | ||
inherit builtByPackageId features target; | ||
inherit features target; | ||
buildByPackageId = depPackageId: | ||
# proc_macro crates must be compiled for the build architecture | ||
if crateConfigs.${depPackageId}.procMacro or false | ||
then self.build.crates.${depPackageId} | ||
else self.crates.${depPackageId}; | ||
dependencies = | ||
(crateConfig.dependencies or [ ]) | ||
++ devDependencies; | ||
}; | ||
buildDependencies = | ||
dependencyDerivations { | ||
inherit builtByPackageId features target; | ||
inherit features target; | ||
buildByPackageId = depPackageId: | ||
self.build.crates.${depPackageId}; | ||
dependencies = crateConfig.buildDependencies or [ ]; | ||
}; | ||
filterEnabledDependenciesForThis = dependencies: filterEnabledDependencies { | ||
|
@@ -295,13 +310,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 | ||
buildRustCrateForPkgsFunc pkgs | ||
( | ||
crateConfig // { | ||
src = crateConfig.src or ( | ||
|
@@ -320,24 +335,23 @@ rec { | |
} | ||
); | ||
in | ||
builtByPackageId; | ||
builtByPackageIdByPkgs; | ||
|
||
/* 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; | ||
|
||
|
@@ -360,14 +374,14 @@ rec { | |
debug = rec { | ||
# The built tree as passed to buildRustCrate. | ||
buildTree = buildRustCrateWithFeatures { | ||
buildRustCrateFunc = lib.id; | ||
buildRustCrateForPkgsFunc = _: lib.id; | ||
inherit packageId; | ||
}; | ||
sanitizedBuildTree = sanitizeForJson buildTree; | ||
dependencyTree = sanitizeForJson | ||
( | ||
buildRustCrateWithFeatures { | ||
buildRustCrateFunc = crate: { | ||
buildRustCrateForPkgsFunc = _: crate: { | ||
"01_crateName" = crate.crateName or false; | ||
"02_features" = crate.features or [ ]; | ||
"03_dependencies" = crate.dependencies or [ ]; | ||
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
Update comment?
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.
Oh! perhaps I was confused whether the comments were describing the thing above or the thing below.