From 6814c20332fe78d10f2407c88067614401215656 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?John=20K=C3=A5re=20Alsaker?= Date: Sat, 12 Jan 2019 05:16:34 +0100 Subject: [PATCH 1/2] Add an unstable option to build proc macros for both the host and the target --- .../core/compiler/context/unit_dependencies.rs | 15 +++++++++++++-- src/cargo/core/features.rs | 2 ++ src/cargo/core/manifest.rs | 10 ++++++++++ src/cargo/util/toml/targets.rs | 1 + 4 files changed, 26 insertions(+), 2 deletions(-) diff --git a/src/cargo/core/compiler/context/unit_dependencies.rs b/src/cargo/core/compiler/context/unit_dependencies.rs index b101e944360..f9eb4df9a3e 100644 --- a/src/cargo/core/compiler/context/unit_dependencies.rs +++ b/src/cargo/core/compiler/context/unit_dependencies.rs @@ -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 diff --git a/src/cargo/core/features.rs b/src/cargo/core/features.rs index 6a90413391f..7a93f8757d2 100644 --- a/src/cargo/core/features.rs +++ b/src/cargo/core/features.rs @@ -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, } @@ -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), } diff --git a/src/cargo/core/manifest.rs b/src/cargo/core/manifest.rs index 55ee9e6a16d..b7f573a9862 100644 --- a/src/cargo/core/manifest.rs +++ b/src/cargo/core/manifest.rs @@ -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, } @@ -352,6 +353,7 @@ compact_debug! { doctest harness for_host + proc_macro edition )] } @@ -585,6 +587,7 @@ impl Target { doctest: false, harness: true, for_host: false, + proc_macro: false, edition, tested: true, benched: true, @@ -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 } @@ -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 diff --git a/src/cargo/util/toml/targets.rs b/src/cargo/util/toml/targets.rs index 88bf2d6d873..773b6ffdb32 100644 --- a/src/cargo/util/toml/targets.rs +++ b/src/cargo/util/toml/targets.rs @@ -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, From 2a95bd0bd6dfa5753aa27d8028ab974d99f3d862 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?John=20K=C3=A5re=20Alsaker?= Date: Mon, 28 Jan 2019 21:17:06 +0100 Subject: [PATCH 2/2] Fix output calculation --- src/cargo/core/compiler/context/compilation_files.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/cargo/core/compiler/context/compilation_files.rs b/src/cargo/core/compiler/context/compilation_files.rs index 206d0d4f17d..a5cfb1b29d2 100644 --- a/src/cargo/core/compiler/context/compilation_files.rs +++ b/src/cargo/core/compiler/context/compilation_files.rs @@ -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