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

Use a search list to find a compatible toolchain #521

Merged
merged 2 commits into from Jun 29, 2020

Conversation

xobs
Copy link
Contributor

@xobs xobs commented Jun 25, 2020

This adds toolchain detection support and activates it for riscv embedded targets. This enables cc to search for compatible toolchains using a whitelist of targets.

For example, the following builds a test project using riscv64-unknown-elf-gcc when targeting riscv32imac-unknown-none-elf:

[7:40:55 PM] D:/Code/Betrusted/cctest> riscv32-unknown-elf-gcc
riscv32-unknown-elf-gcc: The term 'riscv32-unknown-elf-gcc' is not recognized as the name of a cmdlet, function, script file, or operable program.
Check the spelling of the name, or if a path was included, verify that the path is correct and try again.
[7:40:58 PM] D:/Code/Betrusted/cctest> riscv64-unknown-elf-gcc
riscv64-unknown-elf-gcc.exe: fatal error: no input files
compilation terminated.
[7:41:01 PM] D:/Code/Betrusted/cctest> cargo build --target riscv32imac-unknown-none-elf
    Finished dev [unoptimized + debuginfo] target(s) in 0.17s
[7:41:05 PM] D:/Code/Betrusted/cctest>

This closes #519

@xobs
Copy link
Contributor Author

xobs commented Jun 25, 2020

Also, I have a small test project that I put together. Nothing fancy, but it does show that it works. Is this the sort of thing that would be useful to have in CI, or not (because it's a tier 3 target)?

@alexcrichton
Copy link
Member

Nah I'm always happy to try to add more CI here so long as it doesn't put much of a burden on maintenance!

src/lib.rs Show resolved Hide resolved
src/lib.rs Outdated Show resolved Hide resolved
@xobs xobs force-pushed the find-working-gnu-prefix branch 2 times, most recently from b4e50a7 to e578fba Compare June 26, 2020 04:13
src/lib.rs Outdated
.map(|host| host.contains("windows"))
.unwrap_or(false);
let suffix = if self.cpp { "-g++" } else { "-gcc" };
let extension = if windows_host { ".exe" } else { "" };
Copy link
Member

Choose a reason for hiding this comment

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

I think this can be replaced with std::env::consts::EXE_SUFFIX perhaps?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I had no idea this was a thing. Thanks for pointing it out.

src/lib.rs Outdated
{
return Some(*prefix);
}
}
Copy link
Member

Choose a reason for hiding this comment

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

Could the order of the loops be inverted here? That way if /usr/bin is near the front of PATH we won't have to search for everything everywhere that doesn't exist.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I've made this change as requested.

src/lib.rs Outdated
.as_ref()
.and_then(|path_entries| {
env::split_paths(path_entries)
.find(|path_entry| path_entry.join(&target_compiler).exists())
Copy link
Member

Choose a reason for hiding this comment

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

.find(..).is_some() can be replaced with .any(...)

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, I also didn't know about this construct. However, as part of inverting the two loops, this ended up being unnecessary. And in fact the whole thing got collapsed down to a single statement.

xobs added 2 commits June 27, 2020 13:16
Add `find_working_gnu_prefix()` to iterate through a slice of potential
compiler prefixes, and return the first one that succeeds.

This is useful when there is not yet a single clear toolchain prefix,
for example with riscv (riscv64-unknown-none-elf vs
riscv32-unknown-none-elf vs riscv-none-embed).

Signed-off-by: Sean Cross <sean@xobs.io>
riscv currently has several competing compiler toolchain prefixes. If a
toolchain supports multilib, then an "incorrect" target triple may be
used.

For example, many distributions ship multilib toolchains with a
`riscv64` prefix, so a riscv32imac-unknown-none-elf target can
successfully use a toolchain with a triple of `riscv64-unknown-none`.

Signed-off-by: Sean Cross <sean@xobs.io>
@alexcrichton alexcrichton merged commit fbc1214 into rust-lang:master Jun 29, 2020
@alexcrichton
Copy link
Member

👍

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.

Allow for multiple common toolchain prefixes for a given target
2 participants