-
Notifications
You must be signed in to change notification settings - Fork 97
nix: Fix cross-build on same platform #6691
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
Conversation
📝 WalkthroughWalkthroughThe pull request introduces cross-compilation support in the Changes
Assessment against linked issues
Possibly related PRs
Suggested labels
Suggested reviewers
Thank you for using CodeRabbit. We offer it for free to the OSS community and would appreciate your support in helping us grow. If you find it useful, would you consider giving us a shout-out on your favorite social media? 🪧 TipsChatThere are 3 ways to chat with CodeRabbit:
Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments. CodeRabbit Commands (Invoked using PR comments)
Other keywords and placeholders
Documentation and Community
|
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.
Actionable comments posted: 0
🧹 Outside diff range and nitpick comments (2)
nix/rust-builder.nix (1)
68-73
: LGTM! Consider documenting the cross-compilation workflow.The propagation of
isCross
throughcallPackage
is well-integrated with the existing build system. The parameter inheritance alongsidefoundryBin
,solcDefault
, andcraneLib
ensures consistent cross-compilation behavior.Consider adding documentation in the repository's Nix documentation to:
- Explain when to use
isCross
vs letting the system detect cross-compilation- Provide examples of common cross-compilation scenarios
- Document the interaction between
isCross
,crossSystem
, and platform comparisonnix/rust-package.nix (1)
Line range hint
165-171
: Consider adding error handling for patchelf operations.While the interpreter patching logic is correct, it could benefit from error handling to ensure the patching operation succeeds.
Consider applying this improvement:
preFixup = lib.optionalString (isCross && targetInterpreter != "") '' for f in `find $out/bin/ -type f`; do echo "patching interpreter for $f to ${targetInterpreter}" - patchelf --set-interpreter ${targetInterpreter} --output $f.patched $f - mv $f.patched $f + if ! patchelf --set-interpreter ${targetInterpreter} --output $f.patched $f; then + echo "Failed to patch interpreter for $f" + exit 1 + fi + if ! mv $f.patched $f; then + echo "Failed to replace original binary $f" + exit 1 + fi done '';
📜 Review details
Configuration used: .coderabbit.yaml
Review profile: CHILL
📒 Files selected for processing (3)
flake.nix
(1 hunks)nix/rust-builder.nix
(2 hunks)nix/rust-package.nix
(1 hunks)
🔇 Additional comments (8)
nix/rust-builder.nix (1)
4-4
: LGTM! Verify platform comparison behavior.
The addition of isCross
parameter with a default value of false
is a good approach for explicit cross-compilation control.
Let's verify the platform comparison behavior in the codebase:
✅ Verification successful
The shell script results provide comprehensive information about how isCross
is used across the codebase. Let me generate the final response based on this verification:
Platform comparison logic is correctly implemented
The isCross
parameter works correctly with the platform comparison logic:
- In
rust-builder.nix
,crossSystem
is properly normalized usingpkgsLocal.lib.systems.equals
to compare withlocalSystem
- The parameter is consistently propagated to
rust-package.nix
where it's used inpreFixup
for interpreter patching - All cross-compilation cases in
flake.nix
explicitly setisCross = true
with their respectivecrossSystem
values
🏁 Scripts executed
The following scripts were executed for the analysis:
Script:
#!/bin/bash
# Description: Check how platform comparison is handled across the codebase
# Look for platform comparison logic that might interact with isCross
# Search for platform comparison patterns
rg -A 5 "buildPlatform|hostPlatform|crossSystem" --type nix
# Search for other isCross usage
rg "isCross" --type nix
Length of output: 6488
nix/rust-package.nix (2)
11-11
: LGTM: Explicit cross-build identification parameter added.
The addition of isCross
parameter with a default value of false
aligns well with the PR objective of making cross-build identification explicit in the configuration.
Line range hint 32-36
: Verify support for all required target architectures.
The target interpreter paths are defined for x86_64, aarch64, and armv7 Linux platforms. Let's verify if these cover all required target platforms for cross-compilation.
✅ Verification successful
Target interpreter paths are correctly defined for all supported architectures
Based on the codebase analysis:
- The
flake.nix
defines builds for x86_64-linux, aarch64-linux, armv7l-linux, x86_64-darwin, and aarch64-darwin - The target interpreter paths in
rust-package.nix
correctly cover all Linux architectures:- x86_64:
/lib64/ld-linux-x86-64.so.2
- aarch64:
/lib64/ld-linux-aarch64.so.1
- armv7:
/lib64/ld-linux-armhf.so.3
- x86_64:
- Darwin platforms don't need interpreter paths as they use a different linking mechanism
- The
rust-builder.nix
handles the correct cargo target triple mapping for armv7
🏁 Scripts executed
The following scripts were executed for the analysis:
Script:
#!/bin/bash
# Description: Check for any other architectures referenced in the codebase that might need interpreter support
# Search for architecture-specific references in Nix files
rg -t nix "(x86_64|aarch64|armv7|arm64|i686)"
# Search for build target definitions
fd -e nix -x grep -l "buildPlatform\|hostPlatform"
Length of output: 2905
Script:
#!/bin/bash
# Let's check the actual target platforms defined in the build configuration
# Check rust-builder.nix for platform configurations
cat nix/rust-builder.nix
# Check for any other platform-specific handling in rust-package.nix
cat nix/rust-package.nix
Length of output: 8260
flake.nix (5)
99-99
: Ensure 'isCross = true' is correctly applied for cross-compilation
The addition of isCross = true
in the rust-builder-x86_64-linux
configuration explicitly indicates cross-compilation, which aligns with the PR objectives to fix cross-building issues when the build and target platforms are the same.
105-105
: Ensure 'isCross = true' is correctly applied for cross-compilation
Similarly, adding isCross = true
to the rust-builder-x86_64-darwin
configuration ensures that cross-compilation is explicitly identified, which should help resolve the cross-building issue on this platform.
111-111
: Ensure 'isCross = true' is correctly applied for cross-compilation
Including isCross = true
in the rust-builder-aarch64-linux
configuration appropriately addresses the cross-compilation identification for this target platform.
117-117
: Ensure 'isCross = true' is correctly applied for cross-compilation
The addition of isCross = true
to the rust-builder-aarch64-darwin
configuration correctly signifies cross-compilation, aiding in the proper handling of builds for this platform.
123-123
: Ensure 'isCross = true' is correctly applied for cross-compilation
Adding isCross = true
in the rust-builder-armv7l-linux
configuration is appropriate and aligns with the goal of explicit cross-compilation identification.
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.
cross compilation now works fine
@@ -8,6 +8,7 @@ | |||
, foundryBin | |||
, git | |||
, html-tidy | |||
, isCross ? false |
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.
redundant default value
The problem was the cross build identification when the build platform was the same as the target platform. This has been made explicit in the configuration of the builder now.
Fixes #6689