41 Commits

Author SHA1 Message Date
Weihang Lo
fbb5b90fe0
test(build-std): make mock-std closer to real world
`test_std_on_unsupported_target` never really succeed to build those targets, due to

* local rustup may not have `{aarch64,x86_64}-unknown-none` installed.
* `core` and `compiler-builtins` mock crate are not `no_std` nor `no_core`
* the dummy `main.rs` uses `println!` and is not `no_std`.

This commit make it compile, if you have those targets installed.
2024-12-05 10:50:51 -05:00
Weihang Lo
88edf01fe3
Check build target supports std when building with -Zbuild-std=std (#14183)
**What does this PR try to resolve?**

Ensures that Cargo first verifies whether a given target supports
building the standard library when the `-Zbuild-std=std` option is
passed to Cargo ([see issue
here](https://github.com/rust-lang/wg-cargo-std-aware/issues/87)). This
information can be obtained by querying `rustc
--print=target-spec-json`. The target spec "metadata" contains an
`Option<bool>` determining whether the target supports building std.

In the case this value is `false`, cargo will stop the build. This
avoids the numerous "use of unstable library" errors, giving a cleaner,
and simpler, "building std is not supported on this target".

**How should we test and review this PR?**

It can be manually tested by running `cargo build --target <target>
-Zbuild-std=std`. If a target who's target-spec marks std as false is
passed, cargo will exit. This works with multiple `--target`'s, and if
any of them don't support std, cargo will exit.

**Additional Information**

This change relies on two things:
* The target-spec metadata in rustc needs to be filled out. Currently,
most fields are None, which is treated as OK with this change. Meaning
this can be merged before the rustc changes.
* The new test case added with this change will fail without at least
`aarch64-unknown-none` having it's target-spec metadata completed.
* Some targets have std support marked as "?". If this state is properly
represented in the target-spec in the future, it needs to be determined
whether this is allowed, so the build can continue, or whether it fails.
2024-11-22 01:31:41 +00:00
Harry Moulton
6a980bca73 Add new test case 'test_std_on_unsupported_target'
Add a new test case to check cargo handles building a target which
doesn't support the standard library properly.
2024-11-21 14:22:58 +00:00
Ed Page
af3cfd5abe fix(test): Un-deprecate contains assertions 2024-11-07 15:55:35 -06:00
Harry Moulton
b6e1942ff2 test: mock-std test case for shared dependencies without --target req
Add a test case which ensures that -Zbuild-std without --target
correctly handles building a crate that has a shared dependency between
it's own build script, and std.
2024-09-25 10:52:58 +01:00
Ed Page
a6cf1be655 test: Switch from allow to expect deprecated
This caught a couple of lingering items.
2024-09-23 20:44:06 -05:00
Weihang Lo
50237f4049
fix: std Cargo.lock moved to library dir
rust-lang/cargo#14358 didn't check the correct Cargo.lock existence
Perhaps it was there so the test passed, but after a new nightly
is out it is gone.

```
    Blocking waiting for file lock on package cache
error: "/home/user/.rustup/toolchains/nightly-aarch64-apple-darwin/lib/rustlib/src/rust/Cargo.lock" does not exist, unable to build with the standard library, try:
        rustup component add rust-src --toolchain nightly-aarch64-apple-darwin

note: run with `RUST_BACKTRACE=1` environment variable to display a backtrace
```
2024-08-08 01:04:42 -04:00
Ed Page
5b9799c6f4 refactor: Migrate from extern crate to test-support prelude
We now include the prelude in so many places, this simplifies how we can
present how `cargo-test-support` works.

Yes, this included some `use` clean ups but its already painful enough
walking through every test file, I didn't want to do it twice.
2024-07-12 15:57:00 -05:00
eth3lbert
d025f14904
test: migrate standard_lib to snapbox 2024-06-26 10:50:41 +08:00
Ed Page
dc5ac62cab fix(test): Deprecate non-snapbox assertions
While this is noisy and hides other deprecations, I figured deprecations would
make it easier for people to discover what tasks remain and allow us to
divide and conquer this work rather than doing a heroic PR.
In theory, this will be short lived and we'll go back to seeing
deprecations in our tests.
2024-06-10 10:20:52 -05:00
Eric Huss
473e770cdd Temporarily fix standard_lib tests on linux. 2024-05-18 14:00:06 -07:00
Eric Huss
1c3640e05c Add requirements to cargo_test. 2022-07-30 19:36:58 -07:00
Scott Schafer
c239e407e7 add a reason to masquerade_as_nightly_cargo so it is searchable 2022-07-15 21:32:23 -05:00
Eric Huss
502a9c5407 Fix tests due to change in dead_code diagnostic. 2022-06-23 13:08:08 -07:00
Joshua Nelson
55b680c194 Add support for -Zbuild-std to cargo fetch
This allows downloading the dependencies for libstd in advance, which
can be useful in e.g. sandboxed build environments.

- Abstract check for `--target` out into a function
- Try to abstract `test` special-casing into a function

  This avoids hard-coding crate names in multiple places.

- Unify handling of checks for `--target` in `BuildConfig::new`

  This makes sure it's checked consistently, without requiring each new command to check it explicitly.

- Share more code between `fetch` and `build` by adding `std_crates()`
- Warn about `--build-plan` and `-Zbuild-std` consistently, not just for `build`

  Currently only `build` uses build-plan. But cargo may choose to add it to new commands in the future (e.g. check and doc).
  Future-proof it, since it's simple to do.
2022-05-03 20:07:14 -05:00
Eric Huss
00e925f61f Fix panic with build-std of a proc-macro. 2021-08-23 12:06:32 -07:00
Eric Huss
0ac41f0051 Fix tests not working with a different CARGO_TARGET_DIR. 2020-12-16 11:19:32 -08:00
Alex Crichton
049b2727b1 Fix a test 2020-12-11 08:43:27 -08:00
Alex Crichton
602f6b64de Revert "Check if rust-src contains a vendor dir, and patch it in"
This reverts commit eadb4fc86c6660760ff857df41b7e88f6da0f714.
2020-12-11 07:45:27 -08:00
Eric Huss
6b472c90e1 Fix panic with -Zbuild-std and no roots. 2020-12-04 13:34:34 -08:00
Alexis Beingessner
eadb4fc86c Check if rust-src contains a vendor dir, and patch it in
This is the cargo side of https://github.com/rust-lang/wg-cargo-std-aware/issues/23
2020-11-10 11:47:32 -05:00
Alex Crichton
1faf5b9f00 Add a -Zbuild-std-features flag
This flag is intended to pair with `-Zbuild-std` as necessary to
configure the features that libstd is built with. This is highly
unlikely to ever be stabilized in any form (unlike `-Zbuild-std` which
we'd like to stabilize at some point), but can be useful for
experimenting with the standard library. For example today it can be
used to test changes to binary size by disabling backtraces.

My intention is that we won't need a `--no-default-features` equivalent
for libstd, where after rust-lang/rust#74377 is merged we can
unconditionally specify default features are disabled but the default
set of features lists `default`. That way if users want to override the
list *and* include the default feature, they can just be sure to include
`default`.
2020-07-17 07:02:19 -07:00
Alex Crichton
78314caf38 Ensure unstable.build-std works like -Zbuild-std
This fixes an issue where the deserializer for `-Zbuild-std` was a bit
fancier than the `unstable.build-std` directive.

cc #8393
2020-07-16 08:49:04 -07:00
Alex Crichton
3fd28143de Support multiple --target flags on the CLI
This commit refactors the internals of Cargo to no longer have a
singular `--target` flag (and singular `requested_target` kind throught)
but to instead have a list. The semantics of multiple `--target` flags
is to build the selected targets for each of the input `--target` flag
inputs.

For now this is gated behind `-Zmultitarget` as an unstable features,
since I'm not entirely sure this is the interface we want. In general
it'd be great if we had a way to simply specify `Unit` structures of
what to build on the CLI, but we're in general very far away from that,
so I figured that this is probably sufficient at least for testing for
now.

cc #8156
2020-04-28 15:16:47 -07:00
Eric Huss
b6a4b074ed build-std: Don't treat std like a "local" package. 2020-04-28 13:05:55 -07:00
bors
90931d9b31 Auto merge of #8077 - faern:use-assoc-int-consts, r=ehuss
Use associated constants directly on primitive types instead of modules

This PR is in no way critical. It's more of a code cleanup. It comes as a result of me making https://github.com/rust-lang/rust/pull/70857 and search-and-replacing all usage of the soft-deprecated ways of reaching primitive type constants.

It makes the code slightly shorter, that's basically it. And showcases the recommended way of reaching these consts on new code :)
2020-04-28 01:56:59 +00:00
Mateusz Mikuła
9f742466f1 Update tests for windows-gnu 2020-04-21 17:25:25 +02:00
Linus Färnstrand
c428c0ef41 Use associated constants directly on primitive types instead of modules 2020-04-06 23:37:06 +02:00
Eric Huss
1c779ac5d4 Switch build-std to use --extern 2019-12-12 08:18:15 -08:00
Eric Huss
83571aee56 Minor testsuite organization. 2019-11-24 18:42:45 -08:00
Matthias Krüger
3fce509208 fix a bunch of clippy warnings 2019-09-26 17:51:19 +02:00
Eric Huss
d0ab04add4 Simplify mock rustc wrapper. 2019-09-24 12:45:32 -07:00
Eric Huss
53a3db05a6 Some more --sysroot tests. 2019-09-23 18:53:28 -07:00
Alex Crichton
bc5c441b12 Change how standard_lib tests work
* Minimize the sysroot crates in play
* Don't use build scripts to inject args
* Use `RUSTC_WRAPPER` to dynamically switch `--sysroot` depending on
  whether we're building sysroot crates or not.
* Minimize dependency graph in sysroot, only have each crate depend on a
  dummy crates.io crate for testing and otherwise don't depend on
  anything to load the desired sysroot crate directly.
2019-09-23 18:53:28 -07:00
Alex Crichton
0dd79670d4 Add back a full integration test for -Zbuild-std
Only run these tests on one CI builder (not all platforms) though. This
is extremely resource intensive since it rebuilds libstd. Currently this
does not share a build directly like before because the number of tests
are supposed to be small, but if necessary we can add that in later too.
2019-09-16 11:47:09 -07:00
Alex Crichton
9115b2c326 Extract support directory to its own crate
Extract out all our test support code to its own standalone crate so it
can be shared between multiple test suites if necessary.
2019-09-16 11:47:09 -07:00
Alex Crichton
4cbfd02eff Improve test suite for -Zbuild-std
This commit is aimed directly at rust-lang/wg-cargo-std-aware#33 and in
general making the `-Zbuild-std` tests more robust. The main change here
is that a new source tree is checked in, `tests/testsuite/mock-std`,
which mirrors rust-lang/rust's own tree for libstd. This mock tree is as
empty as it can be, ideally duplicating almost nothing but for not
requiring duplication of Cargo metadata about patches and such.

The end result here looks like:

* All `-Zbuild-std` tests are now run in parallel
* All tests run much more quickly since they're compiling tiny crates
  instead of actually compiling libstd/libcore
* No tests require network access
* We verify that crates have access to the "custom" libraries
  that we build

Coverage of tests is not currently expanded, but it's hoped that we
could add that shortly afterwards. Coverage has actually gone down
slightly since the custom target test was commented out temporarily and
the full integration test of running `-Zbuild-std` isn't run on CI any
more.

Closes rust-lang/wg-cargo-std-aware#33
2019-09-16 11:46:46 -07:00
Philipp Oppermann
6b4fd44ea6 Add a test for -Zbuild-std with custom test frameworks 2019-09-15 17:54:35 +02:00
Alex Crichton
2ed112c14e Add alloc and proc_macro to libstd crates
These two have been stabilized for all targets like `std` so if `std` is
requested let's be sure to make them available to other crates as well.
2019-09-06 13:49:48 -07:00
Eric Huss
aee4048229 Remove bin_nostd test, it will likely to finicky. 2019-09-03 13:53:59 -07:00
Eric Huss
1f14fa3172 Basic standard library support. 2019-09-03 13:53:59 -07:00