Skip to content

Commit b4a3645

Browse files
authored
Merge pull request #248 from japaric/libm
expose math symbols on wasm32-unknown-unknown
2 parents 5d370bb + d73ccba commit b4a3645

File tree

5 files changed

+62
-0
lines changed

5 files changed

+62
-0
lines changed

.gitmodules

+3
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,6 @@
11
[submodule "compiler-rt"]
22
path = compiler-rt
33
url = https://github.com/rust-lang/compiler-rt
4+
[submodule "libm"]
5+
path = libm
6+
url = https://github.com/japaric/libm

.travis.yml

+3
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,9 @@ matrix:
2525
- env: TARGET=thumbv7em-linux-eabi
2626
- env: TARGET=thumbv7em-linux-eabihf
2727
- env: TARGET=thumbv7m-linux-eabi
28+
- env: TARGET=wasm32-unknown-unknown
29+
install: rustup target add $TARGET
30+
script: cargo build --target $TARGET
2831
- env: TARGET=x86_64-apple-darwin
2932
os: osx
3033
- env: TARGET=x86_64-unknown-linux-gnu

libm

Submodule libm added at d65f60f

src/lib.rs

+3
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,9 @@ pub mod int;
4848
pub mod float;
4949

5050
pub mod mem;
51+
// only for the wasm32-unknown-unknown target
52+
#[cfg(all(target_arch = "wasm32", target_os = "unknown"))]
53+
pub mod math;
5154

5255
#[cfg(target_arch = "arm")]
5356
pub mod arm;

src/math.rs

+52
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
1+
#[allow(dead_code)]
2+
#[path = "../libm/src/math/mod.rs"]
3+
mod libm;
4+
5+
macro_rules! no_mangle {
6+
($(fn $fun:ident($($iid:ident : $ity:ty),+) -> $oty:ty;)+) => {
7+
intrinsics! {
8+
$(
9+
pub extern "C" fn $fun($($iid: $ity),+) -> $oty {
10+
self::libm::$fun($($iid),+)
11+
}
12+
)+
13+
}
14+
}
15+
}
16+
17+
no_mangle! {
18+
fn acos(x: f64) -> f64;
19+
fn asin(x: f64) -> f64;
20+
fn atan(x: f64) -> f64;
21+
fn atan2(x: f64, y: f64) -> f64;
22+
fn cbrt(x: f64) -> f64;
23+
fn cosh(x: f64) -> f64;
24+
fn expm1(x: f64) -> f64;
25+
fn hypot(x: f64, y: f64) -> f64;
26+
fn log1p(x: f64) -> f64;
27+
fn sinh(x: f64) -> f64;
28+
fn tan(x: f64) -> f64;
29+
fn tanh(x: f64) -> f64;
30+
fn cos(x: f64) -> f64;
31+
fn cosf(x: f32) -> f32;
32+
fn exp(x: f64) -> f64;
33+
fn expf(x: f32) -> f32;
34+
fn log2(x: f64) -> f64;
35+
fn log2f(x: f32) -> f32;
36+
fn log10(x: f64) -> f64;
37+
fn log10f(x: f32) -> f32;
38+
fn log(x: f64) -> f64;
39+
fn logf(x: f32) -> f32;
40+
fn round(x: f64) -> f64;
41+
fn roundf(x: f32) -> f32;
42+
fn sin(x: f64) -> f64;
43+
fn sinf(x: f32) -> f32;
44+
fn pow(x: f64, y: f64) -> f64;
45+
fn powf(x: f32, y: f32) -> f32;
46+
fn exp2(x: f64) -> f64;
47+
fn exp2f(x: f32) -> f32;
48+
fn fmod(x: f64, y: f64) -> f64;
49+
fn fmodf(x: f32, y: f32) -> f32;
50+
fn fma(x: f64, y: f64, z: f64) -> f64;
51+
fn fmaf(x: f32, y: f32, z: f32) -> f32;
52+
}

0 commit comments

Comments
 (0)