Skip to content
Merged
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
17 changes: 12 additions & 5 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -71,13 +71,20 @@ rustc-dep-of-std = ['compiler-builtins', 'core']
# are not normally public but are required by the `testcrate`
public-test-deps = []

[[example]]
name = "intrinsics"
required-features = ["compiler-builtins"]

[workspace]
resolver = "2"
members = ["testcrate"]
members = [
# Note that builtins-test-intrinsics cannot be a default member because it
# needs the `mangled-names` feature disabled, while `testcrate` needs it
# enabled.
"builtins-test-intrinsics",
"testcrate",
]

default-members = [
".",
"testcrate",
]

[profile.release]
panic = 'abort'
Expand Down
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,8 @@ It is distributed as part of Rust's sysroot.
[C implementation][2] to Rust.
4. Add a test to compare the behavior of the ported intrinsic(s) with their
implementation on the testing host.
5. Add the intrinsic to `examples/intrinsics.rs` to verify it can be linked on
all targets.
5. Add the intrinsic to `builtins-test-intrinsics/src/main.rs` to verify it
can be linked on all targets.
6. Send a Pull Request (PR).
7. Once the PR passes our extensive testing infrastructure, we'll merge it!
8. Celebrate :tada:
Expand Down
17 changes: 2 additions & 15 deletions build.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ use std::{collections::BTreeMap, env, path::PathBuf, sync::atomic::Ordering};

mod configure;

use configure::{configure_f16_f128, Target};
use configure::{configure_aliases, configure_f16_f128, Target};

fn main() {
println!("cargo::rerun-if-changed=build.rs");
Expand All @@ -13,6 +13,7 @@ fn main() {

configure_check_cfg();
configure_f16_f128(&target);
configure_aliases(&target);

configure_libm(&target);

Expand Down Expand Up @@ -71,20 +72,6 @@ fn main() {
}
}

// To compile intrinsics.rs for thumb targets, where there is no libc
println!("cargo::rustc-check-cfg=cfg(thumb)");
if llvm_target[0].starts_with("thumb") {
println!("cargo:rustc-cfg=thumb")
}

// compiler-rt `cfg`s away some intrinsics for thumbv6m and thumbv8m.base because
// these targets do not have full Thumb-2 support but only original Thumb-1.
// We have to cfg our code accordingly.
println!("cargo::rustc-check-cfg=cfg(thumb_1)");
if llvm_target[0] == "thumbv6m" || llvm_target[0] == "thumbv8m.base" {
println!("cargo:rustc-cfg=thumb_1")
}

// Only emit the ARM Linux atomic emulation on pre-ARMv6 architectures. This
// includes the old androideabi. It is deprecated but it is available as a
// rustc target (arm-linux-androideabi).
Expand Down
11 changes: 11 additions & 0 deletions builtins-test-intrinsics/Cargo.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
[package]
name = "builtins-test-intrinsics"
version = "0.1.0"
edition = "2021"

[dependencies]
compiler_builtins = { path = "../", features = ["compiler-builtins"]}
panic-handler = { path = '../crates/panic-handler' }

[features]
c = ["compiler_builtins/c"]
11 changes: 11 additions & 0 deletions builtins-test-intrinsics/build.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
mod builtins_configure {
include!("../configure.rs");
}

fn main() {
println!("cargo::rerun-if-changed=../configure.rs");

let target = builtins_configure::Target::from_env();
builtins_configure::configure_f16_f128(&target);
builtins_configure::configure_aliases(&target);
}
File renamed without changes.
18 changes: 9 additions & 9 deletions ci/run.sh
Original file line number Diff line number Diff line change
Expand Up @@ -120,22 +120,22 @@ done

rm -f "${rlib_paths[@]}"

build_intrinsics() {
cargo build --target "$target" -v --example intrinsics "$@"
build_intrinsics_test() {
cargo build --target "$target" -v --package builtins-test-intrinsics "$@"
}

# Verify that we haven't drop any intrinsic/symbol
build_intrinsics
build_intrinsics --release
build_intrinsics --features c
build_intrinsics --features c --release
# Verify that we haven't dropped any intrinsics/symbols
build_intrinsics_test
build_intrinsics_test --release
build_intrinsics_test --features c
build_intrinsics_test --features c --release

# Verify that there are no undefined symbols to `panic` within our
# implementations
CARGO_PROFILE_DEV_LTO=true \
cargo build --target "$target" --example intrinsics
cargo build --target "$target" --package builtins-test-intrinsics
CARGO_PROFILE_RELEASE_LTO=true \
cargo build --target "$target" --example intrinsics --release
cargo build --target "$target" --package builtins-test-intrinsics --release

# Ensure no references to any symbols from core
update_rlib_paths
Expand Down
22 changes: 21 additions & 1 deletion configure.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ use std::env;
#[allow(dead_code)]
pub struct Target {
pub triple: String,
pub triple_split: Vec<String>,
pub opt_level: String,
pub cargo_features: Vec<String>,
pub os: String,
Expand All @@ -19,6 +20,8 @@ pub struct Target {

impl Target {
pub fn from_env() -> Self {
let triple = env::var("TARGET").unwrap();
let triple_split = triple.split('-').map(ToOwned::to_owned).collect();
let little_endian = match env::var("CARGO_CFG_TARGET_ENDIAN").unwrap().as_str() {
"little" => true,
"big" => false,
Expand All @@ -30,7 +33,8 @@ impl Target {
.collect();

Self {
triple: env::var("TARGET").unwrap(),
triple,
triple_split,
os: env::var("CARGO_CFG_TARGET_OS").unwrap(),
opt_level: env::var("OPT_LEVEL").unwrap(),
cargo_features,
Expand All @@ -56,6 +60,22 @@ impl Target {
}
}

pub fn configure_aliases(target: &Target) {
// To compile builtins-test-intrinsics for thumb targets, where there is no libc
println!("cargo::rustc-check-cfg=cfg(thumb)");
if target.triple_split[0].starts_with("thumb") {
println!("cargo:rustc-cfg=thumb")
}

// compiler-rt `cfg`s away some intrinsics for thumbv6m and thumbv8m.base because
// these targets do not have full Thumb-2 support but only original Thumb-1.
// We have to cfg our code accordingly.
println!("cargo::rustc-check-cfg=cfg(thumb_1)");
if target.triple_split[0] == "thumbv6m" || target.triple_split[0] == "thumbv8m.base" {
println!("cargo:rustc-cfg=thumb_1")
}
}

/// Configure whether or not `f16` and `f128` support should be enabled.
pub fn configure_f16_f128(target: &Target) {
// Set whether or not `f16` and `f128` are supported at a basic level by LLVM. This only means
Expand Down
1 change: 1 addition & 0 deletions testcrate/build.rs
Original file line number Diff line number Diff line change
Expand Up @@ -115,5 +115,6 @@ fn main() {
println!("cargo:rustc-cfg=feature=\"{name}\"");
}

builtins_configure::configure_aliases(&target);
builtins_configure::configure_f16_f128(&target);
}
Loading