Skip to content
Closed
Changes from all commits
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
28 changes: 28 additions & 0 deletions compiler/generator/rust/rust_code_container.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -295,6 +295,8 @@ void RustCodeContainer::produceClass()
// Missing math functions
// See: https://users.rust-lang.org/t/analog-of-c-std-remainder/59670
if (gGlobal->gFloatSize == 1 && !gGlobal->gRustNoLibm) {
*fOut << "#[cfg(not(target_arch = \"wasm32\"))] // Compile ffi bindings only on non-wasm targets";
tab(n, *fOut);
*fOut << "mod ffi {";
tab(n + 1, *fOut);
*fOut << "use std::os::raw::c_float;";
Expand All @@ -315,13 +317,25 @@ void RustCodeContainer::produceClass()
tab(n, *fOut);
*fOut << "fn remainder_f32(from: f32, to: f32) -> f32 {";
tab(n + 1, *fOut);
*fOut << "#[cfg(not(target_arch = \"wasm32\"))] // non-wasm targets use ffi bindings";
tab(n + 1, *fOut);
*fOut << "unsafe { ffi::remainderf(from, to) }";
tab(n + 1, *fOut);
*fOut << "#[cfg(target_arch = \"wasm32\")] // wasm relies on libm";
tab(n + 1, *fOut);
*fOut << "libm::remainderf(from, to)";
tab(n, *fOut);
*fOut << "}";
tab(n, *fOut);
*fOut << "fn rint_f32(val: f32) -> f32 {";
tab(n + 1, *fOut);
*fOut << "#[cfg(not(target_arch = \"wasm32\"))] // non-wasm targets use ffi bindings";
tab(n + 1, *fOut);
*fOut << "unsafe { ffi::rintf(val) }";
tab(n + 1, *fOut);
*fOut << "#[cfg(target_arch = \"wasm32\")] // wasm relies on libm";
tab(n + 1, *fOut);
*fOut << "libm::rintf(val)";
tab(n, *fOut);
*fOut << "}";
tab(n, *fOut);
Expand All @@ -332,6 +346,8 @@ void RustCodeContainer::produceClass()
tab(n, *fOut);
*/
} else if (gGlobal->gFloatSize == 2 && !gGlobal->gRustNoLibm) {
*fOut << "#[cfg(not(target_arch = \"wasm32\"))] // Compile ffi bindings only on non-wasm targets";
tab(n + 1, *fOut);
*fOut << "mod ffi {";
tab(n + 1, *fOut);
*fOut << "use std::os::raw::c_double;";
Expand All @@ -352,13 +368,25 @@ void RustCodeContainer::produceClass()
tab(n, *fOut);
*fOut << "fn remainder_f64(from: f64, to: f64) -> f64 {";
tab(n + 1, *fOut);
*fOut << "#[cfg(not(target_arch = \"wasm32\"))] // non-wasm targets use ffi bindings";
tab(n + 1, *fOut);
*fOut << "unsafe { ffi::remainder(from, to) }";
tab(n + 1, *fOut);
*fOut << "#[cfg(target_arch = \"wasm32\")] // wasm relies on libm";
tab(n + 1, *fOut);
*fOut << "libm::remainder(from, to)";
tab(n, *fOut);
*fOut << "}";
tab(n, *fOut);
*fOut << "fn rint_f64(val: f64) -> f64 {";
tab(n + 1, *fOut);
*fOut << "#[cfg(not(target_arch = \"wasm32\"))] // non-wasm targets use ffi bindings";
tab(n + 1, *fOut);
*fOut << "unsafe { ffi::rint(val) }";
tab(n + 1, *fOut);
*fOut << "#[cfg(target_arch = \"wasm32\")] // wasm relies on libm";
tab(n + 1, *fOut);
*fOut << "libm::rint(val)";
tab(n, *fOut);
*fOut << "}";
tab(n, *fOut);
Expand Down