Skip to content

Commit

Permalink
Add "features" argument to rust components
Browse files Browse the repository at this point in the history
  • Loading branch information
piscisaureus authored and ry committed Jul 29, 2018
1 parent 4d386e9 commit 37a4606
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 11 deletions.
8 changes: 4 additions & 4 deletions build_extra/rust/BUILD.gn
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ crates = "//third_party/rust_crates"
rust_component("libc") {
source_root =
"$crates/registry/src/github.com-1ecc6299db9ec823/libc-0.2.42/src/lib.rs"
cfg = [ "feature=\"use_std\"" ]
features = [ "use_std" ]
}

rust_component("url") {
Expand Down Expand Up @@ -91,9 +91,9 @@ rust_component("rand") {
":libc",
":rand_core",
]
cfg = [
"feature=\"std\"",
"feature=\"alloc\"",
features = [
"std",
"alloc",
]
if (is_mac) {
libs = [ "Security.framework" ]
Expand Down
26 changes: 19 additions & 7 deletions build_extra/rust/rust.gni
Original file line number Diff line number Diff line change
Expand Up @@ -43,10 +43,11 @@ template("run_rustc") {
"cfg",
"crate_name",
"crate_type",
"source_root",
"deps",
"extern",
"features",
"is_test",
"source_root",
"testonly",
])
if (!defined(crate_name)) {
Expand Down Expand Up @@ -119,6 +120,15 @@ template("run_rustc") {
}
}

if (defined(features)) {
foreach(f, features) {
args += [
"--cfg",
"feature=\"" + f + "\"",
]
}
}

if (defined(invoker.args)) {
args += invoker.args
}
Expand Down Expand Up @@ -155,15 +165,16 @@ template("rust_component") {
run_rustc(rustc_name) {
forward_variables_from(invoker,
[
"args",
"cfg",
"crate_name",
"crate_type",
"deps",
"extern",
"cfg",
"source_root",
"features",
"is_test",
"source_root",
"testonly",
"args",
"deps",
])
if (!defined(invoker.crate_type)) {
crate_type = "rlib"
Expand All @@ -176,8 +187,8 @@ template("rust_component") {
component(target_name) {
forward_variables_from(invoker,
[
"libs",
"deps",
"libs",
"testonly",
])
if (!defined(deps)) {
Expand All @@ -195,9 +206,10 @@ template("rust_staticlib") {
rust_component(target_name) {
forward_variables_from(invoker,
[
"cfg",
"crate_name",
"extern",
"cfg",
"features",
"source_root",
"testonly",
])
Expand Down

0 comments on commit 37a4606

Please sign in to comment.