Skip to content

Commit 94e3606

Browse files
committed
Fix target detection for cdylib.
Adapted from rust-lang#186, thanks @smbolton.
1 parent 6eebab6 commit 94e3606

File tree

18 files changed

+76
-14
lines changed

18 files changed

+76
-14
lines changed

rust/cargo_config.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -238,7 +238,7 @@ def items_target(self):
238238
# AFAIK, when there are multiple "kind" values, this only happens
239239
# when there are multiple library kinds.
240240
kind = target['kind'][0]
241-
if kind in ('lib', 'rlib', 'dylib', 'staticlib', 'proc-macro'):
241+
if kind in ('lib', 'rlib', 'dylib', 'cdylib', 'staticlib', 'proc-macro'):
242242
kinds.setdefault('lib', []).append(('Lib', '--lib'))
243243
elif kind in ('bin', 'test', 'example', 'bench'):
244244
text = '%s: %s' % (kind.capitalize(), target['name'])
@@ -915,7 +915,7 @@ def get_cargo_metadata(window, cwd):
915915
- kind: List of kinds. May contain multiple entries if
916916
`crate-type` specifies multiple values in Cargo.toml.
917917
Lots of different types of values:
918-
- Libraries: 'lib', 'rlib', 'dylib', 'staticlib',
918+
- Libraries: 'lib', 'rlib', 'dylib', 'cdylib', 'staticlib',
919919
'proc-macro'
920920
- Executables: 'bin', 'test', 'example', 'bench'
921921
- build.rs: 'custom-build'

rust/target_detect.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -92,16 +92,16 @@ def _target_to_args(self, target):
9292
# generally you only use one command-line argument to build multiple
9393
# "kinds" (--lib in this case).
9494
#
95-
# Nightly beware: [[example]] that specifies crate-type will no
96-
# longer show up as "example", making it impossible to compile.
95+
# Caution: [[example]] that specifies crate-type had issues before
96+
# 1.17.
9797
# See https://github.com/rust-lang/cargo/pull/3556 and
9898
# https://github.com/rust-lang/cargo/issues/3572
9999
# https://github.com/rust-lang/cargo/pull/3668 (ISSUE FIXED)
100100
#
101101
# For now, just grab the first kind since it will always result in the
102102
# same arguments.
103103
kind = target['kind'][0]
104-
if kind in ('lib', 'rlib', 'dylib', 'staticlib', 'proc-macro'):
104+
if kind in ('lib', 'rlib', 'dylib', 'cdylib', 'staticlib', 'proc-macro'):
105105
return (target['src_path'], ['--lib'])
106106
elif kind in ('bin', 'test', 'example', 'bench'):
107107
return (target['src_path'], ['--' + kind, target['name']])

tests/multi-targets/Cargo.toml

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -52,3 +52,9 @@ name = "exlib"
5252
path = "examples/exlib.rs"
5353
crate-type = ["dylib"]
5454
test = false
55+
56+
[[example]]
57+
name = "excdylib"
58+
path = "examples/excdylib.rs"
59+
crate-type = ["cdylib"]
60+
test = false
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
pub fn somefunc() {
2+
println!("somefunc");
3+
}

tests/multi-targets/libs/cdylib/Cargo.lock

Lines changed: 4 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
[package]
2+
name = "cdylib"
3+
version = "0.1.0"
4+
5+
[lib]
6+
crate-type = ["cdylib"]
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
fn f() {
2+
}

tests/multi-targets/libs/dylib/Cargo.lock

Lines changed: 4 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
[package]
2+
name = "dylib"
3+
version = "0.1.0"
4+
5+
[lib]
6+
crate-type = ["dylib"]
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
fn f() {
2+
}

0 commit comments

Comments
 (0)