Skip to content

Commit

Permalink
add relibm crate
Browse files Browse the repository at this point in the history
  • Loading branch information
augustin-cheron committed Jan 27, 2020
1 parent 3d729b7 commit 4605b93
Show file tree
Hide file tree
Showing 12 changed files with 1,212 additions and 0 deletions.
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -6,3 +6,6 @@
/target
/tests
Cargo.lock
# libm-c-abi tests folders
libc-test
openlibm
1 change: 1 addition & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ musl-reference-tests = ['rand']
members = [
"crates/compiler-builtins-smoke-test",
"crates/libm-bench",
"crates/libm-c-abi"
]

[dev-dependencies]
Expand Down
14 changes: 14 additions & 0 deletions crates/libm-c-abi/Cargo.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
[package]
name = "relibm"
version = "0.1.0"
authors = ["augustin <[email protected]>"]
description = "Expose rust libm functions in a c abi compatible library. This is highly experimental. This crate is for test purpose only."
edition = "2018"
license = "MIT OR Apache-2.0"

[lib]
crate-type = ["staticlib", "cdylib"]

[dependencies]
libm = { path = "../.." }
libc = {version="0.2", default-features=false}
15 changes: 15 additions & 0 deletions crates/libm-c-abi/example/Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
mkfile_path := $(abspath $(lastword $(MAKEFILE_LIST)))
mkfile_dir := $(dir $(mkfile_path))

ifndef CARGO_TARGET_DIR
override CARGO_TARGET_DIR = "../"
endif
CRATE_RELEASE_DIR := $(CARGO_TARGET_DIR)release
LDLIBS += -L $(CRATE_RELEASE_DIR) -lrelibm -Wl,-rpath=$(CRATE_RELEASE_DIR)

all: shared

shared:
clang simple.c $(LDLIBS)
static:
clang simple.c $(CRATE_RELEASE_DIR)/librelibm.a
15 changes: 15 additions & 0 deletions crates/libm-c-abi/example/simple.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
/*
* Simple test program.
* You can use it to debug test case outside the test suite.
* This is usefull to debug in parallel the C and rust version, to float debug precision issue.
*/
#include <math.h>
#include <stdio.h>

int main(void)
{
double res = y0(0x1.c982eb8d417eap-1);
double want = -0x1.af74bfa0f1304p-56;
double got = -0x1p-55;
printf("want: %a : got : %a\ngot in test : %a\n", want, res, got);
}
12 changes: 12 additions & 0 deletions crates/libm-c-abi/src/lib.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
mod lib_f32;
mod lib_f64;
mod lib_fenv;
mod lib_long_double;

pub use lib_f32::*;
pub use lib_f64::*;
pub use lib_fenv::*;
pub use lib_long_double::*;

#[no_mangle]
pub static mut signgam: i32 = 0;
Loading

0 comments on commit 4605b93

Please sign in to comment.