Skip to content

Commit 7fd9c73

Browse files
committed
Auto merge of #6547 - Zoxc:dual-proc-macros, r=alexcrichton
Add an unstable option to build proc macros for both the host and the target r? @alexcrichton
2 parents 55895e7 + 2a95bd0 commit 7fd9c73

File tree

5 files changed

+27
-3
lines changed

5 files changed

+27
-3
lines changed

src/cargo/core/compiler/context/compilation_files.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -276,7 +276,7 @@ impl<'a, 'cfg: 'a> CompilationFiles<'a, 'cfg> {
276276
let out_dir = self.out_dir(unit);
277277
let file_stem = self.file_stem(unit);
278278
let link_stem = self.link_stem(unit);
279-
let info = if unit.target.for_host() {
279+
let info = if unit.kind == Kind::Host {
280280
&bcx.host_info
281281
} else {
282282
&bcx.target_info

src/cargo/core/compiler/context/unit_dependencies.rs

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -180,8 +180,19 @@ fn compute_deps<'a, 'cfg, 'tmp>(
180180
};
181181
let mode = check_or_build_mode(unit.mode, lib);
182182
let dep_unit_for = unit_for.with_for_host(lib.for_host());
183-
let unit = new_unit(bcx, pkg, lib, dep_unit_for, unit.kind.for_target(lib), mode);
184-
ret.push((unit, dep_unit_for));
183+
184+
if bcx.config.cli_unstable().dual_proc_macros
185+
&& lib.proc_macro()
186+
&& unit.kind == Kind::Target
187+
{
188+
let unit = new_unit(bcx, pkg, lib, dep_unit_for, Kind::Target, mode);
189+
ret.push((unit, dep_unit_for));
190+
let unit = new_unit(bcx, pkg, lib, dep_unit_for, Kind::Host, mode);
191+
ret.push((unit, dep_unit_for));
192+
} else {
193+
let unit = new_unit(bcx, pkg, lib, dep_unit_for, unit.kind.for_target(lib), mode);
194+
ret.push((unit, dep_unit_for));
195+
}
185196
}
186197

187198
// If this target is a build script, then what we've collected so far is

src/cargo/core/features.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -320,6 +320,7 @@ pub struct CliUnstable {
320320
pub package_features: bool,
321321
pub advanced_env: bool,
322322
pub config_profile: bool,
323+
pub dual_proc_macros: bool,
323324
pub mtime_on_use: bool,
324325
}
325326

@@ -357,6 +358,7 @@ impl CliUnstable {
357358
"package-features" => self.package_features = true,
358359
"advanced-env" => self.advanced_env = true,
359360
"config-profile" => self.config_profile = true,
361+
"dual-proc-macros" => self.dual_proc_macros = true,
360362
"mtime-on-use" => self.mtime_on_use = true,
361363
_ => failure::bail!("unknown `-Z` flag specified: {}", k),
362364
}

src/cargo/core/manifest.rs

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -212,6 +212,7 @@ pub struct Target {
212212
doctest: bool,
213213
harness: bool, // whether to use the test harness (--test)
214214
for_host: bool,
215+
proc_macro: bool,
215216
edition: Edition,
216217
}
217218

@@ -352,6 +353,7 @@ compact_debug! {
352353
doctest
353354
harness
354355
for_host
356+
proc_macro
355357
edition
356358
)]
357359
}
@@ -585,6 +587,7 @@ impl Target {
585587
doctest: false,
586588
harness: true,
587589
for_host: false,
590+
proc_macro: false,
588591
edition,
589592
tested: true,
590593
benched: true,
@@ -735,6 +738,9 @@ impl Target {
735738
pub fn for_host(&self) -> bool {
736739
self.for_host
737740
}
741+
pub fn proc_macro(&self) -> bool {
742+
self.proc_macro
743+
}
738744
pub fn edition(&self) -> Edition {
739745
self.edition
740746
}
@@ -860,6 +866,10 @@ impl Target {
860866
self.for_host = for_host;
861867
self
862868
}
869+
pub fn set_proc_macro(&mut self, proc_macro: bool) -> &mut Target {
870+
self.proc_macro = proc_macro;
871+
self
872+
}
863873
pub fn set_edition(&mut self, edition: Edition) -> &mut Target {
864874
self.edition = edition;
865875
self

src/cargo/util/toml/targets.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -764,6 +764,7 @@ fn configure(features: &Features, toml: &TomlTarget, target: &mut Target) -> Car
764764
.set_doctest(toml.doctest.unwrap_or_else(|| t2.doctested()))
765765
.set_benched(toml.bench.unwrap_or_else(|| t2.benched()))
766766
.set_harness(toml.harness.unwrap_or_else(|| t2.harness()))
767+
.set_proc_macro(toml.proc_macro.unwrap_or_else(|| t2.proc_macro()))
767768
.set_for_host(match (toml.plugin, toml.proc_macro()) {
768769
(None, None) => t2.for_host(),
769770
(Some(true), _) | (_, Some(true)) => true,

0 commit comments

Comments
 (0)