From 42614484ebeed926db7ba3d2f3a8ef46819db7c6 Mon Sep 17 00:00:00 2001 From: Haitao Li Date: Fri, 18 Nov 2011 16:00:28 +0800 Subject: [PATCH 1/8] Using filename when finding libraries for linking Revert #999 commit 16dad84f7b2f173db012dda2e77b08ccb423391f --- Makefile.in | 2 +- src/comp/metadata/creader.rs | 30 ++++++++++++++++++++++-------- 2 files changed, 23 insertions(+), 9 deletions(-) diff --git a/Makefile.in b/Makefile.in index c0a56c7896861..51bc708c36c10 100644 --- a/Makefile.in +++ b/Makefile.in @@ -105,7 +105,7 @@ endif CFG_RUNTIME :=$(call CFG_LIB_NAME,rustrt) CFG_RUSTLLVM :=$(call CFG_LIB_NAME,rustllvm) CFG_CORELIB :=$(call CFG_LIB_NAME,core) -CFG_STDLIB :=$(call CFG_LIB_NAME,ruststd) +CFG_STDLIB :=$(call CFG_LIB_NAME,std) CFG_LIBRUSTC :=$(call CFG_LIB_NAME,rustc) # version-string calculation diff --git a/src/comp/metadata/creader.rs b/src/comp/metadata/creader.rs index cb1273ec4898f..cb806efa6474d 100644 --- a/src/comp/metadata/creader.rs +++ b/src/comp/metadata/creader.rs @@ -125,25 +125,39 @@ fn find_library_crate(sess: session::session, ident: ast::ident, attr::require_unique_names(sess, metas); let metas = metas; - // Metadata "name" will be used to find the crate. Use `ident' - // as "name" if the attribute is not explicitly specified - if !attr::contains_name(metas, "name") { - metas += [attr::mk_name_value_item_str("name", ident)]; - } + let crate_name = + { + let name_items = attr::find_meta_items_by_name(metas, "name"); + alt vec::last(name_items) { + some(i) { + alt attr::get_meta_item_value_str(i) { + some(n) { n } + // FIXME: Probably want a warning here since the user + // is using the wrong type of meta item + _ { ident } + } + } + none. { ident } + } + }; + let nn = default_native_lib_naming(sess, sess.get_opts().static); let x = - find_library_crate_aux(sess, nn, metas, sess.filesearch()); + find_library_crate_aux(sess, nn, crate_name, + metas, sess.filesearch()); if x != none || sess.get_opts().static { ret x; } let nn2 = default_native_lib_naming(sess, true); - ret find_library_crate_aux(sess, nn2, metas, sess.filesearch()); + ret find_library_crate_aux(sess, nn2, crate_name, metas, + sess.filesearch()); } fn find_library_crate_aux(sess: session::session, nn: {prefix: str, suffix: str}, + crate_name: str, metas: [@ast::meta_item], filesearch: filesearch::filesearch) -> option::t<{ident: str, data: @[u8]}> { - let prefix: str = nn.prefix; + let prefix: str = nn.prefix + crate_name; let suffix: str = nn.suffix; ret filesearch::search(filesearch, { |path| From 0d7ab488eae189f73b80b0a06ffb747419892ac9 Mon Sep 17 00:00:00 2001 From: Haitao Li Date: Sat, 3 Dec 2011 00:51:59 +0800 Subject: [PATCH 2/8] 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 51bc708c36c10..5d98b87e0166d 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 071b4ae0350a1..e28bfc92c5e5a 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 add7278dee297..475fa8085a698 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 c22a4a3701080..e0e32769629cf 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 4a70e545862d6..c4cce8c94388f 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 6170aedb61097..4df1d6dd3928b 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 dea4481fa26da..36a6daeff81f4 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 105832735a465..76c51e35da7d5 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 cb806efa6474d..b94110acb3136 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 df0de922fa36c..fcae4dd45bf7b 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: From 24c912e9db1c78ab379fd55d887afdf691fe17ed Mon Sep 17 00:00:00 2001 From: Haitao Li Date: Fri, 9 Dec 2011 00:02:25 +0800 Subject: [PATCH 3/8] Update snapshot scripts to pick up the versioned libraries --- src/etc/snapshot.py | 30 +++++++++++++++++++++--------- 1 file changed, 21 insertions(+), 9 deletions(-) diff --git a/src/etc/snapshot.py b/src/etc/snapshot.py index b8e3a5c898310..22dce4b8781d8 100644 --- a/src/etc/snapshot.py +++ b/src/etc/snapshot.py @@ -1,4 +1,4 @@ -import re, os, sys, hashlib, tarfile, shutil, subprocess, tempfile +import re, os, sys, glob, hashlib, tarfile, shutil, subprocess, tempfile def scrub(b): if sys.version_info >= (3,) and type(b) == bytes: @@ -17,18 +17,18 @@ def scrub(b): snapshot_files = { "linux": ["bin/rustc", - "lib/libcore.so", - "lib/libruststd.so", + "lib/libcore-*.so", + "lib/libstd-*.so", "lib/librustrt.so", "lib/librustllvm.so"], "macos": ["bin/rustc", - "lib/libcore.dylib", - "lib/libruststd.dylib", + "lib/libcore-*.dylib", + "lib/libstd-*.dylib", "lib/librustrt.dylib", "lib/librustllvm.dylib"], "winnt": ["bin/rustc.exe", - "lib/core.dll", - "lib/ruststd.dll", + "lib/core-*.dll", + "lib/std-*.dll", "lib/rustrt.dll", "lib/rustllvm.dll"] } @@ -128,13 +128,25 @@ def make_snapshot(stage, triple, flag): file0 = partial_snapshot_name(date, rev, platform) + def in_tar_name(fn): + cs = fn.split(os.sep) + if len(cs) >= 2: + return os.sep.join(cs[-2:]) + tar = tarfile.open(file0, "w:bz2") for name in snapshot_files[kernel]: dir = stage if stage == "stage1" and re.match(r"^lib/(lib)?std.*", name): dir = "stage0" - tar.add(os.path.join(triple, os.path.join(dir, name)), - "rust-stage0/" + name) + fn_glob = os.path.join(triple, dir, name) + matches = glob.glob(fn_glob) + if not matches: + raise Exception("Not found file with name like " + fn_glob) + if len(matches) == 1: + tar.add(matches[0], "rust-stage0/" + in_tar_name(matches[0])) + else: + raise Exception("Found stale files: \n %s\n\ +Please make a clean build." % "\n ".join(matches)) tar.close() h = hash_file(file0) From 643771d2888f91029c399c55f0d0109b3465d9cc Mon Sep 17 00:00:00 2001 From: Haitao Li Date: Fri, 9 Dec 2011 00:01:48 +0800 Subject: [PATCH 4/8] build: Temp hack to make transition to new snapshot --- mk/stage0.mk | 12 ++++++++++-- src/etc/get-snapshot.py | 19 ++++++++++++++++++- 2 files changed, 28 insertions(+), 3 deletions(-) diff --git a/mk/stage0.mk b/mk/stage0.mk index 7614c23040685..ac57d5f0923be 100644 --- a/mk/stage0.mk +++ b/mk/stage0.mk @@ -13,13 +13,21 @@ $(HLIB0_H_$(CFG_HOST_TRIPLE))/$(CFG_RUNTIME): \ $(HBIN0_H_$(CFG_HOST_TRIPLE))/rustc$(X) $(Q)touch $@ +## FIXME temporary hack for snapshot transition +CORELIB_DUMMY :=$(call CFG_LIB_NAME,core-dummy) +STDLIB_DUMMY :=$(call CFG_LIB_NAME,std-dummy) + $(HLIB0_H_$(CFG_HOST_TRIPLE))/$(CFG_CORELIB): \ $(HBIN0_H_$(CFG_HOST_TRIPLE))/rustc$(X) $(Q)touch $@ + $(foreach target,$(CFG_TARGET_TRIPLES),\ + $(shell touch $(CFG_HOST_TRIPLE)/stage0/lib/rustc/$(target)/lib/$(CORELIB_DUMMY))) $(HLIB0_H_$(CFG_HOST_TRIPLE))/$(CFG_STDLIB): \ $(HBIN0_H_$(CFG_HOST_TRIPLE))/rustc$(X) $(Q)touch $@ + $(foreach target,$(CFG_TARGET_TRIPLES),\ + $(shell touch $(CFG_HOST_TRIPLE)/stage0/lib/rustc/$(target)/lib/$(STDLIB_DUMMY))) $(HLIB0_H_$(CFG_HOST_TRIPLE))/$(CFG_RUSTLLVM): \ $(HBIN0_H_$(CFG_HOST_TRIPLE))/rustc$(X) @@ -45,12 +53,12 @@ $$(HLIB0_H_$(1))/$$(CFG_RUNTIME): \ $$(HLIB0_H_$(1))/$(CFG_CORELIB): \ $$(TLIB$(2)_T_$(1)_H_$(3))/$$(CFG_CORELIB) @$$(call E, cp: $$@) - $$(Q)cp $$< $$@ + $$(Q)cp $$(TLIB$(2)_T_$(1)_H_$(3))/$$(CORELIB_GLOB) $$@ $$(HLIB0_H_$(1))/$(CFG_STDLIB): \ $$(TLIB$(2)_T_$(1)_H_$(3))/$$(CFG_STDLIB) @$$(call E, cp: $$@) - $$(Q)cp $$< $$@ + $$(Q)cp $$(TLIB$(2)_T_$(1)_H_$(3))/$$(STDLIB_GLOB) $$@ $$(HLIB0_H_$(1))/$(CFG_RUSTLLVM): \ $$(TLIB$(2)_T_$(1)_H_$(3))/$$(CFG_RUSTLLVM) diff --git a/src/etc/get-snapshot.py b/src/etc/get-snapshot.py index 40fbd70cf71c8..b42a76350d998 100755 --- a/src/etc/get-snapshot.py +++ b/src/etc/get-snapshot.py @@ -3,13 +3,30 @@ import os, tarfile, hashlib, re, shutil, sys from snapshot import * +old_snapshot_files = { + "linux": ["bin/rustc", + "lib/libcore.so", + "lib/libruststd.so", + "lib/librustrt.so", + "lib/librustllvm.so"], + "macos": ["bin/rustc", + "lib/libcore.dylib", + "lib/libruststd.dylib", + "lib/librustrt.dylib", + "lib/librustllvm.dylib"], + "winnt": ["bin/rustc.exe", + "lib/core.dll", + "lib/ruststd.dll", + "lib/rustrt.dll", + "lib/rustllvm.dll"] + } def unpack_snapshot(triple, snap): dl_path = os.path.join(download_dir_base, snap) print("opening snapshot " + dl_path) tar = tarfile.open(dl_path) kernel = get_kernel(triple) - for name in snapshot_files[kernel]: + for name in old_snapshot_files[kernel]: p = "rust-stage0/" + name stagep = os.path.join(triple, "stage0") fp = os.path.join(stagep, name) From 094bb5fd5337d7795c7ea2af90457719cf32330a Mon Sep 17 00:00:00 2001 From: Haitao Li Date: Sun, 11 Dec 2011 23:23:38 +0800 Subject: [PATCH 5/8] rustc: Encode crate hash into metadata --- src/comp/metadata/common.rs | 2 ++ src/comp/metadata/decoder.rs | 14 +++++++++++--- src/comp/metadata/encoder.rs | 8 ++++++++ 3 files changed, 21 insertions(+), 3 deletions(-) diff --git a/src/comp/metadata/common.rs b/src/comp/metadata/common.rs index fdb2d72da6f3f..8002fddf3c9a9 100644 --- a/src/comp/metadata/common.rs +++ b/src/comp/metadata/common.rs @@ -64,6 +64,8 @@ const tag_crate_dep: uint = 0x26u; const tag_items_data_item_inlineness: uint = 0x27u; +const tag_crate_hash: uint = 0x28u; + // djb's cdb hashes. fn hash_node_id(&&node_id: int) -> uint { ret 177573u ^ (node_id as uint); } diff --git a/src/comp/metadata/decoder.rs b/src/comp/metadata/decoder.rs index b5c32efe66f1f..541b7c3263523 100644 --- a/src/comp/metadata/decoder.rs +++ b/src/comp/metadata/decoder.rs @@ -19,6 +19,7 @@ export get_crate_attributes; export list_crate_metadata; export crate_dep; export get_crate_deps; +export get_crate_hash; export external_resolver; // A function that takes a def_id relative to the crate being searched and @@ -347,8 +348,8 @@ fn list_meta_items(meta_items: ebml::doc, out: io::writer) { } } -fn list_crate_attributes(md: ebml::doc, out: io::writer) { - out.write_str("=Crate Attributes=\n"); +fn list_crate_attributes(md: ebml::doc, hash: str, out: io::writer) { + out.write_str(#fmt("=Crate Attributes (%s)=\n", hash)); for attr: ast::attribute in get_attributes(md) { out.write_str(#fmt["%s\n", pprust::attribute_to_str(attr)]); @@ -386,6 +387,12 @@ fn list_crate_deps(data: @[u8], out: io::writer) { out.write_str("\n"); } +fn get_crate_hash(data: @[u8]) -> str { + let cratedoc = ebml::new_doc(data); + let hashdoc = ebml::get_doc(cratedoc, tag_crate_hash); + ret str::unsafe_from_bytes(ebml::doc_data(hashdoc)); +} + fn list_crate_items(bytes: @[u8], md: ebml::doc, out: io::writer) { out.write_str("=Items=\n"); let paths = ebml::get_doc(md, tag_paths); @@ -407,8 +414,9 @@ fn list_crate_items(bytes: @[u8], md: ebml::doc, out: io::writer) { } fn list_crate_metadata(bytes: @[u8], out: io::writer) { + let hash = get_crate_hash(bytes); let md = ebml::new_doc(bytes); - list_crate_attributes(md, out); + list_crate_attributes(md, hash, out); list_crate_deps(bytes, out); list_crate_items(bytes, md, out); } diff --git a/src/comp/metadata/encoder.rs b/src/comp/metadata/encoder.rs index 8eb0ea64e49b0..646c016d97d7e 100644 --- a/src/comp/metadata/encoder.rs +++ b/src/comp/metadata/encoder.rs @@ -576,6 +576,12 @@ fn encode_crate_deps(ebml_w: ebml::writer, cstore: cstore::cstore) { ebml::end_tag(ebml_w); } +fn encode_hash(ebml_w: ebml::writer, hash: str) { + ebml::start_tag(ebml_w, tag_crate_hash); + ebml_w.writer.write(str::bytes(hash)); + ebml::end_tag(ebml_w); +} + fn encode_metadata(cx: @crate_ctxt, crate: @crate) -> str { let abbrevs = map::mk_hashmap(ty::hash_ty, ty::eq_ty); @@ -585,6 +591,8 @@ fn encode_metadata(cx: @crate_ctxt, crate: @crate) -> str { let buf_w = string_w.get_writer().get_buf_writer(); let ebml_w = ebml::create_writer(buf_w); + encode_hash(ebml_w, cx.link_meta.extras_hash); + let crate_attrs = synthesize_crate_attrs(ecx, crate); encode_attributes(ebml_w, crate_attrs); From 4ec9957e97080af55932a710b33f0734514d6958 Mon Sep 17 00:00:00 2001 From: Haitao Li Date: Sun, 11 Dec 2011 23:42:32 +0800 Subject: [PATCH 6/8] rustc: Hash includes direct dependent crates --- src/comp/back/link.rs | 14 +++++++++++--- src/comp/metadata/cstore.rs | 25 +++++++++++++++++++++++++ 2 files changed, 36 insertions(+), 3 deletions(-) diff --git a/src/comp/back/link.rs b/src/comp/back/link.rs index 36a6daeff81f4..ed0ddad7fe200 100644 --- a/src/comp/back/link.rs +++ b/src/comp/back/link.rs @@ -348,7 +348,7 @@ mod write { * - Define CMETA as all the non-name, non-vers exported meta tags in the * crate (in sorted order). * - * - Define CMH as hash(CMETA). + * - Define CMH as hash(CMETA + hashes of dependent crates). * * - Compile our crate to lib CNAME-CMH-CVERS.so * @@ -395,7 +395,8 @@ fn build_link_meta(sess: session::session, c: ast::crate, output: str, // This calculates CMH as defined above fn crate_meta_extras_hash(sha: sha1, _crate: ast::crate, - metas: provided_metas) -> str { + metas: provided_metas, + dep_hashes: [str]) -> str { fn len_and_str(s: str) -> str { ret #fmt["%u_%s", str::byte_len(s), s]; } @@ -421,6 +422,11 @@ fn build_link_meta(sess: session::session, c: ast::crate, output: str, } } } + + for dh in dep_hashes { + sha.input_str(len_and_str(dh)); + } + ret truncated_sha1_result(sha); } @@ -463,7 +469,9 @@ fn build_link_meta(sess: session::session, c: ast::crate, output: str, let provided_metas = provided_link_metas(sess, c); let name = crate_meta_name(sess, c, output, provided_metas); let vers = crate_meta_vers(sess, c, provided_metas); - let extras_hash = crate_meta_extras_hash(sha, c, provided_metas); + let dep_hashes = cstore::get_dep_hashes(sess.get_cstore()); + let extras_hash = + crate_meta_extras_hash(sha, c, provided_metas, dep_hashes); ret {name: name, vers: vers, extras_hash: extras_hash}; } diff --git a/src/comp/metadata/cstore.rs b/src/comp/metadata/cstore.rs index c0f8588c8a2fb..e7ca671fea890 100644 --- a/src/comp/metadata/cstore.rs +++ b/src/comp/metadata/cstore.rs @@ -20,6 +20,8 @@ export add_used_link_args; export get_used_link_args; export add_use_stmt_cnum; export get_use_stmt_cnum; +export get_dep_hashes; + // A map from external crate numbers (as decoded from some crate file) to // local crate numbers (as generated during this session). Each external @@ -116,6 +118,29 @@ fn get_use_stmt_cnum(cstore: cstore, use_id: ast::node_id) -> ast::crate_num { ret p(cstore).use_crate_map.get(use_id); } +// returns hashes of crates directly used by this crate. Hashes are +// sorted by crate name. +fn get_dep_hashes(cstore: cstore) -> [str] { + type crate_hash = {name: str, hash: str}; + let result = []; + + p(cstore).use_crate_map.values {|cnum| + let cdata = cstore::get_crate_data(cstore, cnum); + let hash = decoder::get_crate_hash(cdata.data); + log #fmt("Add hash[%s]: %s", cdata.name, hash); + result += [{name: cdata.name, hash: hash}]; + }; + fn lteq(a: crate_hash, b: crate_hash) -> bool { + ret a.name <= b.name; + } + let sorted = std::sort::merge_sort(lteq, result); + log "sorted:"; + for x in sorted { + log #fmt(" hash[%s]: %s", x.name, x.hash); + } + fn mapper(ch: crate_hash) -> str { ret ch.hash; } + ret vec::map(mapper, sorted); +} // Local Variables: // mode: rust // fill-column: 78; From 3d20a09b9c5d0c4ff32dc462f31ea781b97d5f1e Mon Sep 17 00:00:00 2001 From: Haitao Li Date: Mon, 12 Dec 2011 17:24:12 +0800 Subject: [PATCH 7/8] rustc: Refactor and get built on Windows --- src/comp/back/link.rs | 26 ++++++++++++-------------- 1 file changed, 12 insertions(+), 14 deletions(-) diff --git a/src/comp/back/link.rs b/src/comp/back/link.rs index ed0ddad7fe200..aa00cf680549a 100644 --- a/src/comp/back/link.rs +++ b/src/comp/back/link.rs @@ -561,6 +561,13 @@ fn link_binary(sess: session::session, obj_filename: str, out_filename: str, lm: link_meta) { + let output = if sess.building_library() { + let long_libname = + std::os::dylib_filename(#fmt("%s-%s-%s", + lm.name, lm.extras_hash, lm.vers)); + fs::connect(fs::dirname(out_filename), long_libname) + } else { out_filename }; + // 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(); @@ -570,9 +577,9 @@ fn link_binary(sess: session::session, let gcc_args = [stage] + sess.get_targ_cfg().target_strs.gcc_args + - ["-o", out_filename, obj_filename]; - let lib_cmd; + ["-o", output, obj_filename]; + let lib_cmd; let os = sess.get_targ_cfg().os; if os == session::os_macos { lib_cmd = "-dynamiclib"; @@ -620,24 +627,20 @@ 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/" + long_libname]; + gcc_args += ["-Wl,-install_name,@rpath/" + + fs::basename(output)]; } } else { // FIXME: why do we hardcode -lm? gcc_args += ["-lm"]; } - // Always want the runtime linked in gcc_args += ["-lrustrt"]; @@ -666,18 +669,13 @@ fn link_binary(sess: session::session, // Clean up on Darwin if sess.get_targ_cfg().os == session::os_macos { - run::run_program("dsymutil", [out_filename]); + run::run_program("dsymutil", [output]); } // 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: From 7efc9b0172e84f8f54794147764d282f2035aa53 Mon Sep 17 00:00:00 2001 From: Haitao Li Date: Mon, 12 Dec 2011 21:40:03 +0800 Subject: [PATCH 8/8] rustc: Work around a segmentation fault On Linux/Mac, I got a segmentation fault: (gdb) bt #0 0x00000000007519af in glue_take584 () #1 0x00000000006d4bec in back::rpath::get_rpath_flags::_3899df2ca513c603 () #2 0x00000000006c7655 in back::link::link_binary::_7afde00a9791031c () #3 0x00000000007d3ff5 in driver::rustc::compile_input::thunk9212 () #4 0x0000000000710f24 in driver::rustc::time::_3e691b2a4ba58aee () #5 0x000000000071a79d in driver::rustc::compile_input::_7b4a41b87c18e034 () #6 0x000000000072f0a9 in driver::rustc::main::_cd8b8c8185af3dee () #7 0x000000000072f1ed in _rust_main () #8 0x00007ffff7e6e146 in task_start_wrapper (a=) at ../src/rt/rust_task.cpp:176 The variable `output` or `out_filename` becomes (null) after the definition of `fn unlib`. Move the function defintion to the beginning seems prevent the crash on Linux. --- src/comp/back/link.rs | 48 +++++++++++++++++++++---------------------- 1 file changed, 24 insertions(+), 24 deletions(-) diff --git a/src/comp/back/link.rs b/src/comp/back/link.rs index aa00cf680549a..d6cbd2aa9faea 100644 --- a/src/comp/back/link.rs +++ b/src/comp/back/link.rs @@ -561,6 +561,29 @@ fn link_binary(sess: session::session, obj_filename: str, out_filename: str, lm: link_meta) { + // Converts a library file name into a gcc -l argument + fn unlib(config: @session::config, filename: str) -> str { + let rmlib = + bind fn (config: @session::config, filename: str) -> str { + if config.os == session::os_macos || + config.os == session::os_linux && + str::find(filename, "lib") == 0 { + ret str::slice(filename, 3u, + str::byte_len(filename)); + } else { ret filename; } + }(config, _); + fn rmext(filename: str) -> str { + let parts = str::split(filename, '.' as u8); + vec::pop(parts); + ret str::connect(parts, "."); + } + ret alt config.os { + session::os_macos. { rmext(rmlib(filename)) } + session::os_linux. { rmext(rmlib(filename)) } + _ { rmext(filename) } + }; + } + let output = if sess.building_library() { let long_libname = std::os::dylib_filename(#fmt("%s-%s-%s", @@ -585,29 +608,6 @@ fn link_binary(sess: session::session, lib_cmd = "-dynamiclib"; } else { lib_cmd = "-shared"; } - // Converts a library file name into a gcc -l argument - fn unlib(config: @session::config, filename: str) -> str { - let rmlib = - bind fn (config: @session::config, filename: str) -> str { - if config.os == session::os_macos || - config.os == session::os_linux && - str::find(filename, "lib") == 0 { - ret str::slice(filename, 3u, - str::byte_len(filename)); - } else { ret filename; } - }(config, _); - fn rmext(filename: str) -> str { - let parts = str::split(filename, '.' as u8); - vec::pop(parts); - ret str::connect(parts, "."); - } - ret alt config.os { - session::os_macos. { rmext(rmlib(filename)) } - session::os_linux. { rmext(rmlib(filename)) } - _ { rmext(filename) } - }; - } - let cstore = sess.get_cstore(); for cratepath: str in cstore::get_used_crate_files(cstore) { if str::ends_with(cratepath, ".rlib") { @@ -655,7 +655,7 @@ fn link_binary(sess: session::session, gcc_args += ["-lmorestack"]; } - gcc_args += rpath::get_rpath_flags(sess, out_filename); + gcc_args += rpath::get_rpath_flags(sess, output); log #fmt("gcc link args: %s", str::connect(gcc_args, " ")); // We run 'gcc' here