Skip to content

Commit af3300a

Browse files
committed
---
yaml --- r: 3368 b: refs/heads/master c: ac081c3 h: refs/heads/master v: v3
1 parent fda2127 commit af3300a

File tree

12 files changed

+77
-32
lines changed

12 files changed

+77
-32
lines changed

[refs]

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,2 @@
11
---
2-
refs/heads/master: 8fc51dfc6524d0a4e8ddd80a567b266792170ff0
2+
refs/heads/master: ac081c30be77ca95f195b9f984c47f7735edc7e0

trunk/src/comp/driver/rustc.rs

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -273,7 +273,7 @@ fn build_session(@session::options sopts) -> session::session {
273273
auto target_crate_num = 0;
274274
auto sess =
275275
session::session(target_crate_num, target_cfg, sopts, crate_cache, [],
276-
front::codemap::new_codemap(), 0u);
276+
[], front::codemap::new_codemap(), 0u);
277277
ret sess;
278278
}
279279

@@ -419,12 +419,19 @@ fn main(vec[str] args) {
419419
}
420420
}
421421

422-
gcc_args += sess.get_used_libraries();
422+
gcc_args += sess.get_used_crate_files();
423+
424+
auto used_libs = sess.get_used_libraries();
425+
for (str l in used_libs) {
426+
gcc_args += ["-l" + l];
427+
}
423428

424429
if (sopts.shared) {
425430
gcc_args += [shared_cmd];
426431
} else {
427-
gcc_args += ["-Lrustllvm", "-lrustllvm", "-lm", main];
432+
// FIXME: having -Lrustllvm hardcoded in here is hack
433+
// FIXME: same for -lm
434+
gcc_args += ["-Lrustllvm", "-lm", main];
428435
}
429436
// We run 'gcc' here
430437

trunk/src/comp/driver/session.rs

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -66,6 +66,7 @@ obj session(ast::crate_num cnum,
6666
@config targ_cfg,
6767
@options opts,
6868
map::hashmap[int, crate_metadata] crates,
69+
mutable vec[str] used_crate_files,
6970
mutable vec[str] used_libraries,
7071
codemap::codemap cm,
7172
mutable uint err_count) {
@@ -136,6 +137,19 @@ obj session(ast::crate_num cnum,
136137
fn get_used_libraries() -> vec[str] {
137138
ret used_libraries;
138139
}
140+
fn add_used_crate_file(&str lib) {
141+
// A program has a small number of crates, so a vector is probably
142+
// a good data structure in here.
143+
for (str l in used_crate_files) {
144+
if (l == lib) {
145+
ret;
146+
}
147+
}
148+
used_crate_files += [lib];
149+
}
150+
fn get_used_crate_files() -> vec[str] {
151+
ret used_crate_files;
152+
}
139153
fn get_codemap() -> codemap::codemap { ret cm; }
140154
fn lookup_pos(uint pos) -> codemap::loc {
141155
ret codemap::lookup_pos(cm, pos);

trunk/src/comp/front/creader.rs

Lines changed: 39 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -590,6 +590,15 @@ fn metadata_matches(hashmap[str, str] mm, &vec[@ast::meta_item] metas) ->
590590
ret true;
591591
}
592592

593+
fn default_native_lib_naming(session::session sess) ->
594+
rec(str prefix, str suffix) {
595+
alt (sess.get_targ_cfg().os) {
596+
case (session::os_win32) { ret rec(prefix="", suffix=".dll"); }
597+
case (session::os_macos) { ret rec(prefix="lib", suffix=".dylib"); }
598+
case (session::os_linux) { ret rec(prefix="lib", suffix=".so"); }
599+
}
600+
}
601+
593602
fn find_library_crate(&session::session sess, &ast::ident ident,
594603
&vec[@ast::meta_item] metas,
595604
&vec[str] library_search_paths) ->
@@ -609,7 +618,7 @@ fn find_library_crate(&session::session sess, &ast::ident ident,
609618
}
610619
}
611620
}
612-
auto nn = parser::default_native_lib_naming(sess);
621+
auto nn = default_native_lib_naming(sess);
613622
let str prefix = nn.prefix + crate_name;
614623
// FIXME: we could probably use a 'glob' function in std::fs but it will
615624
// be much easier to write once the unsafe module knows more about FFI
@@ -649,7 +658,7 @@ fn load_library_crate(&session::session sess, int cnum, &ast::ident ident,
649658
alt (find_library_crate(sess, ident, metas, library_search_paths)) {
650659
case (some(?t)) {
651660
sess.set_external_crate(cnum, rec(name=ident, data=t._1));
652-
sess.add_used_library(t._0);
661+
sess.add_used_crate_file(t._0);
653662
ret;
654663
}
655664
case (_) { }
@@ -682,6 +691,32 @@ fn visit_view_item(env e, &@ast::view_item i) {
682691
}
683692
}
684693

694+
fn visit_item(env e, &@ast::item i) {
695+
alt (i.node) {
696+
case (ast::item_native_mod(?m)) {
697+
auto name;
698+
if (m.native_name == "" ) {
699+
name = i.ident;
700+
} else {
701+
name = m.native_name;
702+
}
703+
alt (m.abi) {
704+
case (ast::native_abi_rust) {
705+
e.sess.add_used_library(name);
706+
}
707+
case (ast::native_abi_cdecl) {
708+
e.sess.add_used_library(name);
709+
}
710+
case (ast::native_abi_llvm) {
711+
}
712+
case (ast::native_abi_rust_intrinsic) {
713+
}
714+
}
715+
}
716+
case (_) {
717+
}
718+
}
719+
}
685720

686721
// Reads external crates referenced by "use" directives.
687722
fn read_crates(session::session sess, resolve::crate_map crate_map,
@@ -693,7 +728,8 @@ fn read_crates(session::session sess, resolve::crate_map crate_map,
693728
library_search_paths=sess.get_opts().library_search_paths,
694729
mutable next_crate_num=1);
695730
auto v =
696-
rec(visit_view_item_pre=bind visit_view_item(e, _)
731+
rec(visit_view_item_pre=bind visit_view_item(e, _),
732+
visit_item_pre=bind visit_item(e, _)
697733
with walk::default_visitor());
698734
walk::walk_crate(v, crate);
699735
}

trunk/src/comp/front/parser.rs

Lines changed: 3 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1899,20 +1899,6 @@ fn parse_native_mod_items(&parser p, &str native_name, ast::native_abi abi) ->
18991899
items=items);
19001900
}
19011901

1902-
fn default_native_lib_naming(session::session sess) ->
1903-
rec(str prefix, str suffix) {
1904-
alt (sess.get_targ_cfg().os) {
1905-
case (session::os_win32) { ret rec(prefix="", suffix=".dll"); }
1906-
case (session::os_macos) { ret rec(prefix="lib", suffix=".dylib"); }
1907-
case (session::os_linux) { ret rec(prefix="lib", suffix=".so"); }
1908-
}
1909-
}
1910-
1911-
fn default_native_name(session::session sess, str id) -> str {
1912-
auto n = default_native_lib_naming(sess);
1913-
ret n.prefix + id + n.suffix;
1914-
}
1915-
19161902
fn parse_item_native_mod(&parser p, vec[ast::attribute] attrs) -> @ast::item {
19171903
auto lo = p.get_last_lo_pos();
19181904
auto abi = ast::native_abi_cdecl;
@@ -1933,7 +1919,9 @@ fn parse_item_native_mod(&parser p, vec[ast::attribute] attrs) -> @ast::item {
19331919
if (p.peek() == token::EQ) {
19341920
expect(p, token::EQ);
19351921
native_name = parse_str(p);
1936-
} else { native_name = default_native_name(p.get_session(), id); }
1922+
} else {
1923+
native_name = "";
1924+
}
19371925
expect(p, token::LBRACE);
19381926
auto m = parse_native_mod_items(p, native_name, abi);
19391927
auto hi = p.get_hi_pos();

trunk/src/lib/linux_os.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ import vec::vbuf;
55

66
// FIXME Somehow merge stuff duplicated here and macosx_os.rs. Made difficult
77
// by https://github.com/graydon/rust/issues#issue/268
8-
native "cdecl" mod libc {
8+
native "cdecl" mod libc = "c" {
99
fn open(sbuf s, int flags, uint mode) -> int;
1010
fn read(int fd, vbuf buf, uint count) -> int;
1111
fn write(int fd, vbuf buf, uint count) -> int;

trunk/src/lib/macos_os.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
import str::sbuf;
33
import vec::vbuf;
44

5-
native "cdecl" mod libc {
5+
native "cdecl" mod libc = "c" {
66
fn open(sbuf s, int flags, uint mode) -> int;
77
fn read(int fd, vbuf buf, uint count) -> int;
88
fn write(int fd, vbuf buf, uint count) -> int;

trunk/src/lib/win32_os.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
import str::sbuf;
33
import vec::vbuf;
44

5-
native "cdecl" mod libc {
5+
native "cdecl" mod libc = "c" {
66
fn open(sbuf s, int flags, uint mode) -> int = "_open";
77
fn read(int fd, vbuf buf, uint count) -> int = "_read";
88
fn write(int fd, vbuf buf, uint count) -> int = "_write";

trunk/src/test/run-pass/binops.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -112,7 +112,7 @@ fn test_fn() {
112112
assert (h1 >= h2);
113113
}
114114

115-
native "rust" mod native_mod {
115+
native "rust" mod native_mod = "c" {
116116
fn str_byte_len(str s) -> vec[u8];
117117
fn str_alloc(uint n_bytes) -> str;
118118
}

trunk/src/test/run-pass/import-glob-1.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ mod a1 { //
1212
} // | | |
1313
// | | |
1414
mod a2 { // | | |
15-
native mod b1 { // | | |
15+
native mod b1 = "c" { // | | |
1616
import a1::b2::*; // | <-/ -/
1717
export word_traveler; // |
1818
} // |

trunk/src/test/run-pass/native-opaque-type.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11

22

3-
native "cdecl" mod libc {
3+
native "cdecl" mod libc = "c" {
44
type file_handle;
55
}
66

trunk/src/test/run-pass/native2.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5,14 +5,14 @@ native "rust" mod rustrt {
55
fn vec_buf[T](vec[T] v, uint offset) -> vbuf;
66
}
77

8-
native "rust" mod bar { }
8+
native "rust" mod bar = "c" { }
99

10-
native "cdecl" mod zed { }
10+
native "cdecl" mod zed = "c" { }
1111

12-
native "cdecl" mod libc {
12+
native "cdecl" mod libc = "c" {
1313
fn write(int fd, rustrt::vbuf buf, uint count) -> int;
1414
}
1515

16-
native "cdecl" mod baz { }
16+
native "cdecl" mod baz = "c" { }
1717

1818
fn main(vec[str] args) { }

0 commit comments

Comments
 (0)