-
Notifications
You must be signed in to change notification settings - Fork 90
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
Cross-compilation fixes for Apple M1/x86 #30
Open
kornelski
wants to merge
8
commits into
zmwangx:master
Choose a base branch
from
kornelski:apple-cross-fixes
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
8 commits
Select commit
Hold shift + click to select a range
802077b
Fix unwrap on compiler names without -
kornelski d6facaa
Check for actual target OS
kornelski 57c190e
Use the os from the target triple, rather than Rust's nickname
kornelski e9f53e4
Explicitly enable cross-compilation in ./configure
kornelski a2b4ca7
Set --target flag for Apple's clang when cross-compiling
kornelski 9f75f57
Fix cross-compilation for Windows on Linux
chrox 2c0ff86
Clippy lint
kornelski c6dc629
rustfmt
kornelski 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 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
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.
Is there really no way to use rust's
target_os!
or something more standard? I'm afraid this will bite us if other architectures start to pop upThere 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.
Rust's target definitions are Rust's, and have no guarantee of compatibility with anything, e.g. Rust uses
macos
, but the rest of the world usesdarwin
.So yes, it is already broken, and will keep breaking on every new OS.
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.
would it be possible to have something that just checks if
target_os!
ismacos
, and replace it bydarwin
if it is? And maybe that does that for other OSes, if it happens for others? Maybe just afn target_os()
that wrapstarget_os!
and does the changes or somethingThere 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.
I suspect it's needed for more OSes, but I don't have them to test. Whatever you do, it's going to be an incomplete list that may break on OSes that haven't been tested.
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.
Quick question, but what's the value of
CARGO_CFG_TARGET_OS
on macos? Can't you just use a wrapper that gets CARGO_CFG_TARGET_OS and if it's macos, replace it by darwin?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.
CARGO_CFG_TARGET_*
variables are derived from rustc's cfg values, same ascfg!(target_*)
, so they use the same naming scheme.I can hardcode the result to be correct only on darwin/macos, and leave it incorrect everywhere else, but why should I leave it incorrect everywhere else?
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.
my question is just, why do this triple splitting magic (and explode if it doesn't work) instead of just using
CARGO_CFG_TARGET
and use a hashmap or something like that to substitute the wrong stuff with whatever you know is right? Or maybe I'm missing the point here?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.
Split doesn't work, because Rust's triples are inconsistently named, and sometimes have the "vendor" and sometimes they don't, so you don't know where the OS part starts.
HashMap would work for a closed set. I'm trying to make it work for an open set.
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.
my point was that maybe we could do a hashmap like
{'macos': 'darwin'}
and then just have a customtarget_os
function that would just return either the string itself, if it's not in the hashmap? LikeBut I feel like we're talking about different things though, so I could be completely wrong 😄
https://github.com/rustsec/rustsec/blob/main/platforms/src/target/os.rs#L112-L134 seems to have a pretty consistent list of OS if we wanna list more stuff here?