Skip to content

Commit f6e483d

Browse files
Rollup merge of rust-lang#152134 - hoodmane:emscripten-crt-static-allow-dylibs, r=petrochenkov
Set crt_static_allow_dylibs to true for Emscripten target And add a test. This is followup work to rust-lang#151704. It introduced a regression where cargo is now unwilling to build cdylibs for Emscripten because `crt_static_default` is `true` but `crt_static_allows_dylibs` is `false`. Unfortunately the added test does not fail without the change because the validation logic is in Cargo, not in rustc. But it's good to have some coverage of this anyways.
2 parents af99b0a + bdf8d3b commit f6e483d

File tree

4 files changed

+37
-0
lines changed

4 files changed

+37
-0
lines changed

compiler/rustc_target/src/spec/targets/wasm32_unknown_emscripten.rs

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,8 +19,15 @@ pub(crate) fn target() -> Target {
1919
pre_link_args,
2020
post_link_args,
2121
relocation_model: RelocModel::Pic,
22+
// crt_static should always be true for an executable and always false
23+
// for a shared library. There is no easy way to indicate this and it
24+
// doesn't seem to matter much so we set crt_static_allows_dylibs to
25+
// true and leave crt_static as true when linking dynamic libraries.
26+
// wasi also sets crt_static_allows_dylibs: true so this is at least
27+
// aligned between wasm targets.
2228
crt_static_respected: true,
2329
crt_static_default: true,
30+
crt_static_allows_dylibs: true,
2431
panic_strategy: PanicStrategy::Unwind,
2532
no_default_libraries: false,
2633
families: cvs!["unix", "wasm"],

src/tools/compiletest/src/directives/directive_names.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -249,6 +249,7 @@ pub(crate) const KNOWN_DIRECTIVE_NAMES: &[&str] = &[
249249
"only-unix",
250250
"only-visionos",
251251
"only-wasm32",
252+
"only-wasm32-unknown-emscripten",
252253
"only-wasm32-unknown-unknown",
253254
"only-wasm32-wasip1",
254255
"only-watchos",
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
#[no_mangle]
2+
pub extern "C" fn foo() -> i32 {
3+
42
4+
}
Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
//! Check that cdylib crate type is supported for the wasm32-unknown-emscripten
2+
//! target and produces a valid Emscripten dynamic library.
3+
4+
//@ only-wasm32-unknown-emscripten
5+
6+
use run_make_support::{bare_rustc, rfs, wasmparser};
7+
8+
fn main() {
9+
bare_rustc().input("foo.rs").target("wasm32-unknown-emscripten").crate_type("cdylib").run();
10+
11+
// Verify the output is a valid wasm file with a dylink.0 section
12+
let file = rfs::read("foo.wasm");
13+
let mut has_dylink = false;
14+
15+
for payload in wasmparser::Parser::new(0).parse_all(&file) {
16+
let payload = payload.unwrap();
17+
if let wasmparser::Payload::CustomSection(s) = payload {
18+
if s.name() == "dylink.0" {
19+
has_dylink = true;
20+
}
21+
}
22+
}
23+
24+
assert!(has_dylink, "expected dylink.0 section in emscripten cdylib output");
25+
}

0 commit comments

Comments
 (0)