Skip to content

Fix #1157: Implement versioned library naming #1268

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 8 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 5 additions & 1 deletion Makefile.in
Original file line number Diff line number Diff line change
Expand Up @@ -105,9 +105,13 @@ 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)

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
Expand Down
10 changes: 10 additions & 0 deletions mk/clean.mk
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand All @@ -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
Expand Down
6 changes: 6 additions & 0 deletions mk/host.mk
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -41,13 +43,17 @@ $$(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) \
$$(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))/$(STDLIB_GLOB) \
$$(HLIB$(2)_H_$(4))

$$(HLIB$(2)_H_$(4))/libcore.rlib: \
$$(TLIB$(1)_T_$(4)_H_$(3))/libcore.rlib \
Expand Down
15 changes: 10 additions & 5 deletions mk/install.mk
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand Down Expand Up @@ -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)
Expand Down
4 changes: 4 additions & 0 deletions mk/platform.mk
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -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=
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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)
Expand Down
12 changes: 10 additions & 2 deletions mk/stage0.mk
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -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)
Expand Down
6 changes: 3 additions & 3 deletions mk/target.mk
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -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

Expand Down
69 changes: 41 additions & 28 deletions src/comp/back/link.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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
*
Expand Down Expand Up @@ -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];
}
Expand All @@ -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);
}

Expand Down Expand Up @@ -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};
}
Expand Down Expand Up @@ -551,24 +559,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) {
// 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();

let prog: str = "gcc";
// The invocations of gcc share some flags across platforms

let gcc_args =
[stage] + sess.get_targ_cfg().target_strs.gcc_args +
["-o", out_filename, obj_filename];
let lib_cmd;

let os = sess.get_targ_cfg().os;
if os == session::os_macos {
lib_cmd = "-dynamiclib";
} else { lib_cmd = "-shared"; }

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 =
Expand All @@ -592,6 +584,30 @@ fn link_binary(sess: session::session,
};
}

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();

let prog: str = "gcc";
// The invocations of gcc share some flags across platforms

let gcc_args =
[stage] + sess.get_targ_cfg().target_strs.gcc_args +
["-o", output, obj_filename];

let lib_cmd;
let os = sess.get_targ_cfg().os;
if os == session::os_macos {
lib_cmd = "-dynamiclib";
} else { lib_cmd = "-shared"; }

let cstore = sess.get_cstore();
for cratepath: str in cstore::get_used_crate_files(cstore) {
if str::ends_with(cratepath, ".rlib") {
Expand All @@ -618,14 +634,13 @@ fn link_binary(sess: session::session,
// be rpathed
if sess.get_targ_cfg().os == session::os_macos {
gcc_args += ["-Wl,-install_name,@rpath/"
+ fs::basename(out_filename)];
+ fs::basename(output)];
}
} else {
// FIXME: why do we hardcode -lm?
gcc_args += ["-lm"];
}


// Always want the runtime linked in
gcc_args += ["-lrustrt"];

Expand All @@ -640,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
Expand All @@ -651,19 +666,17 @@ 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]);
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]);
}
}

//
// Local Variables:
// mode: rust
Expand Down
6 changes: 3 additions & 3 deletions src/comp/driver/rustc.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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};
Expand Down Expand Up @@ -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,
Expand All @@ -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,
Expand Down
2 changes: 2 additions & 0 deletions src/comp/metadata/common.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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); }

Expand Down
Loading