Commit graph

316 commits

Author SHA1 Message Date
Ed Page
675224b3a0 test(config): Shift to config.toml 2024-01-26 13:40:46 -06:00
Weihang Lo
f9fd4ff4ee
fix(json-msg): use pkgid spec in in JSON messages
In 12914 we stabilized pkgid spec as unique package identifier for
`cargo metadata`. However, we forgot to make the same change to
JSON message format[^1]. This PR does so.

Note that the `package_id` field in JSON message is not clearly stated
as "opaque", so it might be considered as a breaking change to some extent.

[^1]: https://doc.rust-lang.org/nightly/cargo/reference/external-tools.html#compiler-messages
2024-01-17 11:31:19 -05:00
Scott Schafer
0d62ae2fc3
feat: Add rustc style errors for manifest parsing 2023-12-15 13:30:10 -07:00
hi-rustin
ed9dc44f47 Update other tests to use cargo:: syntax
Signed-off-by: hi-rustin <rustin.liu@gmail.com>
2023-12-23 13:17:55 +08:00
Ed Page
6b6eb06714 fix: Improve package name errors 2023-12-13 11:27:02 -06:00
Ed Page
a383185c38 refactor: Centralize empty name check 2023-12-13 10:46:38 -06:00
Adrian
b7b5a093a1
Fix cargo errors counter 2023-11-29 18:47:14 +02:00
Yerkebulan Tulibergenov
e81d84cc17 feat: Add CARGO_RUSTC_CURRENT_DIR
This is an alternative to #12158's `CARGO_WORKSPACE_DIR` that was
implementing the solution to #3946 that previously discussed in the
cargo team meeting.

`CARGO_WORKSPACE_DIR` is a bit awkward to document / describe because
its the effective workspace directory of the thing being built.
If the thing being built doesn't have a workspace, it falls back to
`CARGO_MANIFEST_DIR`.

It would also be hard to take into account what the
`CARGO_WORKSPACE_DIR` would be for path dependencies into foreign
workspaces *and* it wouldn't solve the problem the user is having.

What the user really wants is the CWD of rustc when it is invoked.
This is much simpler to describe and is accurate when using a path
dependency to a foreign package.

Because the CWD is a much simpler mechanism to talk about, I figured we
could diverge from our prior consensus and make it always present,
rather than limiting it to tests.

Remaining work for #3946: get this stabilized
2023-11-17 09:25:46 -06:00
Ed Page
c75c456de4 test(compiler): Make inner test names more specific
This will make it easier to verify other env variables later
2023-11-17 09:25:34 -06:00
Eric Huss
0afd943dad Fix some test output validation. 2023-11-15 15:10:18 -08:00
hi-rustin
497e1ee307 Better suggestion for unsupported -path flag
Signed-off-by: hi-rustin <rustin.liu@gmail.com>
2023-10-12 19:24:42 +08:00
hi-rustin
95d79094e0 Add test for unsupported --path flag
Signed-off-by: hi-rustin <rustin.liu@gmail.com>
2023-10-12 09:01:34 +08:00
hi-rustin
b514ca5e24 Add unsupported short flag suggestion for --exclude flag
Signed-off-by: hi-rustin <rustin.liu@gmail.com>
2023-10-11 09:41:05 +08:00
hi-rustin
718b69ce19 Add test for unsupported short exclude flag
Signed-off-by: hi-rustin <rustin.liu@gmail.com>
2023-10-11 09:39:13 +08:00
hi-rustin
819a836e9a Add unsupported short flag suggestion for --target flag
Signed-off-by: hi-rustin <rustin.liu@gmail.com>
2023-10-11 09:16:26 +08:00
hi-rustin
2f90430110 Add test for unsupported short target triple flag
Signed-off-by: hi-rustin <rustin.liu@gmail.com>
2023-10-11 09:13:55 +08:00
Weihang Lo
a263a7dc31
test(build): generalize test assertion for non-rustup env 2023-10-10 17:52:46 -04:00
hi-rustin
f9719dcf4e add unsupported lowercase flag suggestion for -Z flag
Signed-off-by: hi-rustin <rustin.liu@gmail.com>
2023-10-08 08:36:49 +08:00
hi-rustin
0108d5b0dc Add test for unsupported short unstable feature flag
Signed-off-by: hi-rustin <rustin.liu@gmail.com>
2023-10-08 08:36:09 +08:00
bors
fc790e7b2d Auto merge of #12781 - dvdhrm:pr/target-typo, r=epage
cargo/targets: fix error-message typo

Fix typo: "with with" -> "with"
2023-10-06 13:59:27 +00:00
David Rheinsberg
4aa1a95714 cargo/targets: fix error-message typo
Fix typo: "with with" -> "with"
2023-10-06 15:08:48 +02:00
hi-rustin
2400e42652 add unsupported short suggestion for --config flag
Signed-off-by: hi-rustin <rustin.liu@gmail.com>
2023-10-06 16:27:31 +08:00
hi-rustin
914119940b Add test for unsupported short config flag 2023-10-06 16:16:35 +08:00
hi-rustin
97656fbf87 Correct the helper name and the tip message 2023-09-21 10:12:03 +08:00
hi-rustin
ed86337492 Better suggestion for unsupported mode in build command 2023-09-20 11:24:44 +08:00
hi-rustin
f262297e9a Add test for using unsupported mode in build command 2023-09-20 11:23:01 +08:00
Ed Page
53dcd2f454 fix(manifest): Provide more context on sematic errors 2023-08-24 16:27:53 -05:00
Ed Page
5cac7aa8c6 fix(toml): Remove redundant error messages 2023-08-24 16:19:48 -05:00
Charalampos Mitrodimas
a777b82d5f Support "default" option for build.jobs
This commit adds support for passing the keyword "default"
to either the CLI "--jobs" argument on the "[build.jobs]"
section of ".cargo/config".

This is dony by:
  1. Changing the "jobs" config type to an enum that holds
     a String or an Integer(i.e. i32).
  2. Matching the enum & casting it to an integer

Signed-off-by: Charalampos Mitrodimas <charmitro@gmail.com>
2023-06-03 15:24:41 +03:00
Weihang Lo
64a1f204f3
refactor: only when -C debuginfo > 0 will spilt-debuginfo be passed
It was unnecessary to pass `spilt-debuginfo` if there is no debuginfo.
Tests are touched here only for matching rustflags invocation stderr
in the original test suite.
2023-05-31 20:43:57 +01:00
jyn
e2eacc6414 Don't distinguish Debuginfo::None and Debuginfo::Explicit(None)
Previously, `Debuginfo::None` meant "don't pass -C debuginfo" and `Explicit(None)` meant
"-C debuginfo=0", which occasionally led to caching bugs where cargo would sometimes pass
`-C debuginfo=0` and sometimes not. There are no such bugs currently that we know of, but
representing them the same within cargo avoids the possibility of the bug popping up again in the
future.

I tested the `with_stderr_does_not_contain_tests` with this diff to ensure they did not pass:
```diff
diff --git a/src/cargo/core/compiler/mod.rs b/src/cargo/core/compiler/mod.rs
index 55ec17182..c186dd00a 100644
--- a/src/cargo/core/compiler/mod.rs
+++ b/src/cargo/core/compiler/mod.rs
@@ -1073,9 +1073,7 @@ fn build_base_args(

     let debuginfo = debuginfo.into_inner();
     // Shorten the number of arguments if possible.
-    if debuginfo != TomlDebugInfo::None {
         cmd.arg("-C").arg(format!("debuginfo={}", debuginfo));
-    }

     cmd.args(unit.pkg.manifest().lint_rustflags());
     if !rustflags.is_empty() {
```
2023-05-30 17:06:50 -05:00
Weihang Lo
277e65bf4c
fix: pass -C debuginfo after weakening if explicitly set
The weakening of debuginfo for build script shouldn't turn debuginfo
to `DebugInfo::None`. That will result in not passing `-C debuginfo=0`
to rustc, leading to build artifact cache miss.
2023-05-22 00:37:08 +01:00
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