From df4ea9c39a355e4cff425cca7d58e7758cb3461c Mon Sep 17 00:00:00 2001 From: Alex Crichton Date: Tue, 1 Jul 2014 07:57:07 -0700 Subject: [PATCH] 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=`. 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] --- mk/main.mk | 2 ++ mk/target.mk | 11 ++++++++++- src/librustc/back/link.rs | 14 +------------- src/librustc/driver/config.rs | 2 ++ src/librustc/driver/driver.rs | 10 ++++------ 5 files changed, 19 insertions(+), 20 deletions(-) diff --git a/mk/main.mk b/mk/main.mk index c4be89033a6..c01410a591b 100644 --- a/mk/main.mk +++ b/mk/main.mk @@ -16,6 +16,8 @@ CFG_RELEASE_NUM=0.11.0 CFG_RELEASE_LABEL= +CFG_FILENAME_EXTRA=4e7c5e5c + ifndef CFG_ENABLE_NIGHTLY # This is the normal version string CFG_RELEASE=$(CFG_RELEASE_NUM)$(CFG_RELEASE_LABEL) diff --git a/mk/target.mk b/mk/target.mk index 0f63ef9a430..b7a570e3275 100644 --- a/mk/target.mk +++ b/mk/target.mk @@ -44,6 +44,13 @@ $(foreach host,$(CFG_HOST), \ $(foreach crate,$(CRATES), \ $(eval $(call RUST_CRATE_FULLDEPS,$(stage),$(target),$(host),$(crate))))))) +# NOTE: after a stage0 snap this should be just EXTRA_FILENAME, not with a stage +# bound +EXTRA_FILENAME_0 = +EXTRA_FILENAME_1 = -C extra-filename=-$(CFG_FILENAME_EXTRA) +EXTRA_FILENAME_2 = -C extra-filename=-$(CFG_FILENAME_EXTRA) +EXTRA_FILENAME_3 = -C extra-filename=-$(CFG_FILENAME_EXTRA) + # RUST_TARGET_STAGE_N template: This defines how target artifacts are built # for all stage/target architecture combinations. This is one giant rule which # works as follows: @@ -85,7 +92,9 @@ $$(TLIB$(1)_T_$(2)_H_$(3))/stamp.$(4): \ -L "$$(LLVM_LIBDIR_$(2))" \ -L "$$(dir $$(LLVM_STDCPP_LOCATION_$(2)))" \ $$(RUSTFLAGS_$(4)) \ - --out-dir $$(@D) $$< + --out-dir $$(@D) \ + $$(EXTRA_FILENAME_$(1)) \ + $$< @touch $$@ $$(call LIST_ALL_OLD_GLOB_MATCHES,\ $$(dir $$@)$$(call CFG_LIB_GLOB_$(2),$(4))) diff --git a/src/librustc/back/link.rs b/src/librustc/back/link.rs index 1145d0595ab..1ad8b0b3698 100644 --- a/src/librustc/back/link.rs +++ b/src/librustc/back/link.rs @@ -588,18 +588,6 @@ pub fn find_crate_name(sess: Option<&Session>, }), None) } -pub fn crate_name_hash(sess: &Session, crate_name: &str) -> String { - // This calculates CMH as defined above. Note that we don't use the path of - // the crate id in the hash because lookups are only done by (name/vers), - // not by path. - let mut s = Sha256::new(); - s.input_str(crate_name); - for meta in sess.crate_metadata.borrow().iter() { - s.input_str(meta.as_slice()); - } - truncated_hash_result(&mut s).as_slice().slice_to(8).to_string() -} - pub fn build_link_meta(krate: &ast::Crate, name: String) -> LinkMeta { let r = LinkMeta { crate_name: name, @@ -880,7 +868,7 @@ pub fn filename_for_input(sess: &Session, crate_type: config::CrateType, name: &str, out_filename: &Path) -> Path { - let libname = format!("{}-{}", name, crate_name_hash(sess, name)); + let libname = format!("{}{}", name, sess.opts.cg.extra_filename); match crate_type { config::CrateTypeRlib => { out_filename.with_filename(format!("lib{}.rlib", libname)) diff --git a/src/librustc/driver/config.rs b/src/librustc/driver/config.rs index b35d1be98f3..c7f8b4a62ee 100644 --- a/src/librustc/driver/config.rs +++ b/src/librustc/driver/config.rs @@ -320,6 +320,8 @@ cgoptions!( "choose the relocation model to use (llc -relocation-model for details)"), metadata: Vec = (Vec::new(), parse_list, "metadata to mangle symbol names with"), + extra_filename: String = ("".to_string(), parse_string, + "extra data to put in each output filename"), ) pub fn build_codegen_options(matches: &getopts::Matches) -> CodegenOptions diff --git a/src/librustc/driver/driver.rs b/src/librustc/driver/driver.rs index 1512c359bb8..12efecb4a0b 100644 --- a/src/librustc/driver/driver.rs +++ b/src/librustc/driver/driver.rs @@ -903,13 +903,11 @@ pub fn build_output_filenames(input: &Input, None => Path::new(".") }; - let mut stem = input.filestem(); - // If a crate name is present, we use it as the link name - match attr::find_crate_name(attrs) { - None => {} - Some(name) => stem = name.get().to_string(), - } + let stem = match attr::find_crate_name(attrs) { + None => input.filestem(), + Some(name) => name.get().to_string(), + }; OutputFilenames { out_directory: dirpath, out_filestem: stem,