Skip to content

Commit 9702309

Browse files
committed
code cleanup
1 parent 604e4b0 commit 9702309

File tree

2 files changed

+53
-49
lines changed

2 files changed

+53
-49
lines changed

compiler/rustc_codegen_ssa/src/back/link.rs

Lines changed: 45 additions & 41 deletions
Original file line numberDiff line numberDiff line change
@@ -335,8 +335,8 @@ fn link_rlib<'a, B: ArchiveBuilder<'a>>(
335335
}
336336

337337
let Some(name) = lib.name else {
338-
continue;
339-
};
338+
continue;
339+
};
340340

341341
let location = find_library(
342342
name.as_str(),
@@ -345,23 +345,28 @@ fn link_rlib<'a, B: ArchiveBuilder<'a>>(
345345
sess,
346346
);
347347

348-
if (flavor == RlibFlavor::Normal) && sess.opts.unstable_opts.split_bundled_libs {
348+
if flavor == RlibFlavor::Normal && sess.opts.unstable_opts.split_bundled_libs {
349349
let suffix = &sess.target.staticlib_suffix;
350-
let crate_name = out_filename.to_str().unwrap();
351-
let bundle_lib = PathBuf::from(&format!("{crate_name}.bundle.{name}{suffix}"));
352-
fs::copy(location, bundle_lib).unwrap();
353-
continue;
350+
let bundle_lib = PathBuf::from(format!("{}.bundle.{name}{suffix}", out_filename.display()));
351+
match fs::copy(location, bundle_lib) {
352+
Ok(_) => {},
353+
Err(_) => sess.fatal("unable to create file for bundle lib"),
354+
}
355+
} else {
356+
ab.add_archive(&location, |_| false).unwrap_or_else(|e| {
357+
sess.fatal(&format!(
358+
"failed to add native library {}: {}",
359+
location.to_string_lossy(),
360+
e
361+
));
362+
});
354363
}
355-
356-
ab.add_archive(&location, |_| false).unwrap_or_else(|e| {
357-
sess.fatal(&format!(
358-
"failed to add native library {}: {}",
359-
location.to_string_lossy(),
360-
e
361-
));
362-
});
363364
}
364-
_ => {}
365+
NativeLibKind::Static { bundle: Some(false), .. }
366+
| NativeLibKind::Dylib { .. }
367+
| NativeLibKind::Framework { .. }
368+
| NativeLibKind::RawDylib
369+
| NativeLibKind::Unspecified => continue,
365370
}
366371
}
367372

@@ -2376,40 +2381,39 @@ fn add_upstream_rust_crates<'a, B: ArchiveBuilder<'a>>(
23762381
(lib.name, lib.kind, lib.verbatim)
23772382
};
23782383

2379-
if sess.opts.unstable_opts.split_bundled_libs {
2380-
if let NativeLibKind::Static {
2381-
bundle: Some(true) | None,
2382-
whole_archive,
2383-
} = lib.kind
2384+
match lib.kind {
2385+
NativeLibKind::Static { bundle: None | Some(true), whole_archive }
2386+
if sess.opts.unstable_opts.split_bundled_libs =>
23842387
{
23852388
let suffix = &sess.target.staticlib_suffix;
2386-
let crate_path = src.paths().next().unwrap().to_str().unwrap();
2389+
let cratepath = &src.rlib.as_ref().unwrap().0;
23872390
let bundle_lib =
2388-
PathBuf::from(&format!("{crate_path}.bundle.{name}{suffix}"));
2391+
PathBuf::from(format!("{}.bundle.{name}{suffix}", cratepath.display()));
23892392
if whole_archive == Some(true) {
2390-
cmd.link_whole_rlib(&bundle_lib);
2393+
cmd.link_whole_rlib(&fix_windows_verbatim_for_gcc(&bundle_lib));
23912394
} else {
2392-
cmd.link_rlib(&bundle_lib);
2395+
cmd.link_rlib(&fix_windows_verbatim_for_gcc(&bundle_lib));
23932396
}
2394-
2395-
continue;
23962397
}
2397-
}
23982398

2399-
if let NativeLibKind::Static { bundle: Some(false), whole_archive } =
2400-
lib.kind
2401-
{
2402-
let verbatim = lib.verbatim.unwrap_or(false);
2403-
if whole_archive == Some(true) {
2404-
cmd.link_whole_staticlib(
2405-
name,
2406-
verbatim,
2407-
search_path.get_or_init(|| archive_search_paths(sess)),
2408-
);
2409-
} else {
2410-
cmd.link_staticlib(name, verbatim);
2399+
NativeLibKind::Static { bundle: Some(false), whole_archive } => {
2400+
let verbatim = lib.verbatim.unwrap_or(false);
2401+
if whole_archive == Some(true) {
2402+
cmd.link_whole_staticlib(
2403+
name,
2404+
verbatim,
2405+
search_path.get_or_init(|| archive_search_paths(sess)),
2406+
);
2407+
} else {
2408+
cmd.link_staticlib(name, verbatim);
2409+
}
24112410
}
2412-
}
2411+
NativeLibKind::Static { bundle: None | Some(true), .. }
2412+
| NativeLibKind::Dylib { .. }
2413+
| NativeLibKind::Framework { .. }
2414+
| NativeLibKind::RawDylib
2415+
| NativeLibKind::Unspecified => {}
2416+
};
24132417
}
24142418
}
24152419
}

compiler/rustc_session/src/options.rs

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1496,14 +1496,6 @@ options! {
14961496
/// o/w tests have closure@path
14971497
span_free_formats: bool = (false, parse_bool, [UNTRACKED],
14981498
"exclude spans when debug-printing compiler state (default: no)"),
1499-
src_hash_algorithm: Option<SourceFileHashAlgorithm> = (None, parse_src_file_hash, [TRACKED],
1500-
"hash algorithm of source files in debug info (`md5`, `sha1`, or `sha256`)"),
1501-
stack_protector: StackProtector = (StackProtector::None, parse_stack_protector, [TRACKED],
1502-
"control stack smash protection strategy (`rustc --print stack-protector-strategies` for details)"),
1503-
strict_init_checks: bool = (false, parse_bool, [TRACKED],
1504-
"control if mem::uninitialized and mem::zeroed panic on more UB"),
1505-
strip: Strip = (Strip::None, parse_strip, [UNTRACKED],
1506-
"tell the linker which information to strip (`none` (default), `debuginfo` or `symbols`)"),
15071499
split_bundled_libs: bool = (false, parse_bool, [TRACKED],
15081500
"if libfoo.rlib is the rlib, then libfoo.rlib.bundle.* are the corresponding bundled static libraries"),
15091501
split_dwarf_kind: SplitDwarfKind = (SplitDwarfKind::Split, parse_split_dwarf_kind, [TRACKED],
@@ -1517,6 +1509,14 @@ options! {
15171509
split_dwarf_inlining: bool = (true, parse_bool, [TRACKED],
15181510
"provide minimal debug info in the object/executable to facilitate online \
15191511
symbolication/stack traces in the absence of .dwo/.dwp files when using Split DWARF"),
1512+
src_hash_algorithm: Option<SourceFileHashAlgorithm> = (None, parse_src_file_hash, [TRACKED],
1513+
"hash algorithm of source files in debug info (`md5`, `sha1`, or `sha256`)"),
1514+
stack_protector: StackProtector = (StackProtector::None, parse_stack_protector, [TRACKED],
1515+
"control stack smash protection strategy (`rustc --print stack-protector-strategies` for details)"),
1516+
strict_init_checks: bool = (false, parse_bool, [TRACKED],
1517+
"control if mem::uninitialized and mem::zeroed panic on more UB"),
1518+
strip: Strip = (Strip::None, parse_strip, [UNTRACKED],
1519+
"tell the linker which information to strip (`none` (default), `debuginfo` or `symbols`)"),
15201520
symbol_mangling_version: Option<SymbolManglingVersion> = (None,
15211521
parse_symbol_mangling_version, [TRACKED],
15221522
"which mangling version to use for symbol names ('legacy' (default) or 'v0')"),

0 commit comments

Comments
 (0)