Skip to content

Commit 6dbd4c2

Browse files
lhtgraydon
authored andcommitted
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`.
1 parent b4f450a commit 6dbd4c2

File tree

10 files changed

+56
-20
lines changed

10 files changed

+56
-20
lines changed

Makefile.in

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -108,6 +108,10 @@ CFG_CORELIB :=$(call CFG_LIB_NAME,core)
108108
CFG_STDLIB :=$(call CFG_LIB_NAME,std)
109109
CFG_LIBRUSTC :=$(call CFG_LIB_NAME,rustc)
110110

111+
STDLIB_GLOB :=$(call CFG_LIB_GLOB,std)
112+
CORELIB_GLOB :=$(call CFG_LIB_GLOB,core)
113+
LIBRUSTC_GLOB :=$(call CFG_LIB_GLOB,rustc)
114+
111115
# version-string calculation
112116
CFG_GIT_DIR := $(CFG_SRC_DIR).git
113117
CFG_VERSION = prerelease

mk/clean.mk

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,12 @@ clean$(1)_H_$(2):
5656
$(Q)rm -f $$(HBIN$(1)_H_$(2))/fuzzer$(X)
5757
$(Q)rm -f $$(HBIN$(1)_H_$(2))/cargo$(X)
5858
$(Q)rm -f $$(HLIB$(1)_H_$(2))/$(CFG_RUNTIME)
59+
$(Q)rm -f $$(HLIB$(1)_H_$(2))/$(CFG_CORELIB)
5960
$(Q)rm -f $$(HLIB$(1)_H_$(2))/$(CFG_STDLIB)
61+
$(Q)rm -f $$(HLIB$(1)_H_$(2))/$(CFG_LIBRUSTC)
62+
$(Q)rm -f $$(HLIB$(1)_H_$(2))/$(CORELIB_GLOB)
63+
$(Q)rm -f $$(HLIB$(1)_H_$(2))/$(STDLIB_GLOB)
64+
$(Q)rm -f $$(HLIB$(1)_H_$(2))/$(LIBRUSTC_GLOB)
6065
$(Q)rm -f $$(HLIB$(1)_H_$(2))/$(CFG_RUSTLLVM)
6166
$(Q)rm -f $$(HLIB$(1)_H_$(2))/libstd.rlib
6267

@@ -72,7 +77,12 @@ clean$(1)_T_$(2)_H_$(3):
7277
$(Q)rm -f $$(TBIN$(1)_T_$(2)_H_$(3))/rustc$(X)
7378
$(Q)rm -f $$(TBIN$(1)_T_$(2)_H_$(3))/fuzzer$(X)
7479
$(Q)rm -f $$(TLIB$(1)_T_$(2)_H_$(3))/$(CFG_RUNTIME)
80+
$(Q)rm -f $$(TLIB$(1)_T_$(2)_H_$(3))/$(CFG_CORELIB)
7581
$(Q)rm -f $$(TLIB$(1)_T_$(2)_H_$(3))/$(CFG_STDLIB)
82+
$(Q)rm -f $$(TLIB$(1)_T_$(2)_H_$(3))/$(CFG_LIBRUSTC)
83+
$(Q)rm -f $$(TLIB$(1)_T_$(2)_H_$(3))/$(CORELIB_GLOB)
84+
$(Q)rm -f $$(TLIB$(1)_T_$(2)_H_$(3))/$(STDLIB_GLOB)
85+
$(Q)rm -f $$(TLIB$(1)_T_$(2)_H_$(3))/$(LIBRUSTC_GLOB)
7686
$(Q)rm -f $$(TLIB$(1)_T_$(2)_H_$(3))/$(CFG_RUSTLLVM)
7787
$(Q)rm -f $$(TLIB$(1)_T_$(2)_H_$(3))/libstd.rlib
7888
$(Q)rm -f $$(TLIB$(1)_T_$(2)_H_$(3))/intrinsics.bc

mk/host.mk

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,8 @@ $$(HLIB$(2)_H_$(4))/$$(CFG_LIBRUSTC): \
3030
$$(HSTDLIB_DEFAULT$(2)_H_$(3))
3131
@$$(call E, cp: $$@)
3232
$$(Q)cp $$< $$@
33+
$$(Q)cp $$(TLIB$(1)_T_$(4)_H_$(3))/$(LIBRUSTC_GLOB) \
34+
$$(HLIB$(2)_H_$(4))
3335

3436
$$(HLIB$(2)_H_$(4))/$$(CFG_RUNTIME): \
3537
$$(TLIB$(1)_T_$(4)_H_$(3))/$$(CFG_RUNTIME)
@@ -41,13 +43,17 @@ $$(HLIB$(2)_H_$(4))/$$(CFG_CORELIB): \
4143
$$(HLIB$(2)_H_$(4))/$$(CFG_RUNTIME)
4244
@$$(call E, cp: $$@)
4345
$$(Q)cp $$< $$@
46+
$$(Q)cp $$(TLIB$(1)_T_$(4)_H_$(3))/$(CORELIB_GLOB) \
47+
$$(HLIB$(2)_H_$(4))
4448

4549
$$(HLIB$(2)_H_$(4))/$$(CFG_STDLIB): \
4650
$$(TLIB$(1)_T_$(4)_H_$(3))/$$(CFG_STDLIB) \
4751
$$(HLIB$(2)_H_$(4))/$$(CFG_CORELIB) \
4852
$$(HLIB$(2)_H_$(4))/$$(CFG_RUNTIME)
4953
@$$(call E, cp: $$@)
5054
$$(Q)cp $$< $$@
55+
$$(Q)cp $$(TLIB$(1)_T_$(4)_H_$(3))/$(STDLIB_GLOB) \
56+
$$(HLIB$(2)_H_$(4))
5157

5258
$$(HLIB$(2)_H_$(4))/libcore.rlib: \
5359
$$(TLIB$(1)_T_$(4)_H_$(3))/libcore.rlib \

mk/install.mk

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -3,11 +3,14 @@
33
# mirror of the installation directory structure.
44

55
# Installation macro. Call with source directory as arg 1,
6-
# destination directory as arg 2, and filename as arg 3
6+
# destination directory as arg 2, and filename/libname-glob as arg 3
77
ifdef VERBOSE
88
INSTALL = cp $(1)/$(3) $(2)/$(3)
9+
INSTALL_LIB = cp `ls -rt1 $(1)/$(3) | tail -1` $(2)/
910
else
1011
INSTALL = $(Q)$(call E, install: $(2)/$(3)) && cp $(1)/$(3) $(2)/$(3)
12+
INSTALL_LIB = $(Q)$(call E, install_lib: $(2)/$(3)) && \
13+
cp `ls -rt1 $(1)/$(3) | tail -1` $(2)/
1114
endif
1215

1316
# The stage we install from
@@ -33,8 +36,10 @@ PTL$(1)$(2) = $$(PTR$(1)$(2))/lib
3336
install-target-$(1)-host-$(2): $$(SREQ$$(ISTAGE)_T_$(1)_H_$(2))
3437
$$(Q)mkdir -p $$(PTL$(1)$(2))
3538
$$(Q)$$(call INSTALL,$$(TL$(1)$(2)),$$(PTL$(1)$(2)),$$(CFG_RUNTIME))
36-
$$(Q)$$(call INSTALL,$$(TL$(1)$(2)),$$(PTL$(1)$(2)),$$(CFG_CORELIB))
37-
$$(Q)$$(call INSTALL,$$(TL$(1)$(2)),$$(PTL$(1)$(2)),$$(CFG_STDLIB))
39+
$$(Q)$$(call INSTALL_LIB, \
40+
$$(TL$(1)$(2)),$$(PTL$(1)$(2)),$$(CORELIB_GLOB))
41+
$$(Q)$$(call INSTALL_LIB, \
42+
$$(TL$(1)$(2)),$$(PTL$(1)$(2)),$$(STDLIB_GLOB))
3843
$$(Q)$$(call INSTALL,$$(TL$(1)$(2)),$$(PTL$(1)$(2)),intrinsics.bc)
3944
$$(Q)$$(call INSTALL,$$(TL$(1)$(2)),$$(PTL$(1)$(2)),libmorestack.a)
4045
endef
@@ -62,8 +67,8 @@ install-host: $(SREQ$(ISTAGE)_T_$(CFG_HOST_TRIPLE)_H_$(CFG_HOST_TRIPLE))
6267
$(Q)mkdir -p $(PREFIX_ROOT)/share/man/man1
6368
$(Q)$(call INSTALL,$(HB),$(PHB),rustc$(X))
6469
$(Q)$(call INSTALL,$(HL),$(PHL),$(CFG_RUNTIME))
65-
$(Q)$(call INSTALL,$(HL),$(PHL),$(CFG_CORELIB))
66-
$(Q)$(call INSTALL,$(HL),$(PHL),$(CFG_STDLIB))
70+
$(Q)$(call INSTALL_LIB,$(HL),$(PHL),$(CORELIB_GLOB))
71+
$(Q)$(call INSTALL_LIB,$(HL),$(PHL),$(STDLIB_GLOB))
6772
$(Q)$(call INSTALL,$(HL),$(PHL),$(CFG_RUSTLLVM))
6873
$(Q)$(call INSTALL,$(S)/man, \
6974
$(PREFIX_ROOT)/share/man/man1,rustc.1)

mk/platform.mk

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@ endif
2323

2424
ifneq ($(findstring freebsd,$(CFG_OSTYPE)),)
2525
CFG_LIB_NAME=lib$(1).so
26+
CFG_LIB_GLOB=lib$(1)-*.so
2627
CFG_GCCISH_CFLAGS += -fPIC -march=i686 -I/usr/local/include
2728
CFG_GCCISH_LINK_FLAGS += -shared -fPIC -lpthread -lrt
2829
ifeq ($(CFG_CPUTYPE), x86_64)
@@ -40,6 +41,7 @@ endif
4041

4142
ifneq ($(findstring linux,$(CFG_OSTYPE)),)
4243
CFG_LIB_NAME=lib$(1).so
44+
CFG_LIB_GLOB=lib$(1)-*.so
4345
CFG_GCCISH_CFLAGS += -fPIC
4446
CFG_GCCISH_LINK_FLAGS += -shared -fPIC -ldl -lpthread -lrt
4547
CFG_GCCISH_DEF_FLAG := -Wl,--export-dynamic,--dynamic-list=
@@ -71,6 +73,7 @@ endif
7173

7274
ifneq ($(findstring darwin,$(CFG_OSTYPE)),)
7375
CFG_LIB_NAME=lib$(1).dylib
76+
CFG_LIB_GLOB=lib$(1)-*.dylib
7477
CFG_UNIXY := 1
7578
CFG_LDENV := DYLD_LIBRARY_PATH
7679
CFG_GCCISH_LINK_FLAGS += -dynamiclib -lpthread -framework CoreServices
@@ -156,6 +159,7 @@ ifdef CFG_WINDOWSY
156159

157160
CFG_EXE_SUFFIX := .exe
158161
CFG_LIB_NAME=$(1).dll
162+
CFG_LIB_GLOB=$(1)-*.dll
159163
CFG_DEF_SUFFIX := .def
160164
CFG_LDPATH :=$(CFG_LDPATH):$$PATH
161165
CFG_RUN=PATH="$(CFG_LDPATH):$(1)" $(2)

mk/target.mk

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -26,14 +26,14 @@ $$(TLIB$(1)_T_$(2)_H_$(3))/$$(CFG_CORELIB): \
2626
$$(CORELIB_CRATE) $$(CORELIB_INPUTS) \
2727
$$(TSREQ$(1)_T_$(2)_H_$(3))
2828
@$$(call E, compile_and_link: $$@)
29-
$$(STAGE$(1)_T_$(2)_H_$(3)) --no-core --lib -o $$@ $$<
29+
$$(STAGE$(1)_T_$(2)_H_$(3)) --no-core --lib -o $$@ $$< && touch $$@
3030

3131
$$(TLIB$(1)_T_$(2)_H_$(3))/$$(CFG_STDLIB): \
3232
$$(STDLIB_CRATE) $$(STDLIB_INPUTS) \
3333
$$(TLIB$(1)_T_$(2)_H_$(3))/$$(CFG_CORELIB) \
3434
$$(TSREQ$(1)_T_$(2)_H_$(3))
3535
@$$(call E, compile_and_link: $$@)
36-
$$(STAGE$(1)_T_$(2)_H_$(3)) --lib -o $$@ $$<
36+
$$(STAGE$(1)_T_$(2)_H_$(3)) --lib -o $$@ $$< && touch $$@
3737

3838
$$(TLIB$(1)_T_$(2)_H_$(3))/$$(CFG_RUNTIME): \
3939
rt/$(2)/$$(CFG_RUNTIME)
@@ -59,7 +59,7 @@ $$(TLIB$(1)_T_$(2)_H_$(3))/$$(CFG_LIBRUSTC): \
5959
$$(TLIB$(1)_T_$(2)_H_$(3))/$$(CFG_RUSTLLVM) \
6060
$$(TSTDLIB_DEFAULT$(1)_T_$(2)_H_$(3))
6161
@$$(call E, compile_and_link: $$@)
62-
$$(STAGE$(1)_T_$(2)_H_$(3)) --lib -o $$@ $$<
62+
$$(STAGE$(1)_T_$(2)_H_$(3)) --lib -o $$@ $$< && touch $$@
6363

6464
endef
6565

src/comp/back/link.rs

Lines changed: 13 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -551,7 +551,8 @@ fn mangle_internal_name_by_seq(ccx: @crate_ctxt, flav: str) -> str {
551551
// gcc to link the object file with some libs
552552
fn link_binary(sess: session::session,
553553
obj_filename: str,
554-
out_filename: str) {
554+
out_filename: str,
555+
lm: link_meta) {
555556
// The default library location, we need this to find the runtime.
556557
// The location of crates will be determined as needed.
557558
let stage: str = "-L" + sess.filesearch().get_target_lib_path();
@@ -611,14 +612,17 @@ fn link_binary(sess: session::session,
611612
let used_libs = cstore::get_used_libraries(cstore);
612613
for l: str in used_libs { gcc_args += ["-l" + l]; }
613614

615+
let long_libname =
616+
std::os::dylib_filename(#fmt("%s-%s-%s",
617+
lm.name, lm.extras_hash, lm.vers));
618+
614619
if sess.building_library() {
615620
gcc_args += [lib_cmd];
616621

617622
// On mac we need to tell the linker to let this library
618623
// be rpathed
619624
if sess.get_targ_cfg().os == session::os_macos {
620-
gcc_args += ["-Wl,-install_name,@rpath/"
621-
+ fs::basename(out_filename)];
625+
gcc_args += ["-Wl,-install_name,@rpath/" + long_libname];
622626
}
623627
} else {
624628
// FIXME: why do we hardcode -lm?
@@ -651,19 +655,22 @@ fn link_binary(sess: session::session,
651655
sess.note(prog.err + prog.out);
652656
sess.abort_if_errors();
653657
}
654-
// Clean up on Darwin
655658

659+
// Clean up on Darwin
656660
if sess.get_targ_cfg().os == session::os_macos {
657661
run::run_program("dsymutil", [out_filename]);
658662
}
659663

660-
661664
// Remove the temporary object file if we aren't saving temps
662665
if !sess.get_opts().save_temps {
663666
run::run_program("rm", [obj_filename]);
664667
}
665-
}
666668

669+
if sess.building_library() {
670+
let fullname = fs::connect(fs::dirname(out_filename), long_libname);
671+
run::run_program("mv", [out_filename, fullname]);
672+
}
673+
}
667674
//
668675
// Local Variables:
669676
// mode: rust

src/comp/driver/rustc.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ import middle::{trans, resolve, freevars, kind, ty, typeck, fn_usage,
1010
import syntax::print::{pp, pprust};
1111
import util::{ppaux, filesearch};
1212
import back::link;
13-
import std::{option, str, vec, int, io, getopts, result};
13+
import std::{fs, option, str, vec, int, io, getopts, result};
1414
import std::option::{some, none};
1515
import std::getopts::{optopt, optmulti, optflag, optflagopt, opt_present};
1616
import back::{x86, x86_64};
@@ -193,7 +193,7 @@ fn compile_input(sess: session::session, cfg: ast::crate_cfg, input: str,
193193

194194
let outputs = build_output_filenames(input, output, sess);
195195

196-
let llmod =
196+
let (llmod, link_meta) =
197197
time(time_passes, "translation",
198198
bind trans::trans_crate(sess, crate, ty_cx,
199199
outputs.obj_filename, ast_map,
@@ -209,7 +209,7 @@ fn compile_input(sess: session::session, cfg: ast::crate_cfg, input: str,
209209

210210
time(time_passes, "Linking",
211211
bind link::link_binary(sess, outputs.obj_filename,
212-
outputs.out_filename));
212+
outputs.out_filename, link_meta));
213213
}
214214

215215
fn pretty_print_input(sess: session::session, cfg: ast::crate_cfg, input: str,

src/comp/metadata/creader.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -157,7 +157,7 @@ fn find_library_crate_aux(sess: session::session,
157157
metas: [@ast::meta_item],
158158
filesearch: filesearch::filesearch) ->
159159
option::t<{ident: str, data: @[u8]}> {
160-
let prefix: str = nn.prefix + crate_name;
160+
let prefix: str = nn.prefix + crate_name + "-";
161161
let suffix: str = nn.suffix;
162162

163163
ret filesearch::search(filesearch, { |path|

src/comp/middle/trans.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6020,7 +6020,7 @@ fn write_abi_version(ccx: @crate_ctxt) {
60206020
fn trans_crate(sess: session::session, crate: @ast::crate, tcx: ty::ctxt,
60216021
output: str, amap: ast_map::map, mut_map: mut::mut_map,
60226022
copy_map: alias::copy_map, last_uses: last_use::last_uses)
6023-
-> ModuleRef {
6023+
-> (ModuleRef, link::link_meta) {
60246024
let sha = std::sha1::mk_sha1();
60256025
let link_meta = link::build_link_meta(sess, *crate, output, sha);
60266026

@@ -6138,7 +6138,7 @@ fn trans_crate(sess: session::session, crate: @ast::crate, tcx: ty::ctxt,
61386138
log_err #fmt["time: %s took %d ms", timing.ident, timing.time];
61396139
}
61406140
}
6141-
ret llmod;
6141+
ret (llmod, link_meta);
61426142
}
61436143
//
61446144
// Local Variables:

0 commit comments

Comments
 (0)