113 lines
5.4 KiB
Diff
113 lines
5.4 KiB
Diff
From 3730abcf2b86d650da97a11190af8dcbfeae311a Mon Sep 17 00:00:00 2001
|
|
From: Josh Stone <jistone@redhat.com>
|
|
Date: Mon, 18 Aug 2025 17:13:28 -0700
|
|
Subject: [PATCH 2/2] set an external library path for wasm32-wasi
|
|
|
|
---
|
|
compiler/rustc_codegen_ssa/src/back/link.rs | 10 ++++++++++
|
|
compiler/rustc_target/src/spec/json.rs | 4 ++++
|
|
compiler/rustc_target/src/spec/mod.rs | 2 ++
|
|
.../rustc_target/src/spec/targets/wasm32_wasip1.rs | 7 ++++---
|
|
4 files changed, 20 insertions(+), 3 deletions(-)
|
|
|
|
diff --git a/compiler/rustc_codegen_ssa/src/back/link.rs b/compiler/rustc_codegen_ssa/src/back/link.rs
|
|
index 162fbf3d6e24..2acfd6dd96b2 100644
|
|
--- a/compiler/rustc_codegen_ssa/src/back/link.rs
|
|
+++ b/compiler/rustc_codegen_ssa/src/back/link.rs
|
|
@@ -1548,6 +1548,12 @@ fn get_object_file_path(sess: &Session, name: &str, self_contained: bool) -> Pat
|
|
return file_path;
|
|
}
|
|
}
|
|
+ if let Some(lib_path) = &sess.target.options.external_lib_path {
|
|
+ let file_path = Path::new(lib_path.as_ref()).join(name);
|
|
+ if file_path.exists() {
|
|
+ return file_path;
|
|
+ }
|
|
+ }
|
|
for search_path in sess.target_filesearch().search_paths(PathKind::Native) {
|
|
let file_path = search_path.dir.join(name);
|
|
if file_path.exists() {
|
|
@@ -2121,6 +2127,10 @@ fn add_library_search_dirs(
|
|
}
|
|
ControlFlow::<()>::Continue(())
|
|
});
|
|
+
|
|
+ if let Some(lib_path) = &sess.target.options.external_lib_path {
|
|
+ cmd.include_path(Path::new(lib_path.as_ref()));
|
|
+ }
|
|
}
|
|
|
|
/// Add options making relocation sections in the produced ELF files read-only
|
|
diff --git a/compiler/rustc_target/src/spec/json.rs b/compiler/rustc_target/src/spec/json.rs
|
|
index d27c1929aef7..b995896450e0 100644
|
|
--- a/compiler/rustc_target/src/spec/json.rs
|
|
+++ b/compiler/rustc_target/src/spec/json.rs
|
|
@@ -84,6 +84,7 @@ macro_rules! forward_opt {
|
|
forward!(linker_is_gnu_json);
|
|
forward!(pre_link_objects);
|
|
forward!(post_link_objects);
|
|
+ forward_opt!(external_lib_path);
|
|
forward!(pre_link_objects_self_contained);
|
|
forward!(post_link_objects_self_contained);
|
|
|
|
@@ -306,6 +307,7 @@ macro_rules! target_option_val {
|
|
target_option_val!(linker_is_gnu_json, "linker-is-gnu");
|
|
target_option_val!(pre_link_objects);
|
|
target_option_val!(post_link_objects);
|
|
+ target_option_val!(external_lib_path);
|
|
target_option_val!(pre_link_objects_self_contained, "pre-link-objects-fallback");
|
|
target_option_val!(post_link_objects_self_contained, "post-link-objects-fallback");
|
|
target_option_val!(link_args - pre_link_args_json, "pre-link-args");
|
|
@@ -490,6 +492,8 @@ struct TargetSpecJson {
|
|
pre_link_objects: Option<CrtObjects>,
|
|
#[serde(rename = "post-link-objects")]
|
|
post_link_objects: Option<CrtObjects>,
|
|
+ #[serde(rename = "external-lib-path")]
|
|
+ external_lib_path: Option<StaticCow<str>>,
|
|
#[serde(rename = "pre-link-objects-fallback")]
|
|
pre_link_objects_self_contained: Option<CrtObjects>,
|
|
#[serde(rename = "post-link-objects-fallback")]
|
|
diff --git a/compiler/rustc_target/src/spec/mod.rs b/compiler/rustc_target/src/spec/mod.rs
|
|
index 033590e01a67..15a012639472 100644
|
|
--- a/compiler/rustc_target/src/spec/mod.rs
|
|
+++ b/compiler/rustc_target/src/spec/mod.rs
|
|
@@ -2439,6 +2439,7 @@ pub struct TargetOptions {
|
|
/// Objects to link before and after all other object code.
|
|
pub pre_link_objects: CrtObjects,
|
|
pub post_link_objects: CrtObjects,
|
|
+ pub external_lib_path: Option<StaticCow<str>>,
|
|
/// Same as `(pre|post)_link_objects`, but when self-contained linking mode is enabled.
|
|
pub pre_link_objects_self_contained: CrtObjects,
|
|
pub post_link_objects_self_contained: CrtObjects,
|
|
@@ -2964,6 +2965,7 @@ fn default() -> TargetOptions {
|
|
relro_level: RelroLevel::None,
|
|
pre_link_objects: Default::default(),
|
|
post_link_objects: Default::default(),
|
|
+ external_lib_path: None,
|
|
pre_link_objects_self_contained: Default::default(),
|
|
post_link_objects_self_contained: Default::default(),
|
|
link_self_contained: LinkSelfContainedDefault::False,
|
|
diff --git a/compiler/rustc_target/src/spec/targets/wasm32_wasip1.rs b/compiler/rustc_target/src/spec/targets/wasm32_wasip1.rs
|
|
index 26add451ed25..3eaf050e6823 100644
|
|
--- a/compiler/rustc_target/src/spec/targets/wasm32_wasip1.rs
|
|
+++ b/compiler/rustc_target/src/spec/targets/wasm32_wasip1.rs
|
|
@@ -21,11 +21,12 @@ pub(crate) fn target() -> Target {
|
|
options.env = "p1".into();
|
|
options.add_pre_link_args(LinkerFlavor::WasmLld(Cc::Yes), &["--target=wasm32-wasip1"]);
|
|
|
|
- options.pre_link_objects_self_contained = crt_objects::pre_wasi_self_contained();
|
|
- options.post_link_objects_self_contained = crt_objects::post_wasi_self_contained();
|
|
+ options.pre_link_objects = crt_objects::pre_wasi_self_contained();
|
|
+ options.post_link_objects = crt_objects::post_wasi_self_contained();
|
|
|
|
// FIXME: Figure out cases in which WASM needs to link with a native toolchain.
|
|
- options.link_self_contained = LinkSelfContainedDefault::True;
|
|
+ options.link_self_contained = LinkSelfContainedDefault::False;
|
|
+ options.external_lib_path = Some("/usr/wasm32-wasi/lib/wasm32-wasi".into());
|
|
|
|
// Right now this is a bit of a workaround but we're currently saying that
|
|
// the target by default has a static crt which we're taking as a signal
|
|
--
|
|
2.50.1
|
|
|