From 6dbd4c21e9cc0fd3bb337ad2d9f10e206cf3e575 Mon Sep 17 00:00:00 2001 From: Haitao Li Date: Sat, 3 Dec 2011 00:51:59 +0800 Subject: [PATCH] rustc: build versioned library with hash in its name Also updated build to install versioned libraries and added a few missing actions for `make clean`. --- Makefile.in | 4 ++++ mk/clean.mk | 10 ++++++++++ mk/host.mk | 6 ++++++ mk/install.mk | 15 ++++++++++----- mk/platform.mk | 4 ++++ mk/target.mk | 6 +++--- src/comp/back/link.rs | 19 +++++++++++++------ src/comp/driver/rustc.rs | 6 +++--- src/comp/metadata/creader.rs | 2 +- src/comp/middle/trans.rs | 4 ++-- 10 files changed, 56 insertions(+), 20 deletions(-) diff --git a/Makefile.in b/Makefile.in index 51bc708c36c..5d98b87e016 100644 --- a/Makefile.in +++ b/Makefile.in @@ -108,6 +108,10 @@ CFG_CORELIB :=$(call CFG_LIB_NAME,core) CFG_STDLIB :=$(call CFG_LIB_NAME,std) CFG_LIBRUSTC :=$(call CFG_LIB_NAME,rustc) +STDLIB_GLOB :=$(call CFG_LIB_GLOB,std) +CORELIB_GLOB :=$(call CFG_LIB_GLOB,core) +LIBRUSTC_GLOB :=$(call CFG_LIB_GLOB,rustc) + # version-string calculation CFG_GIT_DIR := $(CFG_SRC_DIR).git CFG_VERSION = prerelease diff --git a/mk/clean.mk b/mk/clean.mk index 071b4ae0350..e28bfc92c5e 100644 --- a/mk/clean.mk +++ b/mk/clean.mk @@ -56,7 +56,12 @@ clean$(1)_H_$(2): $(Q)rm -f $$(HBIN$(1)_H_$(2))/fuzzer$(X) $(Q)rm -f $$(HBIN$(1)_H_$(2))/cargo$(X) $(Q)rm -f $$(HLIB$(1)_H_$(2))/$(CFG_RUNTIME) + $(Q)rm -f $$(HLIB$(1)_H_$(2))/$(CFG_CORELIB) $(Q)rm -f $$(HLIB$(1)_H_$(2))/$(CFG_STDLIB) + $(Q)rm -f $$(HLIB$(1)_H_$(2))/$(CFG_LIBRUSTC) + $(Q)rm -f $$(HLIB$(1)_H_$(2))/$(CORELIB_GLOB) + $(Q)rm -f $$(HLIB$(1)_H_$(2))/$(STDLIB_GLOB) + $(Q)rm -f $$(HLIB$(1)_H_$(2))/$(LIBRUSTC_GLOB) $(Q)rm -f $$(HLIB$(1)_H_$(2))/$(CFG_RUSTLLVM) $(Q)rm -f $$(HLIB$(1)_H_$(2))/libstd.rlib @@ -72,7 +77,12 @@ clean$(1)_T_$(2)_H_$(3): $(Q)rm -f $$(TBIN$(1)_T_$(2)_H_$(3))/rustc$(X) $(Q)rm -f $$(TBIN$(1)_T_$(2)_H_$(3))/fuzzer$(X) $(Q)rm -f $$(TLIB$(1)_T_$(2)_H_$(3))/$(CFG_RUNTIME) + $(Q)rm -f $$(TLIB$(1)_T_$(2)_H_$(3))/$(CFG_CORELIB) $(Q)rm -f $$(TLIB$(1)_T_$(2)_H_$(3))/$(CFG_STDLIB) + $(Q)rm -f $$(TLIB$(1)_T_$(2)_H_$(3))/$(CFG_LIBRUSTC) + $(Q)rm -f $$(TLIB$(1)_T_$(2)_H_$(3))/$(CORELIB_GLOB) + $(Q)rm -f $$(TLIB$(1)_T_$(2)_H_$(3))/$(STDLIB_GLOB) + $(Q)rm -f $$(TLIB$(1)_T_$(2)_H_$(3))/$(LIBRUSTC_GLOB) $(Q)rm -f $$(TLIB$(1)_T_$(2)_H_$(3))/$(CFG_RUSTLLVM) $(Q)rm -f $$(TLIB$(1)_T_$(2)_H_$(3))/libstd.rlib $(Q)rm -f $$(TLIB$(1)_T_$(2)_H_$(3))/intrinsics.bc diff --git a/mk/host.mk b/mk/host.mk index add7278dee2..475fa8085a6 100644 --- a/mk/host.mk +++ b/mk/host.mk @@ -30,6 +30,8 @@ $$(HLIB$(2)_H_$(4))/$$(CFG_LIBRUSTC): \ $$(HSTDLIB_DEFAULT$(2)_H_$(3)) @$$(call E, cp: $$@) $$(Q)cp $$< $$@ + $$(Q)cp $$(TLIB$(1)_T_$(4)_H_$(3))/$(LIBRUSTC_GLOB) \ + $$(HLIB$(2)_H_$(4)) $$(HLIB$(2)_H_$(4))/$$(CFG_RUNTIME): \ $$(TLIB$(1)_T_$(4)_H_$(3))/$$(CFG_RUNTIME) @@ -41,6 +43,8 @@ $$(HLIB$(2)_H_$(4))/$$(CFG_CORELIB): \ $$(HLIB$(2)_H_$(4))/$$(CFG_RUNTIME) @$$(call E, cp: $$@) $$(Q)cp $$< $$@ + $$(Q)cp $$(TLIB$(1)_T_$(4)_H_$(3))/$(CORELIB_GLOB) \ + $$(HLIB$(2)_H_$(4)) $$(HLIB$(2)_H_$(4))/$$(CFG_STDLIB): \ $$(TLIB$(1)_T_$(4)_H_$(3))/$$(CFG_STDLIB) \ @@ -48,6 +52,8 @@ $$(HLIB$(2)_H_$(4))/$$(CFG_STDLIB): \ $$(HLIB$(2)_H_$(4))/$$(CFG_RUNTIME) @$$(call E, cp: $$@) $$(Q)cp $$< $$@ + $$(Q)cp $$(TLIB$(1)_T_$(4)_H_$(3))/$(STDLIB_GLOB) \ + $$(HLIB$(2)_H_$(4)) $$(HLIB$(2)_H_$(4))/libcore.rlib: \ $$(TLIB$(1)_T_$(4)_H_$(3))/libcore.rlib \ diff --git a/mk/install.mk b/mk/install.mk index c22a4a37010..e0e32769629 100644 --- a/mk/install.mk +++ b/mk/install.mk @@ -3,11 +3,14 @@ # mirror of the installation directory structure. # Installation macro. Call with source directory as arg 1, -# destination directory as arg 2, and filename as arg 3 +# destination directory as arg 2, and filename/libname-glob as arg 3 ifdef VERBOSE INSTALL = cp $(1)/$(3) $(2)/$(3) + INSTALL_LIB = cp `ls -rt1 $(1)/$(3) | tail -1` $(2)/ else INSTALL = $(Q)$(call E, install: $(2)/$(3)) && cp $(1)/$(3) $(2)/$(3) + INSTALL_LIB = $(Q)$(call E, install_lib: $(2)/$(3)) && \ + cp `ls -rt1 $(1)/$(3) | tail -1` $(2)/ endif # The stage we install from @@ -33,8 +36,10 @@ PTL$(1)$(2) = $$(PTR$(1)$(2))/lib install-target-$(1)-host-$(2): $$(SREQ$$(ISTAGE)_T_$(1)_H_$(2)) $$(Q)mkdir -p $$(PTL$(1)$(2)) $$(Q)$$(call INSTALL,$$(TL$(1)$(2)),$$(PTL$(1)$(2)),$$(CFG_RUNTIME)) - $$(Q)$$(call INSTALL,$$(TL$(1)$(2)),$$(PTL$(1)$(2)),$$(CFG_CORELIB)) - $$(Q)$$(call INSTALL,$$(TL$(1)$(2)),$$(PTL$(1)$(2)),$$(CFG_STDLIB)) + $$(Q)$$(call INSTALL_LIB, \ + $$(TL$(1)$(2)),$$(PTL$(1)$(2)),$$(CORELIB_GLOB)) + $$(Q)$$(call INSTALL_LIB, \ + $$(TL$(1)$(2)),$$(PTL$(1)$(2)),$$(STDLIB_GLOB)) $$(Q)$$(call INSTALL,$$(TL$(1)$(2)),$$(PTL$(1)$(2)),intrinsics.bc) $$(Q)$$(call INSTALL,$$(TL$(1)$(2)),$$(PTL$(1)$(2)),libmorestack.a) endef @@ -62,8 +67,8 @@ install-host: $(SREQ$(ISTAGE)_T_$(CFG_HOST_TRIPLE)_H_$(CFG_HOST_TRIPLE)) $(Q)mkdir -p $(PREFIX_ROOT)/share/man/man1 $(Q)$(call INSTALL,$(HB),$(PHB),rustc$(X)) $(Q)$(call INSTALL,$(HL),$(PHL),$(CFG_RUNTIME)) - $(Q)$(call INSTALL,$(HL),$(PHL),$(CFG_CORELIB)) - $(Q)$(call INSTALL,$(HL),$(PHL),$(CFG_STDLIB)) + $(Q)$(call INSTALL_LIB,$(HL),$(PHL),$(CORELIB_GLOB)) + $(Q)$(call INSTALL_LIB,$(HL),$(PHL),$(STDLIB_GLOB)) $(Q)$(call INSTALL,$(HL),$(PHL),$(CFG_RUSTLLVM)) $(Q)$(call INSTALL,$(S)/man, \ $(PREFIX_ROOT)/share/man/man1,rustc.1) diff --git a/mk/platform.mk b/mk/platform.mk index 4a70e545862..c4cce8c9438 100644 --- a/mk/platform.mk +++ b/mk/platform.mk @@ -23,6 +23,7 @@ endif ifneq ($(findstring freebsd,$(CFG_OSTYPE)),) CFG_LIB_NAME=lib$(1).so + CFG_LIB_GLOB=lib$(1)-*.so CFG_GCCISH_CFLAGS += -fPIC -march=i686 -I/usr/local/include CFG_GCCISH_LINK_FLAGS += -shared -fPIC -lpthread -lrt ifeq ($(CFG_CPUTYPE), x86_64) @@ -40,6 +41,7 @@ endif ifneq ($(findstring linux,$(CFG_OSTYPE)),) CFG_LIB_NAME=lib$(1).so + CFG_LIB_GLOB=lib$(1)-*.so CFG_GCCISH_CFLAGS += -fPIC CFG_GCCISH_LINK_FLAGS += -shared -fPIC -ldl -lpthread -lrt CFG_GCCISH_DEF_FLAG := -Wl,--export-dynamic,--dynamic-list= @@ -71,6 +73,7 @@ endif ifneq ($(findstring darwin,$(CFG_OSTYPE)),) CFG_LIB_NAME=lib$(1).dylib + CFG_LIB_GLOB=lib$(1)-*.dylib CFG_UNIXY := 1 CFG_LDENV := DYLD_LIBRARY_PATH CFG_GCCISH_LINK_FLAGS += -dynamiclib -lpthread -framework CoreServices @@ -156,6 +159,7 @@ ifdef CFG_WINDOWSY CFG_EXE_SUFFIX := .exe CFG_LIB_NAME=$(1).dll + CFG_LIB_GLOB=$(1)-*.dll CFG_DEF_SUFFIX := .def CFG_LDPATH :=$(CFG_LDPATH):$$PATH CFG_RUN=PATH="$(CFG_LDPATH):$(1)" $(2) diff --git a/mk/target.mk b/mk/target.mk index 6170aedb610..4df1d6dd392 100644 --- a/mk/target.mk +++ b/mk/target.mk @@ -26,14 +26,14 @@ $$(TLIB$(1)_T_$(2)_H_$(3))/$$(CFG_CORELIB): \ $$(CORELIB_CRATE) $$(CORELIB_INPUTS) \ $$(TSREQ$(1)_T_$(2)_H_$(3)) @$$(call E, compile_and_link: $$@) - $$(STAGE$(1)_T_$(2)_H_$(3)) --no-core --lib -o $$@ $$< + $$(STAGE$(1)_T_$(2)_H_$(3)) --no-core --lib -o $$@ $$< && touch $$@ $$(TLIB$(1)_T_$(2)_H_$(3))/$$(CFG_STDLIB): \ $$(STDLIB_CRATE) $$(STDLIB_INPUTS) \ $$(TLIB$(1)_T_$(2)_H_$(3))/$$(CFG_CORELIB) \ $$(TSREQ$(1)_T_$(2)_H_$(3)) @$$(call E, compile_and_link: $$@) - $$(STAGE$(1)_T_$(2)_H_$(3)) --lib -o $$@ $$< + $$(STAGE$(1)_T_$(2)_H_$(3)) --lib -o $$@ $$< && touch $$@ $$(TLIB$(1)_T_$(2)_H_$(3))/$$(CFG_RUNTIME): \ rt/$(2)/$$(CFG_RUNTIME) @@ -59,7 +59,7 @@ $$(TLIB$(1)_T_$(2)_H_$(3))/$$(CFG_LIBRUSTC): \ $$(TLIB$(1)_T_$(2)_H_$(3))/$$(CFG_RUSTLLVM) \ $$(TSTDLIB_DEFAULT$(1)_T_$(2)_H_$(3)) @$$(call E, compile_and_link: $$@) - $$(STAGE$(1)_T_$(2)_H_$(3)) --lib -o $$@ $$< + $$(STAGE$(1)_T_$(2)_H_$(3)) --lib -o $$@ $$< && touch $$@ endef diff --git a/src/comp/back/link.rs b/src/comp/back/link.rs index dea4481fa26..36a6daeff81 100644 --- a/src/comp/back/link.rs +++ b/src/comp/back/link.rs @@ -551,7 +551,8 @@ fn mangle_internal_name_by_seq(ccx: @crate_ctxt, flav: str) -> str { // gcc to link the object file with some libs fn link_binary(sess: session::session, obj_filename: str, - out_filename: str) { + out_filename: str, + lm: link_meta) { // The default library location, we need this to find the runtime. // The location of crates will be determined as needed. let stage: str = "-L" + sess.filesearch().get_target_lib_path(); @@ -611,14 +612,17 @@ fn link_binary(sess: session::session, let used_libs = cstore::get_used_libraries(cstore); for l: str in used_libs { gcc_args += ["-l" + l]; } + let long_libname = + std::os::dylib_filename(#fmt("%s-%s-%s", + lm.name, lm.extras_hash, lm.vers)); + if sess.building_library() { gcc_args += [lib_cmd]; // On mac we need to tell the linker to let this library // be rpathed if sess.get_targ_cfg().os == session::os_macos { - gcc_args += ["-Wl,-install_name,@rpath/" - + fs::basename(out_filename)]; + gcc_args += ["-Wl,-install_name,@rpath/" + long_libname]; } } else { // FIXME: why do we hardcode -lm? @@ -651,19 +655,22 @@ fn link_binary(sess: session::session, sess.note(prog.err + prog.out); sess.abort_if_errors(); } - // Clean up on Darwin + // Clean up on Darwin if sess.get_targ_cfg().os == session::os_macos { run::run_program("dsymutil", [out_filename]); } - // Remove the temporary object file if we aren't saving temps if !sess.get_opts().save_temps { run::run_program("rm", [obj_filename]); } -} + if sess.building_library() { + let fullname = fs::connect(fs::dirname(out_filename), long_libname); + run::run_program("mv", [out_filename, fullname]); + } +} // // Local Variables: // mode: rust diff --git a/src/comp/driver/rustc.rs b/src/comp/driver/rustc.rs index 105832735a4..76c51e35da7 100644 --- a/src/comp/driver/rustc.rs +++ b/src/comp/driver/rustc.rs @@ -10,7 +10,7 @@ import middle::{trans, resolve, freevars, kind, ty, typeck, fn_usage, import syntax::print::{pp, pprust}; import util::{ppaux, filesearch}; import back::link; -import std::{option, str, vec, int, io, getopts, result}; +import std::{fs, option, str, vec, int, io, getopts, result}; import std::option::{some, none}; import std::getopts::{optopt, optmulti, optflag, optflagopt, opt_present}; import back::{x86, x86_64}; @@ -193,7 +193,7 @@ fn compile_input(sess: session::session, cfg: ast::crate_cfg, input: str, let outputs = build_output_filenames(input, output, sess); - let llmod = + let (llmod, link_meta) = time(time_passes, "translation", bind trans::trans_crate(sess, crate, ty_cx, outputs.obj_filename, ast_map, @@ -209,7 +209,7 @@ fn compile_input(sess: session::session, cfg: ast::crate_cfg, input: str, time(time_passes, "Linking", bind link::link_binary(sess, outputs.obj_filename, - outputs.out_filename)); + outputs.out_filename, link_meta)); } fn pretty_print_input(sess: session::session, cfg: ast::crate_cfg, input: str, diff --git a/src/comp/metadata/creader.rs b/src/comp/metadata/creader.rs index cb806efa647..b94110acb31 100644 --- a/src/comp/metadata/creader.rs +++ b/src/comp/metadata/creader.rs @@ -157,7 +157,7 @@ fn find_library_crate_aux(sess: session::session, metas: [@ast::meta_item], filesearch: filesearch::filesearch) -> option::t<{ident: str, data: @[u8]}> { - let prefix: str = nn.prefix + crate_name; + let prefix: str = nn.prefix + crate_name + "-"; let suffix: str = nn.suffix; ret filesearch::search(filesearch, { |path| diff --git a/src/comp/middle/trans.rs b/src/comp/middle/trans.rs index df0de922fa3..fcae4dd45bf 100644 --- a/src/comp/middle/trans.rs +++ b/src/comp/middle/trans.rs @@ -6020,7 +6020,7 @@ fn write_abi_version(ccx: @crate_ctxt) { fn trans_crate(sess: session::session, crate: @ast::crate, tcx: ty::ctxt, output: str, amap: ast_map::map, mut_map: mut::mut_map, copy_map: alias::copy_map, last_uses: last_use::last_uses) - -> ModuleRef { + -> (ModuleRef, link::link_meta) { let sha = std::sha1::mk_sha1(); let link_meta = link::build_link_meta(sess, *crate, output, sha); @@ -6138,7 +6138,7 @@ fn trans_crate(sess: session::session, crate: @ast::crate, tcx: ty::ctxt, log_err #fmt["time: %s took %d ms", timing.ident, timing.time]; } } - ret llmod; + ret (llmod, link_meta); } // // Local Variables: