From f556a9bbb422e86c76334fe3fe0a3c0382707946 Mon Sep 17 00:00:00 2001 From: Jorge Aparicio Date: Thu, 12 Jul 2018 20:19:42 -0500 Subject: [PATCH] test source importing this crate --- library/compiler-builtins/libm/Cargo.toml | 2 +- library/compiler-builtins/libm/README.md | 5 ++++- library/compiler-builtins/libm/cb/Cargo.toml | 6 ++++++ library/compiler-builtins/libm/cb/src/lib.rs | 9 +++++++++ library/compiler-builtins/libm/ci/script.sh | 10 ++++++++++ 5 files changed, 30 insertions(+), 2 deletions(-) create mode 100644 library/compiler-builtins/libm/cb/Cargo.toml create mode 100644 library/compiler-builtins/libm/cb/src/lib.rs diff --git a/library/compiler-builtins/libm/Cargo.toml b/library/compiler-builtins/libm/Cargo.toml index 96bc290fb320..e3498eed0381 100644 --- a/library/compiler-builtins/libm/Cargo.toml +++ b/library/compiler-builtins/libm/Cargo.toml @@ -4,4 +4,4 @@ version = "0.1.0" authors = ["Jorge Aparicio "] [workspace] -members = ["test-generator"] \ No newline at end of file +members = ["cb", "test-generator"] \ No newline at end of file diff --git a/library/compiler-builtins/libm/README.md b/library/compiler-builtins/libm/README.md index 55f4654346e6..cb29baf63a7b 100644 --- a/library/compiler-builtins/libm/README.md +++ b/library/compiler-builtins/libm/README.md @@ -32,7 +32,7 @@ $ TARGET=armv7-unknown-linux-gnueabihf bash ci/script.sh - Pick your favorite math function from the [issue tracker]. - Look for the C implementation of the function in the [MUSL source code][src]. - Copy paste the C code into a Rust file in the `src/math` directory and adjust `src/math/mod.rs` - accordingly. + accordingly. Also, uncomment the corresponding trait method in `src/lib.rs`. - Run `cargo watch check` and fix the compiler errors. - Tweak the bottom of `test-generator/src/main.rs` to add your function to the test suite. - If you can, run the test suite locally. If you can't, no problem! Your PR will be tested @@ -49,6 +49,9 @@ Check [PR #2] for an example. ### Notes +- Only use relative imports within the `math` directory / module, e.g. `use self::fabs::fabs` or +`use super::isnanf`. Absolute imports from core are OK, e.g. `use core::u64`. + - To reinterpret a float as an integer use the `to_bits` method. The MUSL code uses the `GET_FLOAT_WORD` macro, or a union, to do this operation. diff --git a/library/compiler-builtins/libm/cb/Cargo.toml b/library/compiler-builtins/libm/cb/Cargo.toml new file mode 100644 index 000000000000..40e75dd22fd1 --- /dev/null +++ b/library/compiler-builtins/libm/cb/Cargo.toml @@ -0,0 +1,6 @@ +[package] +name = "cb" +version = "0.1.0" +authors = ["Jorge Aparicio "] + +[dependencies] diff --git a/library/compiler-builtins/libm/cb/src/lib.rs b/library/compiler-builtins/libm/cb/src/lib.rs new file mode 100644 index 000000000000..439ba7dc4e63 --- /dev/null +++ b/library/compiler-builtins/libm/cb/src/lib.rs @@ -0,0 +1,9 @@ +//! Fake compiler-builtins crate +//! +//! This is used to test that we can source import `libm` into the compiler-builtins crate. + +#![allow(dead_code)] +#![no_std] + +#[path = "../../src/math/mod.rs"] +mod libm; diff --git a/library/compiler-builtins/libm/ci/script.sh b/library/compiler-builtins/libm/ci/script.sh index ee2e458cc036..3db6bfeb12d9 100644 --- a/library/compiler-builtins/libm/ci/script.sh +++ b/library/compiler-builtins/libm/ci/script.sh @@ -1,11 +1,21 @@ set -euxo pipefail main() { + # quick check + cargo check + + # check that we can source import libm into compiler-builtins + cargo check --package cb + + # generate tests cargo run --package test-generator --target x86_64-unknown-linux-musl + if cargo fmt --version >/dev/null 2>&1; then # nicer syntax error messages (if any) cargo fmt fi + + # run tests cross test --target $TARGET --release # TODO need to fix overflow issues (cf. issue #4)