Skip to content

Prepare this crate for more wasm32 compatibility #203

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

Merged
merged 2 commits into from
Nov 3, 2017
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
16 changes: 13 additions & 3 deletions build.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,12 @@ fn main() {
return;
}

// Forcibly enable memory intrinsics on wasm32 as we don't have a libc to
// provide them.
if target.contains("wasm32") {
println!("cargo:rustc-cfg=feature=\"mem\"");
}

// NOTE we are going to assume that llvm-target, what determines our codegen option, matches the
// target triple. This is usually correct for our built-in targets but can break in presence of
// custom targets, which can have arbitrary names.
Expand All @@ -25,9 +31,13 @@ fn main() {
// mangling names though we assume that we're also in test mode so we don't
// build anything and we rely on the upstream implementation of compiler-rt
// functions
if !cfg!(feature = "mangled-names") {
#[cfg(feature = "c")]
c::compile(&llvm_target);
if !cfg!(feature = "mangled-names") && cfg!(feature = "c") {
// no C compiler for wasm
if !target.contains("wasm32") {
#[cfg(feature = "c")]
c::compile(&llvm_target);
println!("cargo:rustc-cfg=use_c");
}
}

// To compile intrinsics.rs for thumb targets, where there is no libc
Expand Down
1 change: 1 addition & 0 deletions ci/run.sh
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,7 @@ case "$TRAVIS_OS_NAME" in
# NOTE OSx's nm doesn't accept the `--defined-only` or provide an equivalent.
# Use GNU nm instead
NM=gnm
brew update
brew install binutils
;;
*)
Expand Down
6 changes: 3 additions & 3 deletions src/macros.rs
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@
/// A quick overview of attributes supported right now are:
///
/// * `use_c_shim_if` - takes a #[cfg] directive and falls back to the
/// C-compiled version if `feature = "c"` is specified.
/// C-compiled version if `use_c` is specified.
/// * `aapcs_on_arm` - forces the ABI of the function to be `"aapcs"` on ARM and
/// the specified ABI everywhere else.
/// * `unadjusted_on_win64` - like `aapcs_on_arm` this switches to the
Expand Down Expand Up @@ -68,7 +68,7 @@ macro_rules! intrinsics {
$($rest:tt)*
) => (

#[cfg(all(feature = "c", $($cfg_clause)*))]
#[cfg(all(use_c, $($cfg_clause)*))]
pub extern $abi fn $name( $($argname: $ty),* ) -> $ret {
extern $abi {
fn $name($($argname: $ty),*) -> $ret;
Expand All @@ -78,7 +78,7 @@ macro_rules! intrinsics {
}
}

#[cfg(not(all(feature = "c", $($cfg_clause)*)))]
#[cfg(not(all(use_c, $($cfg_clause)*)))]
intrinsics! {
$(#[$($attr)*])*
pub extern $abi fn $name( $($argname: $ty),* ) -> $ret {
Expand Down