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

Allow of way to toggle freestanding platform features #356

Merged
merged 2 commits into from
Mar 11, 2024
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion mbedtls-sys/build/cmake.rs
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,9 @@ impl super::BuildConfig {
// thumbv6m-none-eabi, thumbv7em-none-eabi, thumbv7em-none-eabihf,
// thumbv7m-none-eabi probably use arm-none-eabi-gcc which can cause the
// cmake compiler test to fail.
if target.starts_with("thumbv") && target.contains("none-eabi") {
if target.starts_with("thumbv") && target.contains("none-eabi")
|| crate::features::FEATURES.have_platform_component("c_compiler", "freestanding")
Copy link
Collaborator

@Taowyoo Taowyoo Mar 9, 2024

Choose a reason for hiding this comment

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

This will affect the environment which already has freestanding feature.
I think you could just directly read RUST_MBED_C_COMPILER_FREESTANDING and use it here. And it could have a better name, such as RUST_MBED_C_COMPILER_ARM_BAREMETAL or anything more related to the issue or reason here.

In mbedtls-sys/build/features.rs you do not need to change the logic about adding freestanding feature.

Copy link
Collaborator

@Taowyoo Taowyoo Mar 9, 2024

Choose a reason for hiding this comment

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

Also, I am thinking if your case can be determined by checking some property of cc here.

Note: cc represents c compiler here, see let cc = cc::Build::new().get_compiler();

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Querying from CC could work but is not guaranteed for example we can check for -none targets however there might be other operating systems that purely only support static libraries.

I've tested 30b7f13 with

$ CFLAGS="-isysroot /opt/arm-gnu-toolchain-13.2.Rel1-x86_64-aarch64-none-elf" CC=clang RUST_MBED_C_COMPILER_BAREMETAL=1 cargo +stable b --target aarch64-unknown-none --no-default-features --features no_std_deps

{
// When building on Linux, -rdynamic flag is added automatically. Changing the
// CMAKE_SYSTEM_NAME to Generic avoids this.
cmk.define("CMAKE_SYSTEM_NAME", "Generic");
Expand Down
7 changes: 6 additions & 1 deletion mbedtls-sys/build/features.rs
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,12 @@ impl Features {
let have_custom_threading = self.have_feature("custom_threading");
let have_custom_gmtime_r = self.have_feature("custom_gmtime_r");

if !self.have_feature("std") || env_have_target_cfg("env", "sgx") || env_have_target_cfg("os", "none") {
println!("cargo:rerun-if-env-changed=RUST_MBED_C_COMPILER_FREESTANDING");
let freestanding = std::env::var("RUST_MBED_C_COMPILER_FREESTANDING")
.map(|x| x == "1")
.unwrap_or_default();

if !self.have_feature("std") || env_have_target_cfg("env", "sgx") || env_have_target_cfg("os", "none") || freestanding {
self.with_feature("c_compiler").unwrap().insert("freestanding");
}
if let Some(components) = self.with_feature("threading") {
Expand Down
Loading