Skip to content

Commit df4ea9c

Browse files
committed
rustc: Stop putting hashes in filenames by default
The compiler will no longer insert a hash or version into a filename by default. Instead, all output is simply based off the crate name being compiled. For example, a crate name of `foo` would produce the following outputs: * bin => foo * rlib => libfoo.rlib * dylib => libfoo.{so,dylib} or foo.dll * staticlib => libfoo.a The old behavior has been moved behind a new codegen flag, `-C extra-filename=<hash>`. For example, with the "extra filename" of `bar` and a crate name of `foo`, the following outputs would be generated: * bin => foo (same old behavior) * rlib => libfoobar.rlib * dylib => libfoobar.{so,dylib} or foobar.dll * staticlib => libfoobar.a The makefiles have been altered to pass a hash by default to invocations of `rustc` so all installed rust libraries will have a hash in their filename. This is done because the standard libraries are intended to be installed into privileged directories such as /usr/local. Additionally, it involves very few build system changes! RFC: 0035-remove-crate-id [breaking-change]
1 parent e44c2b9 commit df4ea9c

File tree

5 files changed

+19
-20
lines changed

5 files changed

+19
-20
lines changed

mk/main.mk

+2
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,8 @@
1616
CFG_RELEASE_NUM=0.11.0
1717
CFG_RELEASE_LABEL=
1818

19+
CFG_FILENAME_EXTRA=4e7c5e5c
20+
1921
ifndef CFG_ENABLE_NIGHTLY
2022
# This is the normal version string
2123
CFG_RELEASE=$(CFG_RELEASE_NUM)$(CFG_RELEASE_LABEL)

mk/target.mk

+10-1
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,13 @@ $(foreach host,$(CFG_HOST), \
4444
$(foreach crate,$(CRATES), \
4545
$(eval $(call RUST_CRATE_FULLDEPS,$(stage),$(target),$(host),$(crate)))))))
4646

47+
# NOTE: after a stage0 snap this should be just EXTRA_FILENAME, not with a stage
48+
# bound
49+
EXTRA_FILENAME_0 =
50+
EXTRA_FILENAME_1 = -C extra-filename=-$(CFG_FILENAME_EXTRA)
51+
EXTRA_FILENAME_2 = -C extra-filename=-$(CFG_FILENAME_EXTRA)
52+
EXTRA_FILENAME_3 = -C extra-filename=-$(CFG_FILENAME_EXTRA)
53+
4754
# RUST_TARGET_STAGE_N template: This defines how target artifacts are built
4855
# for all stage/target architecture combinations. This is one giant rule which
4956
# works as follows:
@@ -85,7 +92,9 @@ $$(TLIB$(1)_T_$(2)_H_$(3))/stamp.$(4): \
8592
-L "$$(LLVM_LIBDIR_$(2))" \
8693
-L "$$(dir $$(LLVM_STDCPP_LOCATION_$(2)))" \
8794
$$(RUSTFLAGS_$(4)) \
88-
--out-dir $$(@D) $$<
95+
--out-dir $$(@D) \
96+
$$(EXTRA_FILENAME_$(1)) \
97+
$$<
8998
@touch $$@
9099
$$(call LIST_ALL_OLD_GLOB_MATCHES,\
91100
$$(dir $$@)$$(call CFG_LIB_GLOB_$(2),$(4)))

src/librustc/back/link.rs

+1-13
Original file line numberDiff line numberDiff line change
@@ -588,18 +588,6 @@ pub fn find_crate_name(sess: Option<&Session>,
588588
}), None)
589589
}
590590

591-
pub fn crate_name_hash(sess: &Session, crate_name: &str) -> String {
592-
// This calculates CMH as defined above. Note that we don't use the path of
593-
// the crate id in the hash because lookups are only done by (name/vers),
594-
// not by path.
595-
let mut s = Sha256::new();
596-
s.input_str(crate_name);
597-
for meta in sess.crate_metadata.borrow().iter() {
598-
s.input_str(meta.as_slice());
599-
}
600-
truncated_hash_result(&mut s).as_slice().slice_to(8).to_string()
601-
}
602-
603591
pub fn build_link_meta(krate: &ast::Crate, name: String) -> LinkMeta {
604592
let r = LinkMeta {
605593
crate_name: name,
@@ -880,7 +868,7 @@ pub fn filename_for_input(sess: &Session,
880868
crate_type: config::CrateType,
881869
name: &str,
882870
out_filename: &Path) -> Path {
883-
let libname = format!("{}-{}", name, crate_name_hash(sess, name));
871+
let libname = format!("{}{}", name, sess.opts.cg.extra_filename);
884872
match crate_type {
885873
config::CrateTypeRlib => {
886874
out_filename.with_filename(format!("lib{}.rlib", libname))

src/librustc/driver/config.rs

+2
Original file line numberDiff line numberDiff line change
@@ -320,6 +320,8 @@ cgoptions!(
320320
"choose the relocation model to use (llc -relocation-model for details)"),
321321
metadata: Vec<String> = (Vec::new(), parse_list,
322322
"metadata to mangle symbol names with"),
323+
extra_filename: String = ("".to_string(), parse_string,
324+
"extra data to put in each output filename"),
323325
)
324326

325327
pub fn build_codegen_options(matches: &getopts::Matches) -> CodegenOptions

src/librustc/driver/driver.rs

+4-6
Original file line numberDiff line numberDiff line change
@@ -903,13 +903,11 @@ pub fn build_output_filenames(input: &Input,
903903
None => Path::new(".")
904904
};
905905

906-
let mut stem = input.filestem();
907-
908906
// If a crate name is present, we use it as the link name
909-
match attr::find_crate_name(attrs) {
910-
None => {}
911-
Some(name) => stem = name.get().to_string(),
912-
}
907+
let stem = match attr::find_crate_name(attrs) {
908+
None => input.filestem(),
909+
Some(name) => name.get().to_string(),
910+
};
913911
OutputFilenames {
914912
out_directory: dirpath,
915913
out_filestem: stem,

0 commit comments

Comments
 (0)