Commit graph

284 commits

Author SHA1 Message Date
Eric Huss 3da2b3c67b Mark -C as unstable 2023-04-11 19:46:05 -07:00
bors c1334b059c Auto merge of #11645 - chansuke:issue-11597, r=weihanglo
Add `CARGO_PKG_README`

Fixes #11597

This environment variable shows the path to the README file of your package. From #11597:

> Cargo may rewrite the package’s `Cargo.toml` and move the README file around, relative to the manifest. I would like to `include_str!()` this README in my `lib.rs`, but am unable to do so right now, because if I specify `include_str!("../../README")` it works for development, but I can’t package my crate. Conversely if I specify `include_str!("../README")` it works when packaged, but not during development.
2023-03-07 19:21:50 +00:00
Adrián Ortiz db457d950f Fixing issue https://github.com/rust-lang/cargo/issues/10834:
- Adding display of which target failed to compile
- Consistent messages for warnings/errors.
- Fixing assertions on related tests.
2023-03-07 06:45:26 +01:00
chansuke fb9be455cd Add tests for CARGO_PKG_README 2023-03-03 23:21:16 +09:00
Tobias Rapp 0fda7acf48 Set CARGO_BIN_NAME environment variable also for binary examples
Extend the existing CARGO_BIN_NAME environment variable to be set when
building binary example targets, additional to "normal" binary targets.

Closes #11689.
2023-02-13 14:25:35 +01:00
Ed Page 6007f05a85 chore: Update to toml v0.6, toml_edit v0.18
`toml` replaces `toml_edit::easy`, using `toml_edit` as its parser.
2023-01-19 15:26:28 -06:00
bors 74043673e6 Auto merge of #10952 - compenguy:cargo-change-dir-10098, r=epage
Add '-C' flag for changing current dir before build

This implements the suggestion in #10098 to make cargo change cwd before
completing config processing and starting the build. It is also an
alternative to `--manifest-path` that resolves the issue described
in #2930.

The behavior of this new flag makes cargo build function exactly the same when run at the root of the project as if run elsewhere outside of the project.  This is in contrast to `--manifest-path`, which, for example, results in a different series of directories being searched for `.cargo/config.toml` between the two cases.

Fixes #10098
Reduces impact of #2930 for many, possibly all impacted, by switching to this new cli argument.

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

The easiest way to reproduce the issue described in #2930 is to create an invalid `.cargo/config.toml` file in the root of a cargo project, for example `!` as the contents of the file.  Running cargo with the current working directory underneath the root of that project will quickly fail with an error, showing that the config file was processed.  This is correct and expected behavior.

Running the the same build with the current working directory set outside of the project, e.g. /tmp, and passing the `--manifest-path /path/to/project/Cargo.toml`.  The build will proceed without erroring as a result of reading the project's `.cargo/config.toml`, because config file searching is done from cwd (e.g. in `/tmp` and `/`) without including the project root, which is a surprising result in the context of the [cargo config documentation](https://doc.rust-lang.org/cargo/reference/config.html), which suggests that a `.cargo/config.toml` file checked into the root of a project's revision control will be processed during the build of that project.

Finally to demonstrate that this PR results in the expected behavior, run cargo similar to the previous run, from /tmp or similar, but instead of `--manifest-path /path/to/project/Cargo.toml`, pass `-C/path/to/project` to cargo (note the missing `Cargo.toml` at the end).  The build will provide the exact same (expected error) behavior as when running it within the project root directory.

### Additional information

~Passing a path with a trailing '/' will result in failure.  It is unclear whether this is a result of improper input sanitization, or whether the config.cwd value is being improperly handled on output.  In either case this needs to be resolved before this PR is merge-ready.~

(the above issue appears to have been a side effect of local corruption of my rustup toolchain, and unrelated to this change)

Because a `struct Config` gets created before command line arguments are processed, a config will exist with the actual cwd recorded, and it must then be replaced with the new value after command line arguments are processed but before anything tries to use the stored cwd value or any other value derived from it for anything.  This change effectively creates a difficult-to-document requirement during cargo initialization regarding the order of events.  For example, should a setting stored in a config file discovered via cwd+ancestors search be wanted before argument processing happens, this could result in unpleasant surprises in the exact use case this feature is being added to fix.

A long flag was deferred out to not block this on deciding what to name it.  A follow up issue will be created.
2023-02-10 20:41:41 +00:00
Will Page 4de2c96021 Add '-C' flag for changing current dir before build
This implements the suggestion in #10098 to make cargo change cwd before
completing config processing and starting the build. It is also an
alternative to --manifest-path that resolves the issue described
in #2930.
2023-02-10 07:42:37 -08:00
Noah Hellman bf7f32abf3 util toml targets: infer file only if not a dir
Any directory entry ending with `.rs`, including directories, were
previously assumed to be files, and could end up as targets.

Now only regular files and symbolic links are inferred.
2023-02-04 12:49:33 +01:00
Rémy Rakic 6848006cbe update tests for build deps debuginfo optimization 2023-01-31 20:12:52 +00:00
Kyle Huey 847dc6ed06 Make cargo aware of dwp files.
When using -Csplit-debuginfo=packed on Linux, rustc will produce a dwp file.
Unlike the dwo files, whose paths are embedded into the binary, there's no
information in the binary to help a debugger locate a dwp file. By convention,
the dwp file for <EXE> is given the name <EXE>.dwp and placed next to <EXE>.

When cargo hardlinks the executable file rustc put in target/debug/deps into
target/debug, it also needs to hardlink the dwp file along with it. Failing to
do this prevents the debugger from finding the dwp file when the binary is
executed from target/debug, as there's no way for the debugger to know to look
in the deps subdirectory.
2023-01-14 23:11:57 -08:00
Weihang Lo 3d862d8d8b
by default saves credentials to .cargo/credentials.toml 2023-01-04 16:25:52 +00:00
Eric Huss 1709f0aee2 Stabilize terminal-width 2022-12-19 12:17:52 -08:00
hi-rustin 7eadd58eef Update duplicate build targets test
Signed-off-by: hi-rustin <rustin.liu@gmail.com>
2022-12-01 08:58:52 +08:00
Scott Schafer ab18bd40d5 refactor(testsuite): Replace [project] with [package] 2022-09-26 09:51:16 -06:00
Weihang Lo bf1523b663
test: renamed uplifted artifact remains unmodified after rebuild 2022-09-21 16:02:42 +01:00
hi-rustin 99b3564d0d Update old tests
Signed-off-by: hi-rustin <rustin.liu@gmail.com>
2022-08-19 10:56:29 +08:00
bors 223e84a981 Auto merge of #10844 - yerke:yerke/negative_jobs, r=ehuss
Support for negative --jobs parameter, counting backwards from max CPUs

Fixes #9217.

Continuation of https://github.com/rust-lang/cargo/pull/9221.
2022-08-01 03:41:10 +00:00
Yerkebulan Tulibergenov 767368fd02 Merge branch 'master' into yerke/negative_jobs 2022-07-31 18:21:33 -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
Yerkebulan Tulibergenov 2a75b44bc5 fix the test 2022-07-10 16:31:24 -07:00
Yerkebulan Tulibergenov dc23d97d5b Merge branch 'master' into yerke/negative_jobs 2022-07-10 14:20:26 -07:00
Eric Huss 79d7dc0e49 Update terminal-width flag. 2022-07-08 07:57:40 -07:00
Eric Huss 502a9c5407 Fix tests due to change in dead_code diagnostic. 2022-06-23 13:08:08 -07:00
flip1995 0852f5413e
Expose rust-version through env var 2022-06-06 12:04:20 +02:00
Scott Schafer cab6d30c1d fix typos found by the typos-cli crate 2022-05-10 16:47:28 -05:00
Loïc BRANSTETT 2d0ca84b0e Move check cfg tests to their own module 2022-05-06 22:42:28 +02:00
Loïc BRANSTETT 6a9f094c8c Convert the testsuite to use the new -Zcheck-cfg flag and syntax 2022-05-06 22:40:08 +02:00
bors 403c6bd257 Auto merge of #10486 - Urgau:check-cfg-well-known, r=weihanglo
Add support for rustc --check-cfg well known names and values

This pull-request add support for `rustc` `--check-cfg` well known names and values.

### What does this PR try to resolve?

This pull-request add support for `rustc` `--check-cfg` well known names and values:

- `-Z check-cfg-well-known-names`: `--check-cfg names()` well known names
- `-Z check-cfg-well-known-values`: `--check-cfg values()` well known values

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

#### Testing

`cargo check -Z check-cfg-well-known-names` and
`cargo check -Z check-cfg-well-known-values`

#### Review

This PR contains one commit that split `features_args` into `check_cfg_args`, add the well known support in it, adds call to that new function and add documentation and test for those new flags.

### Additional information

This was implemented as two new additional flags because it's most likely that these flags will not be stabilize at the same time and also because some of these flags may become the default.

RFC: https://github.com/rust-lang/rfcs/pull/3013
`-Z check-cfg-features`: https://github.com/rust-lang/cargo/pull/10408
`cargo doc` support: https://github.com/rust-lang/cargo/pull/10428
2022-04-12 14:36:40 +00:00
bors 5e09899f33 Auto merge of #10394 - dtolnay-contrib:displayerror, r=ehuss
Consistently use crate::display_error on errors during drain

As suggested in https://github.com/rust-lang/cargo/pull/10383#discussion_r808178038 and https://github.com/rust-lang/cargo/pull/10383#discussion_r808182199.
2022-03-21 18:48:36 +00:00
Loïc BRANSTETT 02cd9442c7 Add support for rustc --check-cfg well known names and values 2022-03-18 22:14:39 +01:00
David Tolnay 809bcfe91d
Print only Message::Finish errors all the time 2022-03-16 00:18:52 -07:00
hi-rustin 8b895cc80b Use warn_on_deprecated
Signed-off-by: hi-rustin <rustin.liu@gmail.com>
2022-03-10 00:08:28 +08:00
hi-rustin b295e2fd67 Warning on conflicting dev_dependencies keys of platform
Signed-off-by: hi-rustin <rustin.liu@gmail.com>
2022-03-09 23:16:38 +08:00
hi-rustin ad375afa7a Warning on conflicting build_dependencies keys of platform
Signed-off-by: hi-rustin <rustin.liu@gmail.com>
2022-03-09 23:16:38 +08:00
hi-rustin ed93c94bd1 Warning on conflicting build_dependencies keys
Signed-off-by: hi-rustin <rustin.liu@gmail.com>
2022-03-09 23:16:38 +08:00
hi-rustin 154f372b6b Warning on conflicting dev-dependencies keys
Signed-off-by: hi-rustin <rustin.liu@gmail.com>
2022-03-09 23:16:38 +08:00
hi-rustin a317aff9b8 Warning on conflicting crate_types keys
Signed-off-by: hi-rustin <rustin.liu@gmail.com>
2022-03-09 23:16:38 +08:00
bors c9a8199e92 Auto merge of #10372 - weihanglo:issue-9325, r=ehuss
Test: ensure dep-infos do not collide when cdylib and bin coexist
2022-02-25 18:08:41 +00:00
Loïc BRANSTETT 4ac4f3d9ab Add test for -Z check-cfg-features with namespaced features 2022-02-22 18:43:12 +01:00
Loïc BRANSTETT a864c81549 Disable -Z check-cfg-features tests on windows due to weird normalization issues
See https://github.com/rust-lang/cargo/runs/5290789288?check_suite_focus=true
Where the expected is: --check-cfg 'values(feature, "f_a", "f_b")'
But we got: --check-cfg "values(feature, /"f_a/", /"f_b/")"
2022-02-22 18:33:03 +01:00
Loïc BRANSTETT 03fbb2eda8 Add -Z check-cfg-features to enable compile-time checking of features 2022-02-22 16:47:52 +01:00
Weihang Lo e2142487d4
Test: ensure dep-infos do not collide when cdylib and bin coexist
A new test `build::no_dep_info_collision_when_cdylib_and_bin_coexist`
is added to prevent regression.

Note that on Windows MSVC cargo does not use metadata, so a collision
still happens when cdylib and bin targets coexist.
2022-02-08 22:51:18 +08:00
bors bb96b3a3e8 Auto merge of #10086 - epage:toml, r=ehuss
Port cargo from toml-rs to toml_edit

Benefits:
- A TOML 1.0 compliant parser
- Unblock future work
  - Have `cargo init` add the current crate to the workspace, rather
    than error
  - #5586: Upstream `cargo-add`

TODO
- [x] Analyze performance and address regressions
- [x] Identify and resolve incompatibiies
- [x] Resolve remaining test failures, see
      https://github.com/ordian/toml_edit/labels/cargo
- [x] ~~Switch the code from https://github.com/rust-lang/cargo/pull/10176 to only parse once~~ (this PR is being merged first)
2022-01-20 03:56:18 +00:00
bors 95bb3c92bf Auto merge of #10243 - hi-rustin:rustin-patch-collision, r=ehuss
Error when setting crate type of both dylib and cdylib in library

close https://github.com/rust-lang/cargo/issues/10231

Error when setting crate type of both dylib and cdylib in library. Cargo can't support that at this time, since they both output the same filename.
2022-01-18 17:39:35 +00:00
hi-rustin 3738002e43 Error when setting crate type of both dylib and cdylib in library
Signed-off-by: hi-rustin <rustin.liu@gmail.com>
2022-01-16 17:38:43 +08:00
maxwase 2623af0c43 Use is_symlink() method 2022-01-14 00:36:24 +03:00
Ed Page 320c279f43 Port cargo from toml-rs to toml_edit
Benefits:
- A TOML 1.0 compliant parser
- Unblock future work
  - Have `cargo init` add the current crate to the workspace, rather
    than error
  - #5586: Upstream `cargo-add`
2022-01-13 09:27:27 -06:00
bors 2478331215 Auto merge of #10214 - weihanglo:revert-10188-issue-9528, r=alexcrichton
Be resilient to most IO error and filesystem loop while walking dirs

Let `PathSource::walk` be resilient to most IO errors and filesystem loop.

This PR also

- Add a test validating the resilience against filesystem loop to prevent regression.
- Emit warning when filesystem loop found while walking the filesystem. This is the only way I can think of now to solve #9528

Fixes #10213.
2022-01-05 22:10:29 +00:00