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

compiler_builtins: base conditional compilation on the specification #36512

Closed
wants to merge 2 commits into from

Conversation

japaric
Copy link
Member

@japaric japaric commented Sep 15, 2016

of the target rather than on its triple (i.e. its name).

As explained in #35474, the current conditional compilation logic, which
is based on the target triple (e.g. x86_64-unknown-linux-gnu), is not
robust in the presence of custom targets as those can have arbitrary
triples (e.g. cortex-m3).

To fix that, this commit changes the conditional compilation logic to
use the specification of the target (e.g. target_arch, target_os, etc.).
For that, compiler_builtins build script now depends on the rustc-cfg
crate, whose role is to shell out to rustc --print cfg and return its
output parsed as a struct.

With the goal of completely removing any direct dependency of the
conditional compilation logic on the target triple, this commit also
exposes the llvm-target field of the target specification via rustc --print cfg.

closes #35474


r? @alexcrichton
cc @brson

TODOs

  • Once this has been given the thumbs up. Merge the llvm-target branch of japaric/rustc-cfg into master and publish a new version of crate.
  • Then make the build script depend on that new version.

of the target rather than on its triple (i.e. its name).

As explained in rust-lang#35474, the current conditional compilation logic, which
is based on the target triple (e.g. x86_64-unknown-linux-gnu), is not
robust in the presence of custom targets as those can have arbitrary
triples (e.g. cortex-m3).

To fix that, this commit changes the conditional compilation logic to
use the specification of the target (e.g. target_arch, target_os, etc.).
For that, compiler_builtins build script now depends on the rustc-cfg
crate, whose role is to shell out to `rustc --print cfg` and return its
output parsed as a `struct`.

With the goal of completely removing any direct dependency of the
conditional compilation logic on the target triple, this commit also
exposes the llvm-target field of the target specification via `rustc
--print cfg`.

closes rust-lang#35474
@rust-highfive
Copy link
Collaborator

Thanks for the pull request, and welcome! The Rust team is excited to review your changes, and you should hear from @alexcrichton (or someone else) soon.

If any changes to this PR are deemed necessary, please add them as extra commits. This ensures that the reviewer can see what has changed since they last reviewed the code. Due to the way GitHub handles out-of-date commits, this should also make it reasonably obvious what issues have or haven't been addressed. Large or tricky changes may require several passes of review and changes.

Please see the contribution instructions for more information.

@japaric
Copy link
Member Author

japaric commented Sep 15, 2016

I'm probably biased but the build script now looks more readable to me. I think it does a better job at conveying its intent.

@codyps
Copy link
Contributor

codyps commented Sep 22, 2016

  • What's the logic for using llvm_target[0] when checking for x86_64, i386, i586, and i686? Why isn't target_arch appropriate there?
  • On looking for eabihf: ideally it seems like we'd want to look at llvm-features or something to determine if hf was enabled. I suppose just looking for the absence of soft-float isn't good enough here?
  • On looking for armv7: this also seems like a llvm-features thing: +v7 should be the one we want, and then a probably guard via target_arch.

Do we not want to expose llvm-features quite yet? If so, I might understand trying to use the llvm triple for now.

@japaric
Copy link
Member Author

japaric commented Sep 22, 2016

What's the logic for using llvm_target[0] when checking for x86_64, i386, i586, and i686? Why isn't target_arch appropriate there?

All the i386, i586 and i686 targets have target_arch = x86 (cf. src/librustc_back/target)
so we can't tell them apart just from that.

I suppose just looking for the absence of soft-float isn't good enough here?

The absence of -C target-feature=+soft-float doesn't indicate that the target has hardware support
for floating point operations. For example, the arm-unknown-linux-gnueabi doesn't have
+soft-float and uses software implementations of floating point operations.

Also -C target-feature=+soft-float doesn't make it to rustc --print cfg output AFAICT.

On looking for armv7: this also seems like a llvm-features thing: +v7 should be the one we want, and then a probably guard via target_arch.

Perhaps. But I think the +v7 target feature is redundant in the current built-in targets. By this
I mean that someone could create a custom target that set llvm-target = armv7-* and omit the +v7
in features and still end up with a target that only uses ARMv7+ instructions (*) and, therefore,
the change you propose would stop including that custom target when it should not.

(*) AFAICT, this is the case for llvm-target = thumbv6m and llvm-target = thumv7m where thumb
is pretty much equivalent to arm but with target-feature=+thumb.

Do we not want to expose llvm-features quite yet?

rustc --print cfg already exposes target_feature in its output. But this doesn't include each
and every feature under the sun, for example, +soft-float doesn't show up there whereas sse
and sse2 do.

@Ericson2314
Copy link
Contributor

Oh great, the "TARGET" env var isnt confused by cross compiling? When did this happen again?

@japaric
Copy link
Member Author

japaric commented Sep 22, 2016

@Ericson2314

TARGET has worked as expected (as in it matches cargo build --target $TARGET) in build.rs since I remember. Have you experienced some problem with it before?

@Ericson2314
Copy link
Contributor

I might be getting confused with rust-lang/rfcs#1721 (comment)

@codyps
Copy link
Contributor

codyps commented Sep 22, 2016

@japaric

Regarding i386/i586/i686: the patch doesn't look like it's trying to tell them apart, which is why I'm wondering if target_arch = x86 isn't more correct:

llvm_target[0] == "i386" || llvm_target[0] == "i586" || llvm_target[0] == "i686"

Is there some other item covered by target_arch = x86 that isn't right?

Regarding things not making it to rustc --print cfg (some of llvm-features): I suppose what I'm getting at is that while we might not expose them, it might be good to have rustc ask llvm about them (if possible, I'm not too familiar with llvm) rather than rust trying to re-impliment parts of llvm's triple parsing.

That said, it seems like it'd be fine to postpone that. This patch is already an improvement on our current situation, and seems unlikely to cause issues if we tweak our llvm-target usage.

@japaric
Copy link
Member Author

japaric commented Sep 23, 2016

Is there some other item covered by target_arch = x86 that isn't right?

Oh, I see. That or expression is equivalent to target_arch == x86 AFAIK. I wonder how that or expression ended up like that :P.

I suppose what I'm getting at is that while we might not expose them, it might be good to have rustc ask llvm about them (if possible, I'm not too familiar with llvm) rather than rust trying to re-impliment parts of llvm's triple parsing.

I pretty much agree. I think the current implementation already does that because I don't see other way how rustc --print cfg could print sse as there is no +sse in the target definition.

@bors
Copy link
Contributor

bors commented Sep 26, 2016

☔ The latest upstream changes (presumably #36719) made this pull request unmergeable. Please resolve the merge conflicts.

@@ -13,3 +13,4 @@ core = { path = "../libcore" }

[build-dependencies]
gcc = "0.3.27"
rustc-cfg = { git = "https://github.com/japaric/rustc-cfg", branch = "llvm-target" }
Copy link
Member

@alexcrichton alexcrichton Sep 28, 2016

Choose a reason for hiding this comment

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

I had some comments on the other PR, but I'm not 100% sure that this is buying us enough to pull in a dependency. Many of the .contains are now just relevant_piece == "foo", which is good to work over parsed forms but hasn't cause ambiguity problems in the past?

Copy link
Member Author

Choose a reason for hiding this comment

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

The rationale is to make this crate more robust at handling custom targets whose triple may be foo or any other arbitrary name. My main motivation was to handle Cortex-M targets which are currently customs target and may be named whatever by downstream users. But if those Cortex-M targets land in tree then I'm OK with not landing this PR.

Copy link
Contributor

Choose a reason for hiding this comment

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

I was talking to @japaric about this the other day. This basically does what the extra env vars from rust-lang/rfcs#1721 would do, so it can be considered a stop-gap perhaps.

@@ -949,6 +950,7 @@ pub fn default_configuration(sess: &Session) -> ast::CrateConfig {
mk(InternedString::new("target_pointer_width"), intern(wordsz)),
mk(InternedString::new("target_env"), intern(env)),
mk(InternedString::new("target_vendor"), intern(vendor)),
mk(InternedString::new("llvm_target"), intern(llvm_target)),
Copy link
Member

Choose a reason for hiding this comment

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

This is a pretty weighty target-cfg to add that I'm not sure we'll want to do. Thoughts @brson?

Copy link
Member Author

Choose a reason for hiding this comment

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

Note that this is not necessary. We can do conditional compilation for Cortex-M targets just fine without this change iff the Cortex-M are named thumbv* because we have to disambiguate betwen Cortex-M and our others ARM+Linux targets. This means we can no longer name them e.g. armv7m-none-eabi, which may be less strange to users, for who "thumb" may not ring a bell.

Copy link
Contributor

Choose a reason for hiding this comment

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

I like this direction actually. I think our target names should just be mere aliases (i.e. just the contents of the target definition matters). As @brson actually has mentioned elsewhere, or current policy of associating fine-grained attributes with triple (via the default targets) unnecessarily clashes with LLVM and other tool.s

@alexcrichton
Copy link
Member

@brson do you have thoughts on this?

I think this'll get more relevant when we do custom compiles of std. My preference currently would be to leave out the addition of the llvm_target cfg directive added here but otherwise use rustc-cfg to learn about the target spec. This means that you can define a custom target with standard values for arch/os/etc and you'll be able to compile without modifications to the standard library. Whereas today if you have a custom target name you may have to upstream a tweak to some build script somewhere.

@japaric beyond the cortex targets which are likely to get added to rustc itself, do you know if there are other examples of where this would prevent the need of having to upstream a patch?

@japaric
Copy link
Member Author

japaric commented Sep 30, 2016

@alexcrichton This sort of already landed upstream in japaric/rust-builtins#74 without the llvm_target part of course.

do you know if there are other examples of where this would prevent the need of having to upstream a patch?

In theory, the 3DS (cf. https://github.com/rust3ds/). But I think this won't work for them without the llvm_target part because their target is named 3ds. Also, I think they don't use std, just some crates below it, but they do need a handful of compiler-rt intrinsics.

@FenrirWolf Could you do me a favor and try to compile the rustc-builtins crate for the 3DS but with the "c" Cargo feature enabled? As in cd rustc-builtins && cargo build --target 3ds --features c. Does it compile?

@FenrirWolf
Copy link
Contributor

Yeah, we don't have the standard library since the cross-compiling toolchain we're using is based on a hacked up newlib without pthreads and some other things. It's homebrew stuff, which is to say it's the height of instability and it's a miracle that it works at all. =P

Anyway, this is what I got when trying to compile rustc-builtins with ---features c:

> ~/projects/rustc-builtins$ cargo build --target 3ds --features c
   Compiling rustc_builtins v0.1.0 (file:///home/fenrir/projects/rustc-builtins)
error: failed to run custom build command for `rustc_builtins v0.1.0 (file:///home/fenrir/projects/rustc-builtins)`
process didn't exit successfully: `/home/fenrir/projects/rustc-builtins/target/debug/build/rustc_builtins-49d55fc18653e6c7/build-script-build` (exit code: 101)
--- stdout
cargo:rerun-if-changed=build.rs
cargo:rerun-if-changed=compiler-rt/compiler-rt-cdylib/compiler-rt/lib/builtins/absvdi2.c
cargo:rerun-if-changed=compiler-rt/compiler-rt-cdylib/compiler-rt/lib/builtins/absvsi2.c
cargo:rerun-if-changed=compiler-rt/compiler-rt-cdylib/compiler-rt/lib/builtins/absvti2.c
cargo:rerun-if-changed=compiler-rt/compiler-rt-cdylib/compiler-rt/lib/builtins/addtf3.c
cargo:rerun-if-changed=compiler-rt/compiler-rt-cdylib/compiler-rt/lib/builtins/addvdi3.c
cargo:rerun-if-changed=compiler-rt/compiler-rt-cdylib/compiler-rt/lib/builtins/addvsi3.c
cargo:rerun-if-changed=compiler-rt/compiler-rt-cdylib/compiler-rt/lib/builtins/addvti3.c
cargo:rerun-if-changed=compiler-rt/compiler-rt-cdylib/compiler-rt/lib/builtins/arm/aeabi_cdcmp.S
cargo:rerun-if-changed=compiler-rt/compiler-rt-cdylib/compiler-rt/lib/builtins/arm/aeabi_cdcmpeq_check_nan.c
cargo:rerun-if-changed=compiler-rt/compiler-rt-cdylib/compiler-rt/lib/builtins/arm/aeabi_cfcmp.S
cargo:rerun-if-changed=compiler-rt/compiler-rt-cdylib/compiler-rt/lib/builtins/arm/aeabi_cfcmpeq_check_nan.c
cargo:rerun-if-changed=compiler-rt/compiler-rt-cdylib/compiler-rt/lib/builtins/arm/aeabi_dcmp.S
cargo:rerun-if-changed=compiler-rt/compiler-rt-cdylib/compiler-rt/lib/builtins/arm/aeabi_div0.c
cargo:rerun-if-changed=compiler-rt/compiler-rt-cdylib/compiler-rt/lib/builtins/arm/aeabi_drsub.c
cargo:rerun-if-changed=compiler-rt/compiler-rt-cdylib/compiler-rt/lib/builtins/arm/aeabi_fcmp.S
cargo:rerun-if-changed=compiler-rt/compiler-rt-cdylib/compiler-rt/lib/builtins/arm/aeabi_frsub.c
cargo:rerun-if-changed=compiler-rt/compiler-rt-cdylib/compiler-rt/lib/builtins/apple_versioning.c
cargo:rerun-if-changed=compiler-rt/compiler-rt-cdylib/compiler-rt/lib/builtins/ashlti3.c
cargo:rerun-if-changed=compiler-rt/compiler-rt-cdylib/compiler-rt/lib/builtins/ashrti3.c
cargo:rerun-if-changed=compiler-rt/compiler-rt-cdylib/compiler-rt/lib/builtins/arm/bswapdi2.S
cargo:rerun-if-changed=compiler-rt/compiler-rt-cdylib/compiler-rt/lib/builtins/arm/bswapsi2.S
cargo:rerun-if-changed=compiler-rt/compiler-rt-cdylib/compiler-rt/lib/builtins/clear_cache.c
cargo:rerun-if-changed=compiler-rt/compiler-rt-cdylib/compiler-rt/lib/builtins/arm/clzdi2.S
cargo:rerun-if-changed=compiler-rt/compiler-rt-cdylib/compiler-rt/lib/builtins/arm/clzsi2.S
cargo:rerun-if-changed=compiler-rt/compiler-rt-cdylib/compiler-rt/lib/builtins/clzti2.c
cargo:rerun-if-changed=compiler-rt/compiler-rt-cdylib/compiler-rt/lib/builtins/cmpdi2.c
cargo:rerun-if-changed=compiler-rt/compiler-rt-cdylib/compiler-rt/lib/builtins/cmpti2.c
cargo:rerun-if-changed=compiler-rt/compiler-rt-cdylib/compiler-rt/lib/builtins/comparedf2.c
cargo:rerun-if-changed=compiler-rt/compiler-rt-cdylib/compiler-rt/lib/builtins/arm/comparesf2.S
cargo:rerun-if-changed=compiler-rt/compiler-rt-cdylib/compiler-rt/lib/builtins/ctzdi2.c
cargo:rerun-if-changed=compiler-rt/compiler-rt-cdylib/compiler-rt/lib/builtins/ctzsi2.c
cargo:rerun-if-changed=compiler-rt/compiler-rt-cdylib/compiler-rt/lib/builtins/ctzti2.c
cargo:rerun-if-changed=compiler-rt/compiler-rt-cdylib/compiler-rt/lib/builtins/divdc3.c
cargo:rerun-if-changed=compiler-rt/compiler-rt-cdylib/compiler-rt/lib/builtins/divdf3.c
cargo:rerun-if-changed=compiler-rt/compiler-rt-cdylib/compiler-rt/lib/builtins/arm/divmodsi4.S
cargo:rerun-if-changed=compiler-rt/compiler-rt-cdylib/compiler-rt/lib/builtins/divsc3.c
cargo:rerun-if-changed=compiler-rt/compiler-rt-cdylib/compiler-rt/lib/builtins/divsf3.c
cargo:rerun-if-changed=compiler-rt/compiler-rt-cdylib/compiler-rt/lib/builtins/arm/divsi3.S
cargo:rerun-if-changed=compiler-rt/compiler-rt-cdylib/compiler-rt/lib/builtins/divtf3.c
cargo:rerun-if-changed=compiler-rt/compiler-rt-cdylib/compiler-rt/lib/builtins/divti3.c
cargo:rerun-if-changed=compiler-rt/compiler-rt-cdylib/compiler-rt/lib/builtins/divxc3.c
cargo:rerun-if-changed=compiler-rt/compiler-rt-cdylib/compiler-rt/lib/builtins/extendhfsf2.c
cargo:rerun-if-changed=compiler-rt/compiler-rt-cdylib/compiler-rt/lib/builtins/extendsfdf2.c
cargo:rerun-if-changed=compiler-rt/compiler-rt-cdylib/compiler-rt/lib/builtins/ffsdi2.c
cargo:rerun-if-changed=compiler-rt/compiler-rt-cdylib/compiler-rt/lib/builtins/ffsti2.c
cargo:rerun-if-changed=compiler-rt/compiler-rt-cdylib/compiler-rt/lib/builtins/fixdfdi.c
cargo:rerun-if-changed=compiler-rt/compiler-rt-cdylib/compiler-rt/lib/builtins/fixdfsi.c
cargo:rerun-if-changed=compiler-rt/compiler-rt-cdylib/compiler-rt/lib/builtins/fixdfti.c
cargo:rerun-if-changed=compiler-rt/compiler-rt-cdylib/compiler-rt/lib/builtins/fixsfdi.c
cargo:rerun-if-changed=compiler-rt/compiler-rt-cdylib/compiler-rt/lib/builtins/fixsfsi.c
cargo:rerun-if-changed=compiler-rt/compiler-rt-cdylib/compiler-rt/lib/builtins/fixsfti.c
cargo:rerun-if-changed=compiler-rt/compiler-rt-cdylib/compiler-rt/lib/builtins/fixunsdfdi.c
cargo:rerun-if-changed=compiler-rt/compiler-rt-cdylib/compiler-rt/lib/builtins/fixunsdfsi.c
cargo:rerun-if-changed=compiler-rt/compiler-rt-cdylib/compiler-rt/lib/builtins/fixunsdfti.c
cargo:rerun-if-changed=compiler-rt/compiler-rt-cdylib/compiler-rt/lib/builtins/fixunssfdi.c
cargo:rerun-if-changed=compiler-rt/compiler-rt-cdylib/compiler-rt/lib/builtins/fixunssfsi.c
cargo:rerun-if-changed=compiler-rt/compiler-rt-cdylib/compiler-rt/lib/builtins/fixunssfti.c
cargo:rerun-if-changed=compiler-rt/compiler-rt-cdylib/compiler-rt/lib/builtins/fixunsxfdi.c
cargo:rerun-if-changed=compiler-rt/compiler-rt-cdylib/compiler-rt/lib/builtins/fixunsxfsi.c
cargo:rerun-if-changed=compiler-rt/compiler-rt-cdylib/compiler-rt/lib/builtins/fixunsxfti.c
cargo:rerun-if-changed=compiler-rt/compiler-rt-cdylib/compiler-rt/lib/builtins/fixxfdi.c
cargo:rerun-if-changed=compiler-rt/compiler-rt-cdylib/compiler-rt/lib/builtins/fixxfti.c
cargo:rerun-if-changed=compiler-rt/compiler-rt-cdylib/compiler-rt/lib/builtins/floatdidf.c
cargo:rerun-if-changed=compiler-rt/compiler-rt-cdylib/compiler-rt/lib/builtins/floatdisf.c
cargo:rerun-if-changed=compiler-rt/compiler-rt-cdylib/compiler-rt/lib/builtins/floatdixf.c
cargo:rerun-if-changed=compiler-rt/compiler-rt-cdylib/compiler-rt/lib/builtins/floatsidf.c
cargo:rerun-if-changed=compiler-rt/compiler-rt-cdylib/compiler-rt/lib/builtins/floatsisf.c
cargo:rerun-if-changed=compiler-rt/compiler-rt-cdylib/compiler-rt/lib/builtins/floattidf.c
cargo:rerun-if-changed=compiler-rt/compiler-rt-cdylib/compiler-rt/lib/builtins/floattisf.c
cargo:rerun-if-changed=compiler-rt/compiler-rt-cdylib/compiler-rt/lib/builtins/floattixf.c
cargo:rerun-if-changed=compiler-rt/compiler-rt-cdylib/compiler-rt/lib/builtins/floatundidf.c
cargo:rerun-if-changed=compiler-rt/compiler-rt-cdylib/compiler-rt/lib/builtins/floatundisf.c
cargo:rerun-if-changed=compiler-rt/compiler-rt-cdylib/compiler-rt/lib/builtins/floatundixf.c
cargo:rerun-if-changed=compiler-rt/compiler-rt-cdylib/compiler-rt/lib/builtins/floatunsidf.c
cargo:rerun-if-changed=compiler-rt/compiler-rt-cdylib/compiler-rt/lib/builtins/floatunsisf.c
cargo:rerun-if-changed=compiler-rt/compiler-rt-cdylib/compiler-rt/lib/builtins/floatuntidf.c
cargo:rerun-if-changed=compiler-rt/compiler-rt-cdylib/compiler-rt/lib/builtins/floatuntisf.c
cargo:rerun-if-changed=compiler-rt/compiler-rt-cdylib/compiler-rt/lib/builtins/floatuntixf.c
cargo:rerun-if-changed=compiler-rt/compiler-rt-cdylib/compiler-rt/lib/builtins/gcc_personality_v0.c
cargo:rerun-if-changed=compiler-rt/compiler-rt-cdylib/compiler-rt/lib/builtins/int_util.c
cargo:rerun-if-changed=compiler-rt/compiler-rt-cdylib/compiler-rt/lib/builtins/lshrti3.c
cargo:rerun-if-changed=compiler-rt/compiler-rt-cdylib/compiler-rt/lib/builtins/arm/modsi3.S
cargo:rerun-if-changed=compiler-rt/compiler-rt-cdylib/compiler-rt/lib/builtins/modti3.c
cargo:rerun-if-changed=compiler-rt/compiler-rt-cdylib/compiler-rt/lib/builtins/muldc3.c
cargo:rerun-if-changed=compiler-rt/compiler-rt-cdylib/compiler-rt/lib/builtins/muldf3.c
cargo:rerun-if-changed=compiler-rt/compiler-rt-cdylib/compiler-rt/lib/builtins/muloti4.c
cargo:rerun-if-changed=compiler-rt/compiler-rt-cdylib/compiler-rt/lib/builtins/mulsc3.c
cargo:rerun-if-changed=compiler-rt/compiler-rt-cdylib/compiler-rt/lib/builtins/mulsf3.c
cargo:rerun-if-changed=compiler-rt/compiler-rt-cdylib/compiler-rt/lib/builtins/multf3.c
cargo:rerun-if-changed=compiler-rt/compiler-rt-cdylib/compiler-rt/lib/builtins/multi3.c
cargo:rerun-if-changed=compiler-rt/compiler-rt-cdylib/compiler-rt/lib/builtins/mulvdi3.c
cargo:rerun-if-changed=compiler-rt/compiler-rt-cdylib/compiler-rt/lib/builtins/mulvsi3.c
cargo:rerun-if-changed=compiler-rt/compiler-rt-cdylib/compiler-rt/lib/builtins/mulvti3.c
cargo:rerun-if-changed=compiler-rt/compiler-rt-cdylib/compiler-rt/lib/builtins/mulxc3.c
cargo:rerun-if-changed=compiler-rt/compiler-rt-cdylib/compiler-rt/lib/builtins/negdf2.c
cargo:rerun-if-changed=compiler-rt/compiler-rt-cdylib/compiler-rt/lib/builtins/negdi2.c
cargo:rerun-if-changed=compiler-rt/compiler-rt-cdylib/compiler-rt/lib/builtins/negsf2.c
cargo:rerun-if-changed=compiler-rt/compiler-rt-cdylib/compiler-rt/lib/builtins/negti2.c
cargo:rerun-if-changed=compiler-rt/compiler-rt-cdylib/compiler-rt/lib/builtins/negvdi2.c
cargo:rerun-if-changed=compiler-rt/compiler-rt-cdylib/compiler-rt/lib/builtins/negvsi2.c
cargo:rerun-if-changed=compiler-rt/compiler-rt-cdylib/compiler-rt/lib/builtins/negvti2.c
cargo:rerun-if-changed=compiler-rt/compiler-rt-cdylib/compiler-rt/lib/builtins/paritydi2.c
cargo:rerun-if-changed=compiler-rt/compiler-rt-cdylib/compiler-rt/lib/builtins/paritysi2.c
cargo:rerun-if-changed=compiler-rt/compiler-rt-cdylib/compiler-rt/lib/builtins/parityti2.c
cargo:rerun-if-changed=compiler-rt/compiler-rt-cdylib/compiler-rt/lib/builtins/popcountdi2.c
cargo:rerun-if-changed=compiler-rt/compiler-rt-cdylib/compiler-rt/lib/builtins/popcountsi2.c
cargo:rerun-if-changed=compiler-rt/compiler-rt-cdylib/compiler-rt/lib/builtins/popcountti2.c
cargo:rerun-if-changed=compiler-rt/compiler-rt-cdylib/compiler-rt/lib/builtins/powidf2.c
cargo:rerun-if-changed=compiler-rt/compiler-rt-cdylib/compiler-rt/lib/builtins/powisf2.c
cargo:rerun-if-changed=compiler-rt/compiler-rt-cdylib/compiler-rt/lib/builtins/powitf2.c
cargo:rerun-if-changed=compiler-rt/compiler-rt-cdylib/compiler-rt/lib/builtins/powixf2.c
cargo:rerun-if-changed=compiler-rt/compiler-rt-cdylib/compiler-rt/lib/builtins/subdf3.c
cargo:rerun-if-changed=compiler-rt/compiler-rt-cdylib/compiler-rt/lib/builtins/subsf3.c
cargo:rerun-if-changed=compiler-rt/compiler-rt-cdylib/compiler-rt/lib/builtins/subtf3.c
cargo:rerun-if-changed=compiler-rt/compiler-rt-cdylib/compiler-rt/lib/builtins/subvdi3.c
cargo:rerun-if-changed=compiler-rt/compiler-rt-cdylib/compiler-rt/lib/builtins/subvsi3.c
cargo:rerun-if-changed=compiler-rt/compiler-rt-cdylib/compiler-rt/lib/builtins/subvti3.c
cargo:rerun-if-changed=compiler-rt/compiler-rt-cdylib/compiler-rt/lib/builtins/arm/switch16.S
cargo:rerun-if-changed=compiler-rt/compiler-rt-cdylib/compiler-rt/lib/builtins/arm/switch32.S
cargo:rerun-if-changed=compiler-rt/compiler-rt-cdylib/compiler-rt/lib/builtins/arm/switch8.S
cargo:rerun-if-changed=compiler-rt/compiler-rt-cdylib/compiler-rt/lib/builtins/arm/switchu8.S
cargo:rerun-if-changed=compiler-rt/compiler-rt-cdylib/compiler-rt/lib/builtins/arm/sync_synchronize.S
cargo:rerun-if-changed=compiler-rt/compiler-rt-cdylib/compiler-rt/lib/builtins/trampoline_setup.c
cargo:rerun-if-changed=compiler-rt/compiler-rt-cdylib/compiler-rt/lib/builtins/truncdfhf2.c
cargo:rerun-if-changed=compiler-rt/compiler-rt-cdylib/compiler-rt/lib/builtins/truncdfsf2.c
cargo:rerun-if-changed=compiler-rt/compiler-rt-cdylib/compiler-rt/lib/builtins/truncsfhf2.c
cargo:rerun-if-changed=compiler-rt/compiler-rt-cdylib/compiler-rt/lib/builtins/ucmpdi2.c
cargo:rerun-if-changed=compiler-rt/compiler-rt-cdylib/compiler-rt/lib/builtins/ucmpti2.c
cargo:rerun-if-changed=compiler-rt/compiler-rt-cdylib/compiler-rt/lib/builtins/arm/udivmodsi4.S
cargo:rerun-if-changed=compiler-rt/compiler-rt-cdylib/compiler-rt/lib/builtins/udivmodti4.c
cargo:rerun-if-changed=compiler-rt/compiler-rt-cdylib/compiler-rt/lib/builtins/arm/udivsi3.S
cargo:rerun-if-changed=compiler-rt/compiler-rt-cdylib/compiler-rt/lib/builtins/udivti3.c
cargo:rerun-if-changed=compiler-rt/compiler-rt-cdylib/compiler-rt/lib/builtins/arm/umodsi3.S
cargo:rerun-if-changed=compiler-rt/compiler-rt-cdylib/compiler-rt/lib/builtins/umodti3.c
TARGET = Some("3ds")
OPT_LEVEL = Some("0")
PROFILE = Some("debug")
TARGET = Some("3ds")
debug=true opt-level=0
HOST = Some("x86_64-unknown-linux-gnu")
TARGET = Some("3ds")
TARGET = Some("3ds")
HOST = Some("x86_64-unknown-linux-gnu")
CC_3ds = None
CC_3ds = None
TARGET_CC = None
CC = None
HOST = Some("x86_64-unknown-linux-gnu")
TARGET = Some("3ds")
HOST = Some("x86_64-unknown-linux-gnu")
CFLAGS_3ds = None
CFLAGS_3ds = None
TARGET_CFLAGS = None
CFLAGS = None
running: "cc" "-O0" "-ffunction-sections" "-fdata-sections" "-g" "-fPIC" "-fno-builtin" "-fvisibility=hidden" "-fomit-frame-pointer" "-ffreestanding" "-o" "/home/fenrir/projects/rustc-builtins/target/3ds/debug/build/rustc_builtins-49d55fc18653e6c7/out/compiler-rt/compiler-rt-cdylib/compiler-rt/lib/builtins/absvdi2.o" "-c" "compiler-rt/compiler-rt-cdylib/compiler-rt/lib/builtins/absvdi2.c"
cargo:warning=cc: error: compiler-rt/compiler-rt-cdylib/compiler-rt/lib/builtins/absvdi2.c: No such file or directory
cargo:warning=cc: fatal error: no input files
cargo:warning=compilation terminated.
ExitStatus(ExitStatus(256))


command did not execute successfully, got: exit code: 1



--- stderr
thread 'main' panicked at 'explicit panic', /home/fenrir/.cargo/registry/src/github.com-1ecc6299db9ec823/gcc-0.3.35/src/lib.rs:897
note: Run with `RUST_BACKTRACE=1` for a backtrace.

@japaric
Copy link
Member Author

japaric commented Sep 30, 2016

cargo:warning=cc: error: compiler-rt/compiler-rt-cdylib/compiler-rt/lib/builtins/absvdi2.c: No such file or directory

Oh, sorry. You have to checkout the submodule first: git submodule update --init I think.

@japaric
Copy link
Member Author

japaric commented Sep 30, 2016

You have to checkout the submodule first

@alexcrichton On that note, does Cargo checkout the submodules of git = ... dependencies or is the build.rs supposed to do that?

@alexcrichton
Copy link
Member

@japaric ok, thanks for the info. Also yeah, Cargo should check out submodules in git dependencies.

@FenrirWolf
Copy link
Contributor

@japaric My bad. Checked out the submodule and got a different set of errors: http://pastebin.com/FuXKxK0B

@japaric
Copy link
Member Author

japaric commented Sep 30, 2016

@FenrirWolf This time is my bad; I forgot to tell you to configure the compiler.

Please export CC_3ds=/path/to/the-3ds-gcc and cargo build (..) again.

Then could you try the following as well? Rename 3ds.json to arm-none-eabihf.json, then export CC_arm_none_eabihf=/path/to/the-3ds-gcc and finally call cargo build --target arm-none-eabihf --features c.

Does it work in any of these scenarios?

@FenrirWolf
Copy link
Contributor

@japaric Okay, now we're getting somewhere. After setting CC_3ds, I get this result:

fenrir@DGS-Z87-HD3:~/projects/rustc-builtins$ cargo build --target 3ds --features c
   Compiling gcc v0.3.35
   Compiling rustc-cfg v0.1.2
   Compiling rustc_builtins v0.1.0 (file:///home/fenrir/projects/rustc-builtins)
warning: compiler-rt/compiler-rt-cdylib/compiler-rt/lib/builtins/arm/comparesf2.S: Assembler messages:
warning: compiler-rt/compiler-rt-cdylib/compiler-rt/lib/builtins/arm/comparesf2.S:60: Warning: IT blocks containing 32-bit Thumb instructions are deprecated in ARMv8
warning: compiler-rt/compiler-rt-cdylib/compiler-rt/lib/builtins/arm/switch16.S: Assembler messages:
warning: compiler-rt/compiler-rt-cdylib/compiler-rt/lib/builtins/arm/switch16.S:39: Warning: IT blocks containing 32-bit Thumb instructions are deprecated in ARMv8
warning: compiler-rt/compiler-rt-cdylib/compiler-rt/lib/builtins/arm/switch32.S: Assembler messages:
warning: compiler-rt/compiler-rt-cdylib/compiler-rt/lib/builtins/arm/switch32.S:39: Warning: IT blocks containing 32-bit Thumb instructions are deprecated in ARMv8
warning: compiler-rt/compiler-rt-cdylib/compiler-rt/lib/builtins/arm/switch8.S: Assembler messages:
warning: compiler-rt/compiler-rt-cdylib/compiler-rt/lib/builtins/arm/switch8.S:37: Warning: IT blocks containing 32-bit Thumb instructions are deprecated in ARMv8
warning: compiler-rt/compiler-rt-cdylib/compiler-rt/lib/builtins/arm/switchu8.S: Assembler messages:
warning: compiler-rt/compiler-rt-cdylib/compiler-rt/lib/builtins/arm/switchu8.S:37: Warning: IT blocks containing 32-bit Thumb instructions are deprecated in ARMv8
warning: ar: `u' modifier ignored since `D' is the default (see `U')
error[E0463]: can't find crate for `core`

error: aborting due to previous error

error: Could not compile `rustc_builtins`.

To learn more, run the command again with --verbose.

If I let Xargo grab libcore for me, it keeps going until it can't find libc (which is expected since Xargo doesn't compile that).

fenrir@DGS-Z87-HD3:~/projects/rustc-builtins$ xargo build --target 3ds --features c
   Compiling gcc v0.3.35
   Compiling rustc-cfg v0.1.2
   Compiling rustc_builtins v0.1.0 (file:///home/fenrir/projects/rustc-builtins)
warning: compiler-rt/compiler-rt-cdylib/compiler-rt/lib/builtins/arm/comparesf2.S: Assembler messages:
warning: compiler-rt/compiler-rt-cdylib/compiler-rt/lib/builtins/arm/comparesf2.S:60: Warning: IT blocks containing 32-bit Thumb instructions are deprecated in ARMv8
warning: compiler-rt/compiler-rt-cdylib/compiler-rt/lib/builtins/arm/switch16.S: Assembler messages:
warning: compiler-rt/compiler-rt-cdylib/compiler-rt/lib/builtins/arm/switch16.S:39: Warning: IT blocks containing 32-bit Thumb instructions are deprecated in ARMv8
warning: compiler-rt/compiler-rt-cdylib/compiler-rt/lib/builtins/arm/switch32.S: Assembler messages:
warning: compiler-rt/compiler-rt-cdylib/compiler-rt/lib/builtins/arm/switch32.S:39: Warning: IT blocks containing 32-bit Thumb instructions are deprecated in ARMv8
warning: compiler-rt/compiler-rt-cdylib/compiler-rt/lib/builtins/arm/switch8.S: Assembler messages:
warning: compiler-rt/compiler-rt-cdylib/compiler-rt/lib/builtins/arm/switch8.S:37: Warning: IT blocks containing 32-bit Thumb instructions are deprecated in ARMv8
warning: compiler-rt/compiler-rt-cdylib/compiler-rt/lib/builtins/arm/switchu8.S: Assembler messages:
warning: compiler-rt/compiler-rt-cdylib/compiler-rt/lib/builtins/arm/switchu8.S:37: Warning: IT blocks containing 32-bit Thumb instructions are deprecated in ARMv8
warning: ar: `u' modifier ignored since `D' is the default (see `U')
warning: unnecessary `unsafe` block, #[warn(unused_unsafe)] on by default
  --> src/int/sdiv.rs:44:21
   |
44 |             let r = unsafe { $div(a, b) };
   |                     ^^^^^^^^^^^^^^^^^^^^^
...
66 | divmod!(__divmoddi4, __divdi3: i64);
   | ------------------------------------ in this macro invocation

error[E0463]: can't find crate for `libc`
  --> src/bin/intrinsics.rs:16:1
   |
16 | extern crate libc;
   | ^^^^^^^^^^^^^^^^^^ can't find crate

error: aborting due to previous error

error: Could not compile `rustc_builtins`.

To learn more, run the command again with --verbose.
error: `cargo` process didn't exit successfully
fenrir@DGS-Z87-HD3:~/projects/rustc-builtins$ 

@japaric
Copy link
Member Author

japaric commented Oct 1, 2016

it keeps going until it can't find libc

That's fine. src/bin/intrinsics.rs is actually a test and you are trying to compile its std variant using a no_std target. Anyway, it looks like you managed to compile src/lib.rs which means these changes (using rustc-cfg) were worth it because withouth them that crate would have failed to compile for the 3ds. 👍

@alexcrichton
Copy link
Member

ping @japaric, should we wait to do this until moving to the upstream copy of compiler-builtins?

@japaric
Copy link
Member Author

japaric commented Nov 2, 2016

This has landed "upstream" (in rust-lang-nursery/compiler-builtins) and will land in this repo when #36992 lands so I'm going to close this.

@japaric japaric closed this Nov 2, 2016
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.

rustc-builtins: use the target *specification* (rather than its triple) in build.rs
7 participants