-
Notifications
You must be signed in to change notification settings - Fork 43
Support cross compiling #203
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
base: trunk
Are you sure you want to change the base?
Conversation
|
Thanks for this. I have a use case where I need cross-compilation for One suggested addition would be to support the usual The |
Determining the OS from the triple would be complex, since the triple is in the format {cpu}-{vendor}-{os}{version}-{abi} but sometimes the abi or vendor or both are ommited, so for an example I don't know an easy way to tell if x86_64-linux-gnu means an OS of linux or gnu, or if arm64-apple-darwin22 means an os of darwin or apple. I think autoconf solves this by having a list of known values used as the vendor to check if the os is the 2nd or 3rd field, but then the list would have to be continuously updated and it's a lot easier to just make the user specify it in an environment variable. |
Right.
Okay, I see now. When I first tried using this, I was cross-compiling with nix, which as I mentioned passes the Maybe it would be clearer if it were named
Theoretically, I agree that extracting the correct information for the triple with perfect accuracy has a number of issues. In practice, I don't think it's really a problem though, due to the regularity and small set of actual triples that are encountered on a normal basis. I think the vast majority will be of the form A best-effort heuristic could catch probably 95% of the cases and then for the remaining ambiguous cases you could fall back to requiring the explicit environment variable or another flag or something. But it's just a suggestion.
True, it's not a huge burden, but the downside is that it still requires an extra configuration step for consumers. For the case of nix which I was referencing before, the yash cross-compile would have "just worked" (with this patch) like most other autoconf-based packages, if:
|
Omitting vendor is extremely common, like half of all linux cross toolchains do it, and the remaining have lots of different vendors, unknown, pc, redhat, and suse are just 4 of the ones I know of. The only solution is to have either a list of allowed operating systems or a list of allowed vendors that we can use to check which fields are which. Failing only on edge cases isn't viable either since we would still need to have a list of operating systems or vendors to determine what is and isn't an edge case. |
I guess I don't understand why this is a problem. Why does whether or not the vendor is included in the triple matter for determining the OS? Are you intending to eventually use that information for some implementations?
Isn't that already effectively the case given that there OS-specific signum implementations in the PR? Consider a very simple approach like this: Wouldn't that work? Given that (as far as I'm aware) no triple contains multiple OS values, that should always be unambiguous, right? |
|
I don't want to do that because as it is right now all you need to do to allow a new OS to be cross compiled for is put a file in the root of the build folder called |
Fair point.
This seems like it should suffice, and cheap enough to generate on the fly in the configure script just from the file listings and then checking for the |
I added a commit that implements this in my local branch: silvanshade/yash:target-os-from-host |
|
I could probably do it without using find or grep, I'll try later. |
magicant
left a 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.
Thank you so much for the pull request. I probably wouldn't have implemented this myself.
@Un1q32 Are you still intending to add this? The configure script already uses |
Never got around to it, probably never will, I merged your solution in for now at least. |
|
I made a cross-signum.h that should work on all targets (but less efficiently) on my branch. Does it seem to work for you? cd9ee40 |
|
Any reason you can't do 4d33fa3? Would improve efficiency of the cross build. |
SIGRTMAX and SIGRTMIN are not guaranteed to be compile-time constants. If those macros expand to something like |
|
There could be a configure check to see if the value would be constant when cross compiling, I might do that another time. Other than that the commit looks fine except that makesignum should have a |
|
Wait couldn't you still do the #if defined SIGRTMIN && defined SIGRTMAX
// do whatever
#else
#define 0
#endif |
|
nvm every use of RTSIZE is guarded by that condition anyway so it wouldn't matter. |
|
bug with cross compiling detection |
|
Unless anyone wants any more features I think this is complete. I've tested cross compiling for mac from linux and everything works. I can't think of anything more this needs. |
|
With 0c40a88 it should be possible to make CI automatically test the cross build without needing to setup an emulator or anything, but I don't know enough about your CI setup to set that up myself. |
|
Actually why is the default value for RTSIZE 100? Does it work on MIPS Linux where the value generated by makesignum is 102? |
Oops, just an oversight. |
the variable was unset when the first tryexec call happens which made it always return success
What would a better default value be? |
I'd go with 255. |
we dont actually *need* to always successfully detect an os for every target, most oses don't affect the build later so we can just check for every os that might affect the build and set the ostype to 'unknown' for all others
|
Anything more you want from this? I would consider this complete now. |
|
I'll merge this tomorrow. |
Closes #48
Handles signum.h by pre-generating the header for different operating systems (does it ever differ by architecture?)
Handles tryexec tests by assuming success when cross compiling.
Handles operating system detection by requiring the user to specify it with an environment variable.
Handles POSIX/XOPEN versions by guessing 200112 and 600.
Made the getcwd(NULL, 0) check default to not supported to be safe, and added an environment variable to override it.
Added the --host option to configure, this adds a cross prefix to cc and ar, so if you pass --host=aarch64-linux-musl then configure will look for aarch64-linux-musl-gcc and aarch64-linux-musl-ar