소스 검색

expose math symbol on wasm32-unknown-unknown

Jorge Aparicio 6 년 전
부모
커밋
36f93dbd79
5개의 변경된 파일61개의 추가작업 그리고 0개의 파일을 삭제
  1. 3 0
      .gitmodules
  2. 3 0
      .travis.yml
  3. 1 0
      libm
  4. 3 0
      src/lib.rs
  5. 51 0
      src/math.rs

+ 3 - 0
.gitmodules

@@ -1,3 +1,6 @@
 [submodule "compiler-rt"]
 	path = compiler-rt
 	url = https://github.com/rust-lang/compiler-rt
+[submodule "libm"]
+	path = libm
+	url = https://github.com/japaric/libm

+ 3 - 0
.travis.yml

@@ -25,6 +25,9 @@ matrix:
     - env: TARGET=thumbv7em-linux-eabi
     - env: TARGET=thumbv7em-linux-eabihf
     - env: TARGET=thumbv7m-linux-eabi
+    - env: TARGET=wasm32-unknown-unknown
+      install: rustup target add $TARGET
+      script: cargo build --target $TARGET
     - env: TARGET=x86_64-apple-darwin
       os: osx
     - env: TARGET=x86_64-unknown-linux-gnu

+ 1 - 0
libm

@@ -0,0 +1 @@
+Subproject commit d65f60f24289ba212f5d47792f7236857efb2339

+ 3 - 0
src/lib.rs

@@ -48,6 +48,9 @@ pub mod int;
 pub mod float;
 
 pub mod mem;
+// only for the wasm32-unknown-unknown target
+#[cfg(all(target_arch = "wasm32", target_os = "unknown"))]
+pub mod math;
 
 #[cfg(target_arch = "arm")]
 pub mod arm;

+ 51 - 0
src/math.rs

@@ -0,0 +1,51 @@
+#[allow(dead_code)]
+#[path = "../../libm/src/math/mod.rs"]
+mod libm;
+
+macro_rules! no_mangle {
+    ($(fn $fun:ident($($iid:ident : $ity:ty),+) -> $oty:ty;)+) => {
+        $(
+            #[no_mangle]
+            pub fn $fun($($iid: $ity),+) -> $oty {
+                self::libm::$fun($($iid),+)
+            }
+        )+
+    }
+}
+
+no_mangle! {
+    fn acos(x: f64) -> f64;
+    fn asin(x: f64) -> f64;
+    fn atan(x: f64) -> f64;
+    fn atan2(x: f64, y: f64) -> f64;
+    fn cbrt(x: f64) -> f64;
+    fn cosh(x: f64) -> f64;
+    fn expm1(x: f64) -> f64;
+    fn hypot(x: f64, y: f64) -> f64;
+    fn log1p(x: f64) -> f64;
+    fn sinh(x: f64) -> f64;
+    fn tan(x: f64) -> f64;
+    fn tanh(x: f64) -> f64;
+    fn cos(x: f64) -> f64;
+    fn cosf(x: f32) -> f32;
+    fn exp(x: f64) -> f64;
+    fn expf(x: f32) -> f32;
+    fn log2(x: f64) -> f64;
+    fn log2f(x: f32) -> f32;
+    fn log10(x: f64) -> f64;
+    fn log10f(x: f32) -> f32;
+    fn log(x: f64) -> f64;
+    fn logf(x: f32) -> f32;
+    fn round(x: f64) -> f64;
+    fn roundf(x: f32) -> f32;
+    fn sin(x: f64) -> f64;
+    fn sinf(x: f32) -> f32;
+    fn pow(x: f64, y: f64) -> f64;
+    fn powf(x: f32, y: f32) -> f32;
+    fn exp2(x: f64) -> f64;
+    fn exp2f(x: f32) -> f32;
+    fn fmod(x: f64, y: f64) -> f64;
+    fn fmodf(x: f32, y: f32) -> f32;
+    fn fma(x: f64, y: f64, z: f64) -> f64;
+    fn fmaf(x: f32, y: f32, z: f32) -> f32;
+}