Skip to content

Commit 81cfa98

Browse files
committed
config.toml error reporting:
Improve error messages for musl-libdir and wasi-root keys. Previously the parser would panic with `unwrap()`. Now it prints Target "wasm32-wasi" does not have a "wasi-root" key (and similar for the `musl-libdir` field, which is used in target that use musl) Also update comments around wasi-root field to make it clear that the field is only valid in wasm32-wasi target and needs to be moved to a `[target.wasm32-wasi]` section to be valid. Fixes #82317
1 parent 3b150b7 commit 81cfa98

File tree

2 files changed

+12
-3
lines changed

2 files changed

+12
-3
lines changed

config.toml.example

+3-1
Original file line numberDiff line numberDiff line change
@@ -631,7 +631,9 @@ changelog-seen = 2
631631
# The full path to the musl libdir.
632632
#musl-libdir = musl-root/lib
633633

634-
# The root location of the `wasm32-wasi` sysroot.
634+
# The root location of the `wasm32-wasi` sysroot. Only used for the
635+
# `wasm32-wasi` target. If you are building wasm32-wasi target, make sure to
636+
# create a `[target.wasm32-wasi]` section and move this field there.
635637
#wasi-root = "..."
636638

637639
# Used in testing for configuring where the QEMU images are located, you

src/bootstrap/compile.rs

+9-2
Original file line numberDiff line numberDiff line change
@@ -178,7 +178,9 @@ fn copy_self_contained_objects(
178178
// To do that we have to distribute musl startup objects as a part of Rust toolchain
179179
// and link with them manually in the self-contained mode.
180180
if target.contains("musl") {
181-
let srcdir = builder.musl_libdir(target).unwrap();
181+
let srcdir = builder.musl_libdir(target).unwrap_or_else(|| {
182+
panic!("Target {:?} does not have a \"musl-libdir\" key", target.triple)
183+
});
182184
for &obj in &["crt1.o", "Scrt1.o", "rcrt1.o", "crti.o", "crtn.o"] {
183185
copy_and_stamp(
184186
builder,
@@ -196,7 +198,12 @@ fn copy_self_contained_objects(
196198
target_deps.push((target, DependencyType::TargetSelfContained));
197199
}
198200
} else if target.ends_with("-wasi") {
199-
let srcdir = builder.wasi_root(target).unwrap().join("lib/wasm32-wasi");
201+
let srcdir = builder
202+
.wasi_root(target)
203+
.unwrap_or_else(|| {
204+
panic!("Target {:?} does not have a \"wasi-root\" key", target.triple)
205+
})
206+
.join("lib/wasm32-wasi");
200207
for &obj in &["crt1.o", "crt1-reactor.o"] {
201208
copy_and_stamp(
202209
builder,

0 commit comments

Comments
 (0)