Skip to content

Commit 1be2858

Browse files
authored
Merge pull request #203 from alexcrichton/wasm
Prepare this crate for more wasm32 compatibility
2 parents 2d414af + 46fbf3a commit 1be2858

File tree

3 files changed

+17
-6
lines changed

3 files changed

+17
-6
lines changed

build.rs

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,12 @@ fn main() {
1212
return;
1313
}
1414

15+
// Forcibly enable memory intrinsics on wasm32 as we don't have a libc to
16+
// provide them.
17+
if target.contains("wasm32") {
18+
println!("cargo:rustc-cfg=feature=\"mem\"");
19+
}
20+
1521
// NOTE we are going to assume that llvm-target, what determines our codegen option, matches the
1622
// target triple. This is usually correct for our built-in targets but can break in presence of
1723
// custom targets, which can have arbitrary names.
@@ -25,9 +31,13 @@ fn main() {
2531
// mangling names though we assume that we're also in test mode so we don't
2632
// build anything and we rely on the upstream implementation of compiler-rt
2733
// functions
28-
if !cfg!(feature = "mangled-names") {
29-
#[cfg(feature = "c")]
30-
c::compile(&llvm_target);
34+
if !cfg!(feature = "mangled-names") && cfg!(feature = "c") {
35+
// no C compiler for wasm
36+
if !target.contains("wasm32") {
37+
#[cfg(feature = "c")]
38+
c::compile(&llvm_target);
39+
println!("cargo:rustc-cfg=use_c");
40+
}
3141
}
3242

3343
// To compile intrinsics.rs for thumb targets, where there is no libc

ci/run.sh

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -65,6 +65,7 @@ case "$TRAVIS_OS_NAME" in
6565
# NOTE OSx's nm doesn't accept the `--defined-only` or provide an equivalent.
6666
# Use GNU nm instead
6767
NM=gnm
68+
brew update
6869
brew install binutils
6970
;;
7071
*)

src/macros.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@
3131
/// A quick overview of attributes supported right now are:
3232
///
3333
/// * `use_c_shim_if` - takes a #[cfg] directive and falls back to the
34-
/// C-compiled version if `feature = "c"` is specified.
34+
/// C-compiled version if `use_c` is specified.
3535
/// * `aapcs_on_arm` - forces the ABI of the function to be `"aapcs"` on ARM and
3636
/// the specified ABI everywhere else.
3737
/// * `unadjusted_on_win64` - like `aapcs_on_arm` this switches to the
@@ -68,7 +68,7 @@ macro_rules! intrinsics {
6868
$($rest:tt)*
6969
) => (
7070

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

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

0 commit comments

Comments
 (0)