Skip to content

Commit 02b9afe

Browse files
committed
Handle target names with dots like thumbv8m.base-none-eabi
1 parent 18e2f2c commit 02b9afe

File tree

1 file changed

+13
-4
lines changed

1 file changed

+13
-4
lines changed

src/lib.rs

Lines changed: 13 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -166,12 +166,21 @@ impl SysrootBuilder {
166166
self
167167
}
168168

169+
170+
/// Our configured target can be either a built-in target name, or a path to a target file.
171+
/// We use the same logic as rustc to tell which is which:
172+
/// https://github.com/rust-lang/rust/blob/8d39ec1825024f3014e1f847942ac5bbfcf055b0/compiler/rustc_session/src/config.rs#L2252-L2263
169173
fn target_name(&self) -> &OsStr {
170174
let path = Path::new(&self.target);
171-
// If this is a filename, the name is obtained by stripping directory and extension.
172-
// That will also work fine for built-in target names.
173-
path.file_stem()
174-
.expect("target name must contain a file name")
175+
if path.extension().and_then(OsStr::to_str) == Some("json") {
176+
// Path::file_stem and Path::extension are the last component of the path split on the
177+
// rightmost '.' so if we have an extension we must have a file_name.
178+
path.file_stem().unwrap()
179+
} else {
180+
// The configured target doesn't end in ".json", so we assume that this is a builtin
181+
// target.
182+
&self.target
183+
}
175184
}
176185

177186
fn target_dir(&self) -> PathBuf {

0 commit comments

Comments
 (0)