Skip to content
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

improve cross build configure in build.rs #27

Merged
merged 1 commit into from
Oct 4, 2024

Conversation

gen-xu
Copy link
Contributor

@gen-xu gen-xu commented Aug 7, 2024

this addresses #26

build.rs Outdated
@@ -76,7 +76,7 @@ fn build(metadata: &Metadata) {

// If we're cross-compiling, let configure know.
if metadata.host != metadata.target {
configure_args.push(format!("--host={}", metadata.target));
configure_args.push(format!("--host={}", metadata.host));
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm afraid that this does not look correct to me. GNU autotools uses "host" and "target" differently than Cargo: https://github.com/lu-zero/autotools-rs/blob/27d0437e071ddbf68ff0bbacfa02e01a04cc6b42/src/lib.rs#L71-L94

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for the link, I wasn't aware of this difference before.

Also I digged bit more on that, noticed that the zigbuild actually set CC_<triplets> and AR_<triplets> environment variables in, that are not passed all the way down to configure and make, so it was actually using the host tool & target to compile it into a macos target. Updated the build.rs to pass these when set.

Copy link
Member

@benesch benesch left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for the PR! Unfortunately I don't think this is the right approach; left you a line comment with details.

@gen-xu gen-xu changed the title fix host args for cross build configure in build.rs improve cross build configure in build.rs Aug 7, 2024
Copy link
Member

@benesch benesch left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think this looks about right, but historically we've pushed the responsibility for setting CC and AR correctly onto the person doing the compile—e.g.:

CC=my_cross_cc AR=my_cross_ar cargo build

This is a departure from that philosophy. Probably a worthwhile one, as you're not the first person to struggle getting this crate to cross compile, but a departure nonetheless.

I can get on board with the autodetection of CC and AR if there's a target triple version in the env, but blindly setting the configure tests to yes still feels sketchy to me. Before jumping all the way in to automatically forcing those settings to yes, I'd prefer to instead document in the README of the crate what configure tests will need to be overridden, and how to do so (krb5_cv_attr_constructor_destructor=yes ac_cv... cargo build ...)

build.rs Outdated
Comment on lines 120 to 122
.env("krb5_cv_attr_constructor_destructor", "yes")
.env("ac_cv_func_regcomp", "yes")
.env("ac_cv_printf_positional", "yes")
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We've historical held the position that it is inappropriate to set these flags in this crate, as we don't actually know that the target system supports these features that configure is checking—they're in theory something that whoever's doing the cross compile needs to set for themselves.

That said, it does seem like the answer is yes for basically all the cross-compiling targets that anyone cares about these days...

@gen-xu
Copy link
Contributor Author

gen-xu commented Aug 12, 2024

I think this looks about right, but historically we've pushed the responsibility for setting CC and AR correctly onto the person doing the compile—e.g.:

CC=my_cross_cc AR=my_cross_ar cargo build

This is a departure from that philosophy. Probably a worthwhile one, as you're not the first person to struggle getting this crate to cross compile, but a departure nonetheless.

I can get on board with the autodetection of CC and AR if there's a target triple version in the env, but blindly setting the configure tests to yes still feels sketchy to me. Before jumping all the way in to automatically forcing those settings to yes, I'd prefer to instead document in the README of the crate what configure tests will need to be overridden, and how to do so (krb5_cv_attr_constructor_destructor=yes ac_cv... cargo build ...)

I think the reason why the cargo-zigbuild is setting CC_<target_with_underscores> instead of just CC is coming from the convention in rust's cc crate
https://github.com/rust-lang/cc-rs/blob/eb3390615747fde57f7098797b2acb1aec80f539/src/lib.rs#L97
that this seems to be used pretty in common for cross-build

imo I don't think this is necessarily a departure of that philosophy, because zigbuild is the tool to setting CC_<target_with_underscores> and AR_<target_with_underscores> before invoke cargo for the user

without the zigbuild, one still needs to set those variables to invoke CC_<target_with_underscores>=... AR_<target_with_underscores>=... cargo build, where this PR only adds an extension to take the convention used by rust's cc crate.

I do agree that setting those flags are a bit inappropriate, maybe we could provide a variable flag for user to tweak those behaviors, or even better to check compiler support directly without compiling a test program whenever possible?

@gen-xu
Copy link
Contributor Author

gen-xu commented Aug 24, 2024

@benesch based on the conversation I removed the default environment variable set to skip the test, but providing hints to user to skip these checks correspondingly.

Automatically set CC/AR environment variables when invoking
configure/make if `CC_<target>`/`AR_<target>` are available in the
environment.
@benesch
Copy link
Member

benesch commented Oct 4, 2024

@benesch based on the conversation I removed the default environment variable set to skip the test, but providing hints to user to skip these checks correspondingly.

Sounds good. Sorry for the delay here. I pushed up a revision of your patch that refactors things to my taste. Thanks very much for putting this together! Will merge if/when CI goes green.

@benesch benesch merged commit 0fab152 into MaterializeInc:master Oct 4, 2024
6 of 8 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants