cfg! target_env for fuchsia?

44 views
Skip to first unread message

Nick Lewycky

unread,
Oct 6, 2020, 7:28:58 PM10/6/20
to rust-f...@fuchsia.com
I'd like to be able to write a cfg! statement that detects when we're targeting a fuchsia environment.

We received a bug report on our open source software caused by the fact that fuchsia rustc links in LLVM's libunwind by default, and that behaves differently from libgcc_s. We have code to work with either implementation already in place selected by a cfg! target_env="musl" but fuchsia rustc sets target_env="gnu". Could you set target_env="fuchsia", or some other property we can cfg! test on?

The different matter of LLVM libunwind behaving differently: https://bugs.llvm.org/show_bug.cgi?id=47750

If you let me know what cfg! change you go with, I'll update our code. Thanks!

Nick

Taylor Cramer

unread,
Oct 6, 2020, 7:33:23 PM10/6/20
to Nick Lewycky, rust-f...@fuchsia.com
Are you looking for #[cfg(target_os = "fuchsia")] ?

--
You received this message because you are subscribed to the Google Groups "rust-fuchsia" group.
To unsubscribe from this group and stop receiving emails from it, send an email to rust-fuchsia...@fuchsia.com.
To view this discussion on the web visit https://groups.google.com/a/fuchsia.com/d/msgid/rust-fuchsia/CAJ%2B86-nCmVa648MPdiiifOYxHYFcFdqn72rm4RdmmE8ifiNVWQ%40mail.gmail.com.

Nick Lewycky

unread,
Oct 6, 2020, 7:36:02 PM10/6/20
to Taylor Cramer, rust-f...@fuchsia.com
I don't think so?:

$ ~/fuchsia-rust/bin/rustc --print cfg | grep target_os
target_os="linux"

I've checked and found that fuchsia's rustc links in LLVM libunwind even without any --target flag setting for fuchsia. Maybe that's the bug?

Taylor Cramer

unread,
Oct 6, 2020, 7:49:20 PM10/6/20
to Nick Lewycky, Petr Hosek, Tyler Mandry, rust-f...@fuchsia.com
Ah, I see, you're asking about detecting the rustc built by the Fuchsia team, not asking about rustc targeting Fuchsia. There're a number of bits of configuration specific to the rustc used by the Fuchsia team that vary from the standard distribution, but these aren't detectable programmatically from Rust code itself. +Petr Hosek +Tyler Mandry for more information.

Tyler Mandry

unread,
Oct 6, 2020, 8:24:34 PM10/6/20
to Taylor Cramer, Nick Lewycky, Petr Hosek, rust-f...@fuchsia.com
I think Taylor's initial answer is correct. rustc --print cfg shows you the config the compiler was built with, i.e. that it was built to run on linux. You can target fuchsia from a compiler running on linux, in which case #[cfg(target_os = "fuchsia")] will detect when you're doing that.

Nick Lewycky

unread,
Oct 6, 2020, 8:45:30 PM10/6/20
to Tyler Mandry, Taylor Cramer, Petr Hosek, rust-f...@fuchsia.com
Taylor correctly answered my question, but I asked the wrong thing. The person who reported the bug says they got their rustc from the Dart SDK which in turn is built out of https://fuchsia.googlesource.com/third_party/rust , but we aren't targeting fuchsia when we build, we're targeting linux.

Your email caused me to check, and I see that adding:

    #[cfg(target_os = "fuchsia")]
    std::compile_error!("fuchsia")

to Wasmer does not trigger a compile error while

    #[cfg(target_os = "linux")]
    std::compile_error!("linux");

does, yet the resulting program is different from one built with stock rustc due to the additional linking of llvm's libunwind. I had assumed you were adding fuchsia support but hadn't added a new target_os/target_env yet in order to continue to work with code that checks for linux os or gnu env.

So my request for a cfg! is wrong, you already have one.

Somehow your rustc fork changed the behaviour of a target_os=linux + target_env=gnu build relative to stock rustc. If that's on purpose it'd be nice to have a cfg! detectable option for, but now I think it's more likely a bug? Or possibly it might be something to do with the way dart SDK builds your rustc?

Nick

Tyler Mandry

unread,
Oct 6, 2020, 9:35:30 PM10/6/20
to Nick Lewycky, Taylor Cramer, Petr Hosek, rust-f...@fuchsia.com, Kit Lane
I see. We don't support our builds of rustc outside of the Fuchsia tree. I'm quite surprised to see that it's in the Dart SDK. I'll try to find out more.

Petr Hosek

unread,
Oct 6, 2020, 11:07:18 PM10/6/20
to Tyler Mandry, Nick Lewycky, Taylor Cramer, rust-f...@fuchsia.com, Kit Lane
We use LLVM libunwind as the implementation for Rust's unwinder (see https://github.com/rust-lang/rust/blob/ef95430b9bb42fefa0a5e885525525bb52d9cb00/config.toml.example#L526) to avoid the dependency on GCC for both technical and legal reasons.

Liam Appelbe

unread,
Oct 7, 2020, 1:15:49 PM10/7/20
to rust-fuchsia, Petr Hosek, ni...@wasmer.io, Taylor Cramer, rust-f...@fuchsia.com, Kit Lane, Tyler Mandry
I can give some more context from the Dart side. We're only using rust to build Wasmer, which we want to use to allow Dart programs to load and run wasm code. Since we need to pull all our compilers etc from CIPD, when I needed rustc I just hunted around on CIPD to find a compiler, and found Fuchisia's (we already use Fuchisa's GN and clang). I wasn't aware that Fuchisia was building rustc in a special way.

Unless there's a trivial fix for this issue, I think it makes more sense for Dart to have it's own copy of rust. I can probably set up a bot to just download vanilla rust and upload it to CIPD.
Reply all
Reply to author
Forward
0 new messages