Skip to content

Commit

Permalink
Merge remote-tracking branch 'remotes/origin/master' into remove-str-…
Browse files Browse the repository at this point in the history
…trailing-nulls
  • Loading branch information
erickt committed Aug 10, 2013
2 parents cab6d46 + 6f6dce7 commit ee59aac
Show file tree
Hide file tree
Showing 73 changed files with 1,740 additions and 1,109 deletions.
30 changes: 22 additions & 8 deletions doc/rust.md
Original file line number Diff line number Diff line change
Expand Up @@ -744,7 +744,7 @@ There are several kinds of view item:
##### Extern mod declarations

~~~~~~~~ {.ebnf .gram}
extern_mod_decl : "extern" "mod" ident [ '(' link_attrs ')' ] ? ;
extern_mod_decl : "extern" "mod" ident [ '(' link_attrs ')' ] ? [ '=' string_lit ] ? ;
link_attrs : link_attr [ ',' link_attrs ] + ;
link_attr : ident '=' literal ;
~~~~~~~~
Expand All @@ -755,20 +755,34 @@ as the `ident` provided in the `extern_mod_decl`.

The external crate is resolved to a specific `soname` at compile time,
and a runtime linkage requirement to that `soname` is passed to the linker for
loading at runtime. The `soname` is resolved at compile time by scanning the
compiler's library path and matching the `link_attrs` provided in the
`use_decl` against any `#link` attributes that were declared on the external
crate when it was compiled. If no `link_attrs` are provided, a default `name`
attribute is assumed, equal to the `ident` given in the `use_decl`.

Three examples of `extern mod` declarations:
loading at runtime.
The `soname` is resolved at compile time by scanning the compiler's library path
and matching the `link_attrs` provided in the `use_decl` against any `#link` attributes that
were declared on the external crate when it was compiled.
If no `link_attrs` are provided,
a default `name` attribute is assumed,
equal to the `ident` given in the `use_decl`.

Optionally, an identifier in an `extern mod` declaration may be followed by an equals sign,
then a string literal denoting a relative path on the filesystem.
This path should exist in one of the directories in the Rust path,
which by default contains the `.rust` subdirectory of the current directory and each of its parents,
as well as any directories in the colon-separated (or semicolon-separated on Windows)
list of paths that is the `RUST_PATH` environment variable.
The meaning of `extern mod a = "b/c/d";`, supposing that `/a` is in the RUST_PATH,
is that the name `a` should be taken as a reference to the crate whose absolute location is
`/a/b/c/d`.

Four examples of `extern mod` declarations:

~~~~~~~~{.xfail-test}
extern mod pcre (uuid = "54aba0f8-a7b1-4beb-92f1-4cf625264841");
extern mod extra; // equivalent to: extern mod extra ( name = "extra" );
extern mod rustextra (name = "extra"); // linking to 'extra' under another name
extern mod complicated_mod = "some-file/in/the-rust/path";
~~~~~~~~

##### Use declarations
Expand Down
2 changes: 1 addition & 1 deletion mk/install.mk
Original file line number Diff line number Diff line change
Expand Up @@ -199,7 +199,7 @@ endef
$(foreach target,$(CFG_TARGET_TRIPLES), \
$(if $(findstring $(target),"arm-linux-androideabi"), \
$(if $(findstring adb,$(CFG_ADB)), \
$(if $(findstring device,$(shell adb devices 2>/dev/null | grep -E '^[_A-Za-z0-9-]+[[:blank:]]+device')), \
$(if $(findstring device,$(shell $(CFG_ADB) devices 2>/dev/null | grep -E '^[_A-Za-z0-9-]+[[:blank:]]+device')), \
$(info install: install-runtime-target for $(target) enabled \
$(info install: android device attached) \
$(eval $(call DEF_ADB_DEVICE_STATUS, true))), \
Expand Down
6 changes: 4 additions & 2 deletions mk/tests.mk
Original file line number Diff line number Diff line change
Expand Up @@ -123,7 +123,7 @@ endef
$(foreach target,$(CFG_TARGET_TRIPLES), \
$(if $(findstring $(target),"arm-linux-androideabi"), \
$(if $(findstring adb,$(CFG_ADB)), \
$(if $(findstring device,$(shell adb devices 2>/dev/null | grep -E '^[_A-Za-z0-9-]+[[:blank:]]+device')), \
$(if $(findstring device,$(shell $(CFG_ADB) devices 2>/dev/null | grep -E '^[_A-Za-z0-9-]+[[:blank:]]+device')), \
$(info check: $(target) test enabled \
$(info check: android device attached) \
$(eval $(call DEF_ADB_DEVICE_STATUS, true))), \
Expand Down Expand Up @@ -348,7 +348,9 @@ $(3)/stage$(1)/test/rustpkgtest-$(2)$$(X_$(2)): \
$$(RUSTPKG_LIB) $$(RUSTPKG_INPUTS) \
$$(SREQ$(1)_T_$(2)_H_$(3)) \
$$(TLIB$(1)_T_$(2)_H_$(3))/$$(CFG_LIBSYNTAX_$(2)) \
$$(TLIB$(1)_T_$(2)_H_$(3))/$$(CFG_LIBRUSTC_$(2))
$$(TLIB$(1)_T_$(2)_H_$(3))/$$(CFG_LIBRUSTC_$(2)) \
$$(TBIN$(1)_T_$(2)_H_$(3))/rustpkg$$(X_$(2)) \
$$(TBIN$(1)_T_$(2)_H_$(3))/rustc$$(X_$(2))
@$$(call E, compile_and_link: $$@)
$$(STAGE$(1)_T_$(2)_H_$(3)) -o $$@ $$< --test

Expand Down
3 changes: 0 additions & 3 deletions src/libextra/time.rs
Original file line number Diff line number Diff line change
Expand Up @@ -57,9 +57,6 @@ impl Ord for Timespec {
self.sec < other.sec ||
(self.sec == other.sec && self.nsec < other.nsec)
}
fn le(&self, other: &Timespec) -> bool { !other.lt(self) }
fn ge(&self, other: &Timespec) -> bool { !self.lt(other) }
fn gt(&self, other: &Timespec) -> bool { !self.le(other) }
}

/**
Expand Down
23 changes: 19 additions & 4 deletions src/librustc/back/link.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ use lib::llvm::llvm;
use lib::llvm::ModuleRef;
use lib;
use metadata::common::LinkMeta;
use metadata::{encoder, csearch, cstore};
use metadata::{encoder, csearch, cstore, filesearch};
use middle::trans::context::CrateContext;
use middle::trans::common::gensym_name;
use middle::ty;
Expand Down Expand Up @@ -500,35 +500,40 @@ pub fn build_link_meta(sess: Session,
struct ProvidedMetas {
name: Option<@str>,
vers: Option<@str>,
pkg_id: Option<@str>,
cmh_items: ~[@ast::MetaItem]
}

fn provided_link_metas(sess: Session, c: &ast::Crate) ->
ProvidedMetas {
let mut name = None;
let mut vers = None;
let mut pkg_id = None;
let mut cmh_items = ~[];
let linkage_metas = attr::find_linkage_metas(c.attrs);
attr::require_unique_names(sess.diagnostic(), linkage_metas);
for meta in linkage_metas.iter() {
match meta.name_str_pair() {
Some((n, value)) if "name" == n => name = Some(value),
Some((n, value)) if "vers" == n => vers = Some(value),
Some((n, value)) if "package_id" == n => pkg_id = Some(value),
_ => cmh_items.push(*meta)
}
}

ProvidedMetas {
name: name,
vers: vers,
pkg_id: pkg_id,
cmh_items: cmh_items
}
}

// This calculates CMH as defined above
fn crate_meta_extras_hash(symbol_hasher: &mut hash::State,
cmh_items: ~[@ast::MetaItem],
dep_hashes: ~[@str]) -> @str {
dep_hashes: ~[@str],
pkg_id: Option<@str>) -> @str {
fn len_and_str(s: &str) -> ~str {
fmt!("%u_%s", s.len(), s)
}
Expand Down Expand Up @@ -566,7 +571,10 @@ pub fn build_link_meta(sess: Session,
write_string(symbol_hasher, len_and_str(*dh));
}

// tjc: allocation is unfortunate; need to change std::hash
for p in pkg_id.iter() {
write_string(symbol_hasher, len_and_str(*p));
}

return truncated_hash_result(symbol_hasher).to_managed();
}

Expand Down Expand Up @@ -608,18 +616,20 @@ pub fn build_link_meta(sess: Session,
let ProvidedMetas {
name: opt_name,
vers: opt_vers,
pkg_id: opt_pkg_id,
cmh_items: cmh_items
} = provided_link_metas(sess, c);
let name = crate_meta_name(sess, output, opt_name);
let vers = crate_meta_vers(sess, opt_vers);
let dep_hashes = cstore::get_dep_hashes(sess.cstore);
let extras_hash =
crate_meta_extras_hash(symbol_hasher, cmh_items,
dep_hashes);
dep_hashes, opt_pkg_id);

LinkMeta {
name: name,
vers: vers,
package_id: opt_pkg_id,
extras_hash: extras_hash
}
}
Expand Down Expand Up @@ -942,6 +952,11 @@ pub fn link_args(sess: Session,
args.push(~"-L" + path.to_str());
}

let rustpath = filesearch::rust_path();
for path in rustpath.iter() {
args.push(~"-L" + path.to_str());
}

// The names of the extern libraries
let used_libs = cstore::get_used_libraries(cstore);
for l in used_libs.iter() { args.push(~"-l" + *l); }
Expand Down
126 changes: 13 additions & 113 deletions src/librustc/back/rpath.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,10 +14,7 @@ use metadata::cstore;
use metadata::filesearch;

use std::hashmap::HashSet;
use std::num;
use std::os;
use std::util;
use std::vec;
use std::{num, os, path, uint, util, vec};

fn not_win32(os: session::os) -> bool {
os != session::os_win32
Expand Down Expand Up @@ -122,42 +119,7 @@ pub fn get_rpath_relative_to_output(os: session::os,
session::os_win32 => util::unreachable()
};

Path(prefix).push_rel(&get_relative_to(&os::make_absolute(output),
&os::make_absolute(lib)))
}

// Find the relative path from one file to another
pub fn get_relative_to(abs1: &Path, abs2: &Path) -> Path {
assert!(abs1.is_absolute);
assert!(abs2.is_absolute);
let abs1 = abs1.normalize();
let abs2 = abs2.normalize();
debug!("finding relative path from %s to %s",
abs1.to_str(), abs2.to_str());
let split1: &[~str] = abs1.components;
let split2: &[~str] = abs2.components;
let len1 = split1.len();
let len2 = split2.len();
assert!(len1 > 0);
assert!(len2 > 0);

let max_common_path = num::min(len1, len2) - 1;
let mut start_idx = 0;
while start_idx < max_common_path
&& split1[start_idx] == split2[start_idx] {
start_idx += 1;
}

let mut path = ~[];
for _ in range(start_idx, len1 - 1) { path.push(~".."); };
path.push_all(split2.slice(start_idx, len2 - 1));
return if !path.is_empty() {
Path("").push_many(path)
} else {
Path(".")
}
Path(prefix).push_rel(&os::make_absolute(output).get_relative_to(&os::make_absolute(lib)))
}

fn get_absolute_rpaths(libs: &[Path]) -> ~[Path] {
Expand All @@ -168,6 +130,7 @@ pub fn get_absolute_rpath(lib: &Path) -> Path {
os::make_absolute(lib).dir_path()
}

#[cfg(stage0)]
pub fn get_install_prefix_rpath(target_triple: &str) -> Path {
let install_prefix = env!("CFG_PREFIX");

Expand All @@ -179,6 +142,14 @@ pub fn get_install_prefix_rpath(target_triple: &str) -> Path {
os::make_absolute(&Path(install_prefix).push_rel(&tlib))
}

#[cfg(not(stage0))]
pub fn get_install_prefix_rpath(target_triple: &str) -> Path {
let install_prefix = env!("CFG_PREFIX");

let tlib = filesearch::relative_target_lib_path(target_triple);
os::make_absolute(&Path(install_prefix).push_rel(&tlib))
}

pub fn minimize_rpaths(rpaths: &[Path]) -> ~[Path] {
let mut set = HashSet::new();
let mut minimized = ~[];
Expand All @@ -199,8 +170,7 @@ mod test {
#[cfg(test)]
#[cfg(test)]
use back::rpath::{get_absolute_rpath, get_install_prefix_rpath};
use back::rpath::{get_relative_to, get_rpath_relative_to_output};
use back::rpath::{minimize_rpaths, rpaths_to_flags};
use back::rpath::{minimize_rpaths, rpaths_to_flags, get_rpath_relative_to_output};
use driver::session;

#[test]
Expand Down Expand Up @@ -244,78 +214,9 @@ mod test {
assert_eq!(res, ~[Path("1a"), Path("2"), Path("4a"), Path("3")]);
}
#[test]
fn test_relative_to1() {
let p1 = Path("/usr/bin/rustc");
let p2 = Path("/usr/lib/mylib");
let res = get_relative_to(&p1, &p2);
assert_eq!(res, Path("../lib"));
}
#[test]
fn test_relative_to2() {
let p1 = Path("/usr/bin/rustc");
let p2 = Path("/usr/bin/../lib/mylib");
let res = get_relative_to(&p1, &p2);
assert_eq!(res, Path("../lib"));
}
#[test]
fn test_relative_to3() {
let p1 = Path("/usr/bin/whatever/rustc");
let p2 = Path("/usr/lib/whatever/mylib");
let res = get_relative_to(&p1, &p2);
assert_eq!(res, Path("../../lib/whatever"));
}
#[test]
fn test_relative_to4() {
let p1 = Path("/usr/bin/whatever/../rustc");
let p2 = Path("/usr/lib/whatever/mylib");
let res = get_relative_to(&p1, &p2);
assert_eq!(res, Path("../lib/whatever"));
}
#[test]
fn test_relative_to5() {
let p1 = Path("/usr/bin/whatever/../rustc");
let p2 = Path("/usr/lib/whatever/../mylib");
let res = get_relative_to(&p1, &p2);
assert_eq!(res, Path("../lib"));
}
#[test]
fn test_relative_to6() {
let p1 = Path("/1");
let p2 = Path("/2/3");
let res = get_relative_to(&p1, &p2);
assert_eq!(res, Path("2"));
}
#[test]
fn test_relative_to7() {
let p1 = Path("/1/2");
let p2 = Path("/3");
let res = get_relative_to(&p1, &p2);
assert_eq!(res, Path(".."));
}
#[test]
fn test_relative_to8() {
let p1 = Path("/home/brian/Dev/rust/build/").push_rel(
&Path("stage2/lib/rustc/i686-unknown-linux-gnu/lib/librustc.so"));
let p2 = Path("/home/brian/Dev/rust/build/stage2/bin/..").push_rel(
&Path("lib/rustc/i686-unknown-linux-gnu/lib/libstd.so"));
let res = get_relative_to(&p1, &p2);
debug!("test_relative_tu8: %s vs. %s",
res.to_str(),
Path(".").to_str());
assert_eq!(res, Path("."));
}
#[test]
#[cfg(target_os = "linux")]
#[cfg(target_os = "andorid")]
#[cfg(target_os = "android")]
fn test_rpath_relative() {
let o = session::os_linux;
let res = get_rpath_relative_to_output(o,
Expand All @@ -335,7 +236,6 @@ mod test {
#[test]
#[cfg(target_os = "macos")]
fn test_rpath_relative() {
// this is why refinements would be nice
let o = session::os_macos;
let res = get_rpath_relative_to_output(o,
&Path("bin/rustc"),
Expand Down
Loading

5 comments on commit ee59aac

@bors
Copy link
Contributor

@bors bors commented on ee59aac Aug 10, 2013

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

saw approval from erickt
at erickt@ee59aac

@bors
Copy link
Contributor

@bors bors commented on ee59aac Aug 10, 2013

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

merging erickt/rust/remove-str-trailing-nulls = ee59aac into auto

@bors
Copy link
Contributor

@bors bors commented on ee59aac Aug 10, 2013

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

erickt/rust/remove-str-trailing-nulls = ee59aac merged ok, testing candidate = 60f5011

@bors
Copy link
Contributor

@bors bors commented on ee59aac Aug 10, 2013

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

fast-forwarding master to auto = 60f5011

Please sign in to comment.