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

custom_build: map the CFLAGS and CC variables for HOST builds #1004

Closed
wants to merge 1 commit into from

Conversation

codyps
Copy link
Contributor

@codyps codyps commented Dec 3, 2014

If a build.rs script uses gcc-rs, CC and CFLAGS are used to find the
c compiler and flags. Often, host & target will have different flags
and compilers.

Without this mapping (which allows the use of HOST_CC and HOST_CFLAGS),
it was imposible to specify the compiler and cflags to use for the host
while doing cross builds, and gcc-rs would attempt to use the target
compiler and cflags, typically failing.

We preserve the previous behavoir when the HOST_CC and HOST_CFLAGS
variables are unset, though I'm not sure if this is a good idea unless
host happens to equal target. We may want to restrict the fallback in
the future.

If a build.rs script uses gcc-rs, CC and CFLAGS are used to find the
c compiler and flags. Often, host & target will have different flags
and compilers.

Without this mapping (which allows the use of HOST_CC and HOST_CFLAGS),
it was imposible to specify the compiler and cflags to use for the host
while doing cross builds, and gcc-rs would attempt to use the target
compiler and cflags, typically failing.

We preserve the previous behavoir when the HOST_CC and HOST_CFLAGS
variables are unset, though I'm not sure if this is a good idea unless
host happens to equal target. We may want to restrict the fallback in
the future.
@alexcrichton
Copy link
Member

This is actually something I consider to be a fault of gcc-rs, not of Cargo. For example there's no particular reason that we single out CC/CFLAGS and not AR/CXX/CXXFLAGS/LD/etc. Would you be ok moving this logic (probably via CC_$triple) to gcc-rs?

@codyps
Copy link
Contributor Author

codyps commented Dec 3, 2014

Yep, it doesn't seem like quite the right thing to do, but it does get me my HOST/TARGET split without needing to be careful about triples :)

I'm okay with tweaking gcc-rs instead, but:

  • creating env variables that contain '-' (as triples do) via the shell is not fun (have to use env or some other program to create them indirectly). I suppose we could do some s/-/_/.
  • users need to know the triple rust is using for their system (not a problem for my use case as I'm generating all the triples, but for casual use this could be problematic).

@alexcrichton
Copy link
Member

I was thinking that for example gcc-rs would look at CC_i686_unknown_linux_gnu and then CC to handle cross compiling. That way by default you wouldn't need to set anything in most cases (and never for the host platform), but you could override specifically for targets.

@steveklabnik
Copy link
Member

This also seems to be gcc-rs's fault, not Cargo's fault.

@steveklabnik
Copy link
Member

Also to me, that is. I need more coffee.

@codyps
Copy link
Contributor Author

codyps commented Dec 3, 2014

Closing in favor of gcc-rs pr.

@codyps codyps closed this Dec 3, 2014
@codyps codyps deleted the gcc-rs-fix branch December 4, 2014 06:59
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.

3 participants