Skip to content

Commit

Permalink
Improve Rust backend to have ffi remainder/rint properly compile on W…
Browse files Browse the repository at this point in the history
…indows.
  • Loading branch information
sletz committed Apr 2, 2024
1 parent 5f62e76 commit bde0c9e
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 3 deletions.
23 changes: 21 additions & 2 deletions compiler/generator/rust/rust_code_container.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -178,11 +178,14 @@ void RustCodeContainer::produceClass()
// Missing math functions
// See: https://users.rust-lang.org/t/analog-of-c-std-remainder/59670
if (gGlobal->gFloatSize == 1) {

*fOut << "mod ffi {";
tab(n + 1, *fOut);
*fOut << "use std::os::raw::{c_float};";
tab(n + 1, *fOut);
*fOut << "#[link(name = \"m\")]";
*fOut << "// Conditionally compile the link attribute only on non-Windows platforms";
tab(n + 1, *fOut);
*fOut << "#[cfg_attr(not(target_os=\"windows\"), link(name=\"m\"))]";
tab(n + 1, *fOut);
*fOut << "extern {";
tab(n + 2, *fOut);
Expand All @@ -206,12 +209,21 @@ void RustCodeContainer::produceClass()
tab(n, *fOut);
*fOut << "}";
tab(n, *fOut);

/*
tab(n, *fOut);
*fOut << "fn remainder_f32(a: f32, b: f32) -> f32 { let n = (a/b).round(); a - b*n }";
tab(n, *fOut);
*/
} else if (gGlobal->gFloatSize == 2) {

*fOut << "mod ffi {";
tab(n + 1, *fOut);
*fOut << "use std::os::raw::{c_double};";
tab(n + 1, *fOut);
*fOut << "#[link(name = \"m\")]";
*fOut << "// Conditionally compile the link attribute only on non-Windows platforms";
tab(n + 1, *fOut);
*fOut << "#[cfg_attr(not(target_os=\"windows\"), link(name=\"m\"))]";
tab(n + 1, *fOut);
*fOut << "extern {";
tab(n + 2, *fOut);
Expand All @@ -235,8 +247,15 @@ void RustCodeContainer::produceClass()
tab(n, *fOut);
*fOut << "}";
tab(n, *fOut);

/*
tab(n, *fOut);
*fOut << "fn remainder_f64(a: f64, b: f64) -> f64 { let n = (a/b).round(); a - b*n }";
tab(n, *fOut);
*/
}


tab(n, *fOut);
*fOut << "#[cfg_attr(feature = \"default-boxed\", derive(default_boxed::DefaultBoxed))]";
if (gGlobal->gReprC) {
Expand Down
2 changes: 1 addition & 1 deletion tools/faust-config
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ function get {
esac
}

SYSTEMLIBS="-lm -lz -lzstd -lcurses -lxml2"
SYSTEMLIBS="-lm -lz -lcurses -lxml2"

if [ "$#" -eq 0 ]
then
Expand Down

0 comments on commit bde0c9e

Please sign in to comment.