-
Notifications
You must be signed in to change notification settings - Fork 2.5k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Support per-pkg-target
for -Zbuild-std
, take two
#11969
base: master
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -227,3 +227,50 @@ fn custom_test_framework() { | |
.build_std_arg("core") | ||
.run(); | ||
} | ||
|
||
/// like cross-custom but uses per-package-target instead | ||
#[cargo_test(build_std_real)] | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Can you say why this needs to be a real build-std test? I would prefer to avoid those if possible. The mock tests should be able to use |
||
fn per_package_target() { | ||
let p = project() | ||
.file( | ||
"Cargo.toml", | ||
r#" | ||
cargo-features = ["per-package-target"] | ||
[package] | ||
name = "foo" | ||
version = "0.1.0" | ||
edition = "2018" | ||
default-target = "custom-target.json" | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I don't think this is testing this target. Because build-std requires --target to be specified, the default target is never used. I might suggest using |
||
# [target.custom-target.dependencies] <-- not sure why this doesn't work | ||
[dependencies] | ||
dep = { path = "dep" } | ||
"#, | ||
) | ||
.file( | ||
"src/lib.rs", | ||
"#![no_std] pub fn f() -> u32 { dep::answer() }", | ||
) | ||
.file("dep/Cargo.toml", &basic_manifest("dep", "0.1.0")) | ||
.file("dep/src/lib.rs", "#![no_std] pub fn answer() -> u32 { 42 }") | ||
.file( | ||
"custom-target.json", | ||
r#" | ||
{ | ||
"llvm-target": "x86_64-unknown-none-gnu", | ||
"data-layout": "e-m:e-i64:64-f80:128-n8:16:32:64-S128", | ||
"arch": "x86_64", | ||
"target-endian": "little", | ||
"target-pointer-width": "64", | ||
"target-c-int-width": "32", | ||
"os": "none", | ||
"linker-flavor": "ld.lld" | ||
} | ||
"#, | ||
) | ||
.build(); | ||
|
||
p.cargo("build -v") | ||
.build_std_arg("core") | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Preferably this would contain a |
||
.target_host() | ||
.run(); | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,10 +1,15 @@ | ||
#![feature(staged_api)] | ||
#![stable(since = "1.0.0", feature = "dummy")] | ||
|
||
|
||
extern crate proc_macro; | ||
|
||
// Don't re-export everything in the root so that the mock std can be distinguished from the real one. | ||
#[stable(since = "1.0.0", feature = "dummy")] | ||
pub use proc_macro::*; | ||
pub mod exported { | ||
#[stable(since = "1.0.0", feature = "dummy")] | ||
pub use proc_macro::*; | ||
} | ||
Comment on lines
+7
to
+12
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Can you clarify why this is needed? In general, I'm not seeing the connection with proc-macro changes and support for per-pkg-target. |
||
|
||
#[stable(since = "1.0.0", feature = "dummy")] | ||
pub fn custom_api() { | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -366,16 +366,113 @@ fn target_proc_macro() { | |
"src/lib.rs", | ||
r#" | ||
extern crate proc_macro; | ||
pub fn f() { | ||
fn f() { | ||
let _ts = proc_macro::TokenStream::new(); | ||
} | ||
"#, | ||
) | ||
.file( | ||
"Cargo.toml", | ||
r#" | ||
[package] | ||
name = "pm" | ||
version = "0.1.0" | ||
[lib] | ||
proc-macro = true | ||
"#, | ||
) | ||
Comment on lines
+374
to
+383
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Can you say why this was added? |
||
.build(); | ||
|
||
p.cargo("build -v").build_std(&setup).target_host().run(); | ||
} | ||
|
||
// We already have `basic` which uses `proc_macro::custom_api()`. This case attempts to use | ||
// `TokenStream` which would error because we are using the sysroot version. | ||
#[cargo_test(build_std_mock)] | ||
fn non_proc_macro_crate_uses_non_sysroot_proc_macro() { | ||
let setup = setup(); | ||
|
||
let p = project() | ||
.file( | ||
"src/lib.rs", | ||
r#" | ||
extern crate proc_macro; | ||
fn f() { | ||
let _ts = proc_macro::TokenStream::new(); | ||
} | ||
"#, | ||
) | ||
.file( | ||
"Cargo.toml", | ||
r#" | ||
[package] | ||
name = "pm" | ||
version = "0.1.0" | ||
"#, | ||
) | ||
.build(); | ||
|
||
p.cargo("build -v") | ||
.build_std(&setup) | ||
.target_host() | ||
.run_expect_error(); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This should use Also, similar to the other questions, I'm not clear why this should fail. What's wrong with having a library access the proc_macro crate? |
||
} | ||
|
||
#[cargo_test(build_std_mock)] | ||
fn intergrated_proc_macro() { | ||
let setup = setup(); | ||
|
||
let p = project() | ||
.file( | ||
"src/main.rs", | ||
r#" | ||
fn main() { | ||
println!("The answer is {}", pm::m!()); | ||
} | ||
"#, | ||
) | ||
.file( | ||
"pm/src/lib.rs", | ||
r#" | ||
extern crate proc_macro; | ||
use proc_macro::TokenStream; | ||
#[proc_macro] | ||
pub fn m(_item: TokenStream) -> TokenStream { | ||
"42".parse().unwrap() | ||
} | ||
"#, | ||
) | ||
.file( | ||
"Cargo.toml", | ||
r#" | ||
[package] | ||
name = "foo" | ||
version = "0.1.0" | ||
[workspace] | ||
members = ["pm"] | ||
[dependencies] | ||
pm = { path = "./pm" } | ||
"#, | ||
) | ||
.file( | ||
"pm/Cargo.toml", | ||
r#" | ||
[package] | ||
name = "pm" | ||
version = "0.1.0" | ||
[lib] | ||
proc-macro = true | ||
"#, | ||
) | ||
.build(); | ||
|
||
p.cargo("run -v") | ||
.build_std(&setup) | ||
.with_stdout_contains("The answer is 42") | ||
.target_host() | ||
.run(); | ||
} | ||
|
||
#[cargo_test(build_std_mock)] | ||
fn bench() { | ||
let setup = setup(); | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There's a comment that looks like it needs to be updated here due to the removal of
explicit_host_kinds
.