Skip to content

Commit

Permalink
Auto merge of #6547 - Zoxc:dual-proc-macros, r=alexcrichton
Browse files Browse the repository at this point in the history
Add an unstable option to build proc macros for both the host and the target

r? @alexcrichton
  • Loading branch information
bors committed Feb 19, 2019
2 parents 55895e7 + 2a95bd0 commit 7fd9c73
Show file tree
Hide file tree
Showing 5 changed files with 27 additions and 3 deletions.
2 changes: 1 addition & 1 deletion src/cargo/core/compiler/context/compilation_files.rs
Original file line number Diff line number Diff line change
Expand Up @@ -276,7 +276,7 @@ impl<'a, 'cfg: 'a> CompilationFiles<'a, 'cfg> {
let out_dir = self.out_dir(unit);
let file_stem = self.file_stem(unit);
let link_stem = self.link_stem(unit);
let info = if unit.target.for_host() {
let info = if unit.kind == Kind::Host {
&bcx.host_info
} else {
&bcx.target_info
Expand Down
15 changes: 13 additions & 2 deletions src/cargo/core/compiler/context/unit_dependencies.rs
Original file line number Diff line number Diff line change
Expand Up @@ -180,8 +180,19 @@ fn compute_deps<'a, 'cfg, 'tmp>(
};
let mode = check_or_build_mode(unit.mode, lib);
let dep_unit_for = unit_for.with_for_host(lib.for_host());
let unit = new_unit(bcx, pkg, lib, dep_unit_for, unit.kind.for_target(lib), mode);
ret.push((unit, dep_unit_for));

if bcx.config.cli_unstable().dual_proc_macros
&& lib.proc_macro()
&& unit.kind == Kind::Target
{
let unit = new_unit(bcx, pkg, lib, dep_unit_for, Kind::Target, mode);
ret.push((unit, dep_unit_for));
let unit = new_unit(bcx, pkg, lib, dep_unit_for, Kind::Host, mode);
ret.push((unit, dep_unit_for));
} else {
let unit = new_unit(bcx, pkg, lib, dep_unit_for, unit.kind.for_target(lib), mode);
ret.push((unit, dep_unit_for));
}
}

// If this target is a build script, then what we've collected so far is
Expand Down
2 changes: 2 additions & 0 deletions src/cargo/core/features.rs
Original file line number Diff line number Diff line change
Expand Up @@ -320,6 +320,7 @@ pub struct CliUnstable {
pub package_features: bool,
pub advanced_env: bool,
pub config_profile: bool,
pub dual_proc_macros: bool,
pub mtime_on_use: bool,
}

Expand Down Expand Up @@ -357,6 +358,7 @@ impl CliUnstable {
"package-features" => self.package_features = true,
"advanced-env" => self.advanced_env = true,
"config-profile" => self.config_profile = true,
"dual-proc-macros" => self.dual_proc_macros = true,
"mtime-on-use" => self.mtime_on_use = true,
_ => failure::bail!("unknown `-Z` flag specified: {}", k),
}
Expand Down
10 changes: 10 additions & 0 deletions src/cargo/core/manifest.rs
Original file line number Diff line number Diff line change
Expand Up @@ -212,6 +212,7 @@ pub struct Target {
doctest: bool,
harness: bool, // whether to use the test harness (--test)
for_host: bool,
proc_macro: bool,
edition: Edition,
}

Expand Down Expand Up @@ -352,6 +353,7 @@ compact_debug! {
doctest
harness
for_host
proc_macro
edition
)]
}
Expand Down Expand Up @@ -585,6 +587,7 @@ impl Target {
doctest: false,
harness: true,
for_host: false,
proc_macro: false,
edition,
tested: true,
benched: true,
Expand Down Expand Up @@ -735,6 +738,9 @@ impl Target {
pub fn for_host(&self) -> bool {
self.for_host
}
pub fn proc_macro(&self) -> bool {
self.proc_macro
}
pub fn edition(&self) -> Edition {
self.edition
}
Expand Down Expand Up @@ -860,6 +866,10 @@ impl Target {
self.for_host = for_host;
self
}
pub fn set_proc_macro(&mut self, proc_macro: bool) -> &mut Target {
self.proc_macro = proc_macro;
self
}
pub fn set_edition(&mut self, edition: Edition) -> &mut Target {
self.edition = edition;
self
Expand Down
1 change: 1 addition & 0 deletions src/cargo/util/toml/targets.rs
Original file line number Diff line number Diff line change
Expand Up @@ -764,6 +764,7 @@ fn configure(features: &Features, toml: &TomlTarget, target: &mut Target) -> Car
.set_doctest(toml.doctest.unwrap_or_else(|| t2.doctested()))
.set_benched(toml.bench.unwrap_or_else(|| t2.benched()))
.set_harness(toml.harness.unwrap_or_else(|| t2.harness()))
.set_proc_macro(toml.proc_macro.unwrap_or_else(|| t2.proc_macro()))
.set_for_host(match (toml.plugin, toml.proc_macro()) {
(None, None) => t2.for_host(),
(Some(true), _) | (_, Some(true)) => true,
Expand Down

0 comments on commit 7fd9c73

Please sign in to comment.