Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add relibm crate #237

Open
wants to merge 5 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
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
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
5 changes: 3 additions & 2 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -26,10 +26,11 @@ musl-reference-tests = ['rand']
members = [
"crates/compiler-builtins-smoke-test",
"crates/libm-bench",
"crates/libm-c-abi"
]

[dev-dependencies]
no-panic = "0.1.8"
no-panic = "0.1.15"

[build-dependencies]
rand = { version = "0.6.5", optional = true }
rand = { version = "0.8.3", optional = true }
20 changes: 20 additions & 0 deletions crates/libm-c-abi/Cargo.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
[package]
name = "relibm"
version = "0.1.0"
authors = ["augustin <cheron.augustin@gmail.com>"]
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"]

[profile.dev]
panic = "abort"

[profile.release]
panic = "abort"

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

ifndef CARGO_TARGET_DIR
override CARGO_TARGET_DIR = ${mkfile_dir}../../../target
endif

CRATE_RELEASE_DIR := ${CARGO_TARGET_DIR}/release
LDLIBS += -L $(CRATE_RELEASE_DIR) -lrelibm -Wl,-rpath=$(CRATE_RELEASE_DIR)

all: static

shared:
${CC} -ansi --std=c99 simple.c $(LDLIBS)
static:
${CC} -ansi --std=c99 simple.c $(CRATE_RELEASE_DIR)/librelibm.a
Binary file added crates/libm-c-abi/example/a.out
Binary file not shown.
14 changes: 14 additions & 0 deletions crates/libm-c-abi/example/simple.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
/*
* 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;
printf("want: %a : got : %a\n", want, res);
}
44 changes: 44 additions & 0 deletions crates/libm-c-abi/src/lib.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
#![no_std]
#![feature(lang_items)]
#![feature(core_intrinsics)]
use core::intrinsics;
use core::panic::PanicInfo;

mod lib_f32;
mod lib_f64;
mod lib_fenv;
mod lib_long_double;
mod musl_missing;
mod new_lib;

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

pub use musl_missing::*;
pub use new_lib::*;

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


#[panic_handler]
fn panic(_info: &PanicInfo) -> ! {
intrinsics::abort()
}

/*
#[panic_handler]
fn panic(_: &PanicInfo<'_>) -> ! {
extern "Rust" {
#[link_name = "\nerror(panic-never): your program contains at least one panicking branch"]
fn undefined() -> !;
}

unsafe { undefined() }
}
*/

#[lang = "eh_personality"]
extern "C" fn eh_personality() {}
Loading