Skip to content

Commit a6f5b98

Browse files
committed
rustc: Re-jigger -L and -l for MSYS compatibility
As discovered in #20376, the MSYS shell will silently rewrite arguemnts that look like unix paths into their windows path counterparts for compatibility, but the recently added `:kind` syntax added to the `-L` flag does not allow for this form of rewriting. This means that the syntax can be difficult to use at an MSYS prompt, as well as causing tests to fail when run manuall right now. This commit takes the other option presented in the original issue to prefix the path with `kind=` instead of suffixing it with `:kind`. For consistence, the `-l` flag is also now migrating to `kind=name`. This is a breaking change due to the *removal* of behavior with `-L`. All code using `:kind` should now pass `kind=` for `-L` arguments. This is not currently, but will become, a breaking change for `-l` flags. The old `name:kind` syntax is still accepted, but all code should update to `kind=name`. [breaking-change] Closes #20376
1 parent 84f5ad8 commit a6f5b98

File tree

4 files changed

+45
-28
lines changed

4 files changed

+45
-28
lines changed

src/librustc/session/config.rs

+19-1
Original file line numberDiff line numberDiff line change
@@ -743,7 +743,7 @@ pub fn rustc_short_optgroups() -> Vec<RustcOptGroup> {
743743
opt::multi("l", "", "Link the generated crate(s) to the specified native
744744
library NAME. The optional KIND can be one of,
745745
static, dylib, or framework. If omitted, dylib is
746-
assumed.", "NAME[:KIND]"),
746+
assumed.", "[KIND=]NAME"),
747747
opt::multi("", "crate-type", "Comma separated list of types of crates
748748
for the compiler to emit",
749749
"[bin|lib|rlib|dylib|staticlib]"),
@@ -1016,6 +1016,24 @@ pub fn build_session_options(matches: &getopts::Matches) -> Options {
10161016
}
10171017

10181018
let libs = matches.opt_strs("l").into_iter().map(|s| {
1019+
let mut parts = s.splitn(1, '=');
1020+
let kind = parts.next().unwrap();
1021+
if let Some(name) = parts.next() {
1022+
let kind = match kind {
1023+
"dylib" => cstore::NativeUnknown,
1024+
"framework" => cstore::NativeFramework,
1025+
"static" => cstore::NativeStatic,
1026+
s => {
1027+
early_error(format!("unknown library kind `{}`, expected \
1028+
one of dylib, framework, or static",
1029+
s)[]);
1030+
}
1031+
};
1032+
return (name.to_string(), kind)
1033+
}
1034+
1035+
// FIXME(acrichto) remove this once crates have stopped using it, this
1036+
// is deprecated behavior now.
10191037
let mut parts = s.rsplitn(1, ':');
10201038
let kind = parts.next().unwrap();
10211039
let (name, kind) = match (parts.next(), kind) {

src/librustc/session/search_paths.rs

+8-9
Original file line numberDiff line numberDiff line change
@@ -34,15 +34,14 @@ impl SearchPaths {
3434
}
3535

3636
pub fn add_path(&mut self, path: &str) {
37-
let (kind, path) = if path.ends_with(":native") {
38-
(PathKind::Native, path.slice_to(path.len() - ":native".len()))
39-
} else if path.ends_with(":crate") {
40-
(PathKind::Crate, path.slice_to(path.len() - ":crate".len()))
41-
} else if path.ends_with(":dependency") {
42-
(PathKind::Dependency,
43-
path.slice_to(path.len() - ":dependency".len()))
44-
} else if path.ends_with(":all") {
45-
(PathKind::All, path.slice_to(path.len() - ":all".len()))
37+
let (kind, path) = if path.starts_with("native=") {
38+
(PathKind::Native, path.slice_from("native=".len()))
39+
} else if path.starts_with("crate=") {
40+
(PathKind::Crate, path.slice_from("crate=".len()))
41+
} else if path.starts_with("dependency=") {
42+
(PathKind::Dependency, path.slice_from("dependency=".len()))
43+
} else if path.starts_with("all=") {
44+
(PathKind::All, path.slice_from("all=".len()))
4645
} else {
4746
(PathKind::All, path)
4847
};

src/test/run-make/compiler-lookup-paths/Makefile

+17-17
Original file line numberDiff line numberDiff line change
@@ -6,25 +6,25 @@ all: $(TMPDIR)/libnative.a
66
mv $(TMPDIR)/libnative.a $(TMPDIR)/native
77
$(RUSTC) a.rs
88
mv $(TMPDIR)/liba.rlib $(TMPDIR)/crate
9-
$(RUSTC) b.rs -L $(TMPDIR)/crate:native && exit 1 || exit 0
10-
$(RUSTC) b.rs -L $(TMPDIR)/crate:dependency && exit 1 || exit 0
11-
$(RUSTC) b.rs -L $(TMPDIR)/crate:crate
12-
$(RUSTC) b.rs -L $(TMPDIR)/crate
13-
$(RUSTC) c.rs -L $(TMPDIR)/crate:native && exit 1 || exit 0
14-
$(RUSTC) c.rs -L $(TMPDIR)/crate:crate && exit 1 || exit 0
15-
$(RUSTC) c.rs -L $(TMPDIR)/crate:dependency
16-
$(RUSTC) c.rs -L $(TMPDIR)/crate
17-
$(RUSTC) d.rs -L $(TMPDIR)/native:dependency && exit 1 || exit 0
18-
$(RUSTC) d.rs -L $(TMPDIR)/native:crate && exit 1 || exit 0
19-
$(RUSTC) d.rs -L $(TMPDIR)/native:native
20-
$(RUSTC) d.rs -L $(TMPDIR)/native
9+
$(RUSTC) b.rs -L native=$(TMPDIR)/crate && exit 1 || exit 0
10+
$(RUSTC) b.rs -L dependency=$(TMPDIR)/crate && exit 1 || exit 0
11+
$(RUSTC) b.rs -L crate=$(TMPDIR)/crate
12+
$(RUSTC) b.rs -L all=$(TMPDIR)/crate
13+
$(RUSTC) c.rs -L native=$(TMPDIR)/crate && exit 1 || exit 0
14+
$(RUSTC) c.rs -L crate=$(TMPDIR)/crate && exit 1 || exit 0
15+
$(RUSTC) c.rs -L dependency=$(TMPDIR)/crate
16+
$(RUSTC) c.rs -L all=$(TMPDIR)/crate
17+
$(RUSTC) d.rs -L dependency=$(TMPDIR)/native && exit 1 || exit 0
18+
$(RUSTC) d.rs -L crate=$(TMPDIR)/native && exit 1 || exit 0
19+
$(RUSTC) d.rs -L native=$(TMPDIR)/native
20+
$(RUSTC) d.rs -L all=$(TMPDIR)/native
2121
mkdir -p $(TMPDIR)/e1
2222
mkdir -p $(TMPDIR)/e2
2323
$(RUSTC) e.rs -o $(TMPDIR)/e1/libe.rlib
2424
$(RUSTC) e.rs -o $(TMPDIR)/e2/libe.rlib
2525
$(RUSTC) f.rs -L $(TMPDIR)/e1 -L $(TMPDIR)/e2 && exit 1 || exit 0
26-
$(RUSTC) f.rs -L $(TMPDIR)/e1:crate -L $(TMPDIR)/e2 && exit 1 || exit 0
27-
$(RUSTC) f.rs -L $(TMPDIR)/e1:crate -L $(TMPDIR)/e2:crate && exit 1 || exit 0
28-
$(RUSTC) f.rs -L $(TMPDIR)/e1:native -L $(TMPDIR)/e2
29-
$(RUSTC) f.rs -L $(TMPDIR)/e1:dependency -L $(TMPDIR)/e2
30-
$(RUSTC) f.rs -L $(TMPDIR)/e1:dependency -L $(TMPDIR)/e2:crate
26+
$(RUSTC) f.rs -L crate=$(TMPDIR)/e1 -L $(TMPDIR)/e2 && exit 1 || exit 0
27+
$(RUSTC) f.rs -L crate=$(TMPDIR)/e1 -L crate=$(TMPDIR)/e2 && exit 1 || exit 0
28+
$(RUSTC) f.rs -L native=$(TMPDIR)/e1 -L $(TMPDIR)/e2
29+
$(RUSTC) f.rs -L dependency=$(TMPDIR)/e1 -L $(TMPDIR)/e2
30+
$(RUSTC) f.rs -L dependency=$(TMPDIR)/e1 -L crate=$(TMPDIR)/e2
+1-1
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
-include ../tools.mk
22

33
all: $(TMPDIR)/libbar.a
4-
$(RUSTC) foo.rs -lbar:static
4+
$(RUSTC) foo.rs -lstatic=bar
55
$(RUSTC) main.rs
66
$(call RUN,main)
77

0 commit comments

Comments
 (0)