Stream: t-compiler/help

Topic: patching libc for a new target


Brian Cain (Jul 19 2020 at 02:42, on Zulip):

I'm trying to build libstd for hexagon-unknown-linux-musl. There's some pieces of what I need for this upstream so far.

I am not sure what's the best way to start, so for now I'm just building libstd via bootstrap. First I ran into build issues for libunwind -- the build flags specified in build.rs cause errors w/clang (there's no modern gnu toolchain for my target os, only llvm+clang). I can workaround that for now by omitting the "-std=c99" and "-std=c++11" flags. Now I see errors when libstd tries to build the dependent panic_unwind crate. panic_unwind specifies a version of the libc crate old enough that it didn't have hexagon-unknown-linux-musl support. I tried patching the libc crate by: (1) specifying a newer version of libc in src/panic_unwind/Cargo.toml or (2) adding a [patch.crates-io] to specify a newer libc to any/all of src/tools/rustc-std-workspace-*/Cargo.toml or src/libstd/Cargo.toml. Those all seem ineffective - as if they are not in scope for this crate's build. Has anyone got a good suggestion as how to make progress?

I've also tried cargo xbuild of libstd but ran into issues using the unpatched source for libunwind. I can probably workaround this issue by hacking up the rust-src component.

Jake Goulding (Jul 19 2020 at 12:28, on Zulip):

I happen to be doing the exact same thing for aarch64-apple-darwin. You need to add the patch section in the workspace's Cargo.toml then run cargo update -p libc.

Joshua Nelson (Jul 19 2020 at 12:38, on Zulip):

Maybe it would be good to document this somewhere? Rustc-dev-guide seems like a good place

Jake Goulding (Jul 19 2020 at 12:44, on Zulip):

Maybe a "so you want to target a new platform" section.

Brian Cain (Jul 19 2020 at 14:58, on Zulip):

Yeah, thanks! That seems to help get me further.

Jake Goulding (Jul 19 2020 at 17:39, on Zulip):

Joshua Nelson said:

Maybe it would be good to document this somewhere? Rustc-dev-guide seems like a good place

https://github.com/rust-lang/rustc-dev-guide/pull/805

Brian Cain (Jul 19 2020 at 17:46, on Zulip):

I appreciate this doc update -- this is really useful.

Along these lines -- are there any companies/teams who vendor their own rust toolchain? I'd be pretty curious about that process too.

Jake Goulding (Jul 19 2020 at 17:48, on Zulip):

Brian Cain said:

are there any companies/teams who vendor their own rust toolchain

Like this person?

Brian Cain (Jul 19 2020 at 18:01, on Zulip):

hmm. maybe, sounds like it. So that's on behalf of google?

Brian Cain (Jul 19 2020 at 18:05, on Zulip):

Interesting -- I never considered updating the cc crate. But I see now that it's a dependency of src/libunwind/. Maybe that would be a way to address the compilation failures that I worked around by editing the build.rs?

Jake Goulding (Jul 19 2020 at 18:18, on Zulip):

In my case, I needed to update it to add -arch whatever to the C compiler options. IIRC, backtrace and compiler-builtins were the two primary crates that had C code in them.

Joshua Nelson (Jul 19 2020 at 18:43, on Zulip):

Jake Goulding said:

https://github.com/rust-lang/rustc-dev-guide/pull/805

left a review, thanks for the PR :)

Jake Goulding (Jul 19 2020 at 18:51, on Zulip):
Last update: Jan 22 2021 at 13:15UTC