From bb0b7d660f47e8c383267a9524ede705859b87d3 Mon Sep 17 00:00:00 2001 From: Sean Cross Date: Thu, 9 Jun 2022 08:40:15 +0800 Subject: [PATCH 1/2] build: compile C code for "xous" operating system The "xous" operating system is enturely Rust-based, meaning it has no libc. Therefore, it relies on `compiler-builtins` for all intrinsics. Unfortunately, there are not yet Rust equivalents for all C functions. For example, triganometric functions are still missing. In the meantime, enable C replacements for these functions so that Rust programs compiled for Xous can call these functions. Signed-off-by: Sean Cross --- library/compiler-builtins/build.rs | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/library/compiler-builtins/build.rs b/library/compiler-builtins/build.rs index 11deffb9c926..876224934211 100644 --- a/library/compiler-builtins/build.rs +++ b/library/compiler-builtins/build.rs @@ -58,9 +58,11 @@ fn main() { // unlikely that the C is really that much better than our own Rust. // * nvptx - everything is bitcode, not compatible with mixed C/Rust // * riscv - the rust-lang/rust distribution container doesn't have a C - // compiler nor is cc-rs ready for compilation to riscv (at this - // time). This can probably be removed in the future - if !target.contains("wasm") && !target.contains("nvptx") && !target.starts_with("riscv") { + // compiler. + if !target.contains("wasm") + && !target.contains("nvptx") + && (!target.starts_with("riscv") || target.contains("xous")) + { #[cfg(feature = "c")] c::compile(&llvm_target, &target); } From 7cdad114a59af6b503f611e82ba3a5fd177c4c36 Mon Sep 17 00:00:00 2001 From: Sean Cross Date: Thu, 9 Sep 2021 11:21:33 +0800 Subject: [PATCH 2/2] math: compile math functions for Xous This adds support for Xous, enabling users to call math functions on primitives such as `cos()`. Signed-off-by: Sean Cross --- library/compiler-builtins/src/lib.rs | 1 + library/compiler-builtins/src/math.rs | 13 ++++++++++++- 2 files changed, 13 insertions(+), 1 deletion(-) diff --git a/library/compiler-builtins/src/lib.rs b/library/compiler-builtins/src/lib.rs index acac040be332..e7bc61e4c0f6 100644 --- a/library/compiler-builtins/src/lib.rs +++ b/library/compiler-builtins/src/lib.rs @@ -46,6 +46,7 @@ pub mod int; all(target_family = "wasm", target_os = "unknown"), all(target_arch = "x86_64", target_os = "uefi"), all(target_arch = "arm", target_os = "none"), + target_os = "xous", all(target_vendor = "fortanix", target_env = "sgx") ))] pub mod math; diff --git a/library/compiler-builtins/src/math.rs b/library/compiler-builtins/src/math.rs index fa59753f8f6c..14a65395eb8e 100644 --- a/library/compiler-builtins/src/math.rs +++ b/library/compiler-builtins/src/math.rs @@ -20,6 +20,7 @@ macro_rules! no_mangle { target_os = "unknown", not(target_env = "wasi") ), + target_os = "xous", all(target_arch = "x86_64", target_os = "uefi"), all(target_arch = "xtensa", target_os = "none"), all(target_vendor = "fortanix", target_env = "sgx") @@ -70,6 +71,7 @@ no_mangle! { target_os = "unknown", not(target_env = "wasi") ), + target_os = "xous", all(target_arch = "xtensa", target_os = "none"), all(target_vendor = "fortanix", target_env = "sgx") ))] @@ -93,7 +95,16 @@ no_mangle! { fn tanf(n: f32) -> f32; } -#[cfg(all(target_vendor = "fortanix", target_env = "sgx"))] +#[cfg(target_os = "xous")] +no_mangle! { + fn sqrtf(x: f32) -> f32; + fn sqrt(x: f64) -> f64; +} + +#[cfg(any( + all(target_vendor = "fortanix", target_env = "sgx"), + target_os = "xous" +))] no_mangle! { fn ceil(x: f64) -> f64; fn ceilf(x: f32) -> f32;