Commit graph

108 commits

Author SHA1 Message Date
Ed Page
633929d3aa refactor(schemas): Pull out cargo-util-schemas crate
Fixes #12801
2023-12-15 13:22:25 -06:00
Ed Page
e46df98241 refactor(schemas): Pull out mod for proposed schemas package
Originally for #12801 we talked about a `cargo-util-manifest-schema` package
- `util` in the name to not clash with plugins
- manifest specific to keep the scope down

The problem is we have types that aren't manifest specific, like
- `PartialVersion` (currently slated for `cargo-util-semverext`)
- `RustVersion`
- `PackageIdSpec`
- `SourceKind` (soon)

Things get messy if we try to break things down into common packages.
Instead, I think it'd be useful to have a schemas package that has mods
for each type of schema, re-exporting what is needed.

Normally, componentizing your package by the layer in the stack is a
recipe for pain.
I don't think that'll apply here because these are meant to be so low
level.

The other big concern could be compile times.  My hope is it won't be
too bad.

So this moves the `util/toml` types into the module and we can add more
in the future.
2023-12-01 13:31:30 -06:00
Ed Page
9a1bbc9625 refactor(toml): Pull out schema
Remaining steps
- Decouple `toml/mod.rs` functionality from `toml/schema.rs`
- Pull out `core/` types referenced by `toml/schema.rs`
2023-11-01 20:59:46 -05:00
Weihang Lo
08c5e35f60
test(trim-paths): parsing in mainfest and config 2023-10-30 16:38:55 -04:00
Weihang Lo
4d29af1d81
feat(trim-paths): parsing in mainfest and config 2023-10-30 16:38:55 -04:00
Ed Page
acc52f362b refactor(toml): Decouple parsing from interning system
To have a separate manifest API (#12801), we can't rely on interning
because it might be used in longer-lifetime applications.

I consulted https://github.com/rosetta-rs/string-rosetta-rs when
deciding on what string type to use for performance.

Originally, I hoped to entirely replacing string interning.  For that, I
was looking at `arcstr` as it had a fast equality operator.  However,
that is only helpful so long as the two strings we are comparing came
from the original source.  Unsure how likely that is to happen (and
daunted by converting all of the `Copy`s into `Clone`s), I decided to
scale back.

Concerned about all of the small allocations when parsing a manifest, I
assumed I'd need a string type with small-string optimizations, like
`hipstr`, `compact_str`, `flexstr`, and `ecow`.
The first three give us more wiggle room and `hipstr` was the fastest of
them, so I went with that.

I then double checked macro benchmarks, and realized `hipstr` made no
difference and switched to `String` to keep things simple / with lower
dependencies.

When doing this, I had created a type alias (`TomlStr`) for the string
type so I could more easily swap it out if needed
(and not have to always write out a lifetime).
With just using `String`, I went ahead and dropped that.

I had problems getting the cargo benchmarks running, so I did a quick
and dirty benchmark that is end-to-end, covering fresh builds, clean
builds, and resolution.  I ran these against a fresh clone of cargo's
code base.
```console
$ ../dump/cargo-12801-bench.rs run
    Finished dev [unoptimized + debuginfo] target(s) in 0.07s
     Running `target/debug/cargo -Zscript -Zmsrv-policy ../dump/cargo-12801-bench.rs run`
warning: `package.edition` is unspecified, defaulting to `2021`
    Finished dev [unoptimized + debuginfo] target(s) in 0.04s
     Running `/home/epage/.cargo/target/0a/7f4c1ab500f045/debug/cargo-12801-bench run`
$ hyperfine "../cargo-old check" "../cargo-new check"
Benchmark 1: ../cargo-old check
  Time (mean ± σ):     119.3 ms ±   3.2 ms    [User: 98.6 ms, System: 20.3 ms]
  Range (min … max):   115.6 ms … 124.3 ms    24 runs

Benchmark 2: ../cargo-new check
  Time (mean ± σ):     119.4 ms ±   2.4 ms    [User: 98.0 ms, System: 21.1 ms]
  Range (min … max):   115.7 ms … 123.6 ms    24 runs

Summary
  ../cargo-old check ran
    1.00 ± 0.03 times faster than ../cargo-new check
$ hyperfine --prepare "cargo clean" "../cargo-old check" "../cargo-new check"
Benchmark 1: ../cargo-old check
  Time (mean ± σ):     20.249 s ±  0.392 s    [User: 157.719 s, System: 22.771 s]
  Range (min … max):   19.605 s … 21.123 s    10 runs

Benchmark 2: ../cargo-new check
  Time (mean ± σ):     20.123 s ±  0.212 s    [User: 156.156 s, System: 22.325 s]
  Range (min … max):   19.764 s … 20.420 s    10 runs

Summary
  ../cargo-new check ran
    1.01 ± 0.02 times faster than ../cargo-old check
$ hyperfine --prepare "cargo clean && rm -f Cargo.lock" "../cargo-old check" "../cargo-new check"
Benchmark 1: ../cargo-old check
  Time (mean ± σ):     21.105 s ±  0.465 s    [User: 156.482 s, System: 22.799 s]
  Range (min … max):   20.156 s … 22.010 s    10 runs

Benchmark 2: ../cargo-new check
  Time (mean ± σ):     21.358 s ±  0.538 s    [User: 156.187 s, System: 22.979 s]
  Range (min … max):   20.703 s … 22.462 s    10 runs

Summary
  ../cargo-old check ran
    1.01 ± 0.03 times faster than ../cargo-new check
```
2023-10-27 12:09:44 -05:00
Eric Huss
b37c8f35c0 Add ConfigBuilder::root
This adds the `root` method to set the root directory to be able to
override paths::root().
2023-10-08 14:16:51 -07:00
Ed Page
5cac7aa8c6 fix(toml): Remove redundant error messages 2023-08-24 16:19:48 -05:00
Arlo Siemsen
687ace1ddc Merge higher precedence config lists later
When merging configuration lists, the current order does not match
the expected precedence. This makes merged lists follow precedence
order, with higher precedence items merged later in lists.
2023-08-16 11:21:38 -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
jyn
a982bccfe8 add more debuginfo tests 2023-04-19 20:01:04 -05:00
Joshua Nelson
d861dcf792 Allow named debuginfo options in Cargo.toml
Rustc supports these since rust-lang/rust#109808. It's technically
possible to set a named debuginfo level through `RUSTFLAGS`, but in
practice cargo always passes its own opinion of what the debuginfo level
is, so allow it to be configured through cargo too.
2023-04-11 15:06:02 -05:00
Kyle Matsuda
8353396132 add unit test for config and integration test with cargo --list 2023-03-09 16:54:01 -07:00
Scott Schafer
8507c1701d chore: update config tests to use check 2023-02-20 12:20:46 -06: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
Eric Huss
018403ceaf
Add test for config Value in TOML array. 2023-01-10 14:36:37 +01:00
Weihang Lo
ef7a4ef062
Dont swallow errors when checking existence of a config key 2022-09-22 10:52:39 +01:00
Jon Gjengset
39c3173619 Stabilize --config
FCP
https://github.com/rust-lang/cargo/issues/7722#issuecomment-1114369809

Closes #7722.
2022-06-17 22:46:04 +00:00
cuishuang
6f13c466d2 fix some typos
Signed-off-by: cuishuang <imcusg@gmail.com>
2022-05-08 01:07:28 +08: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
Zach Hamlin
68fd67319d feat: support rustflags per profile 2022-01-09 11:35:15 -06:00
hi-rustin
a0dffe0f43 Make clippy happy
Signed-off-by: hi-rustin <rustin.liu@gmail.com>
2021-11-21 11:40:31 +08:00
Noah Lev
f6823a6427 Fix warnings from better precision of dead_code lint
The lint now ignores derived `Clone` and `Debug` implementations, as of
PR rust-lang/rust#85200, which landed a couple of days ago.

I sprinkled `#[allow(dead_code)]` in a few places; the fields are not
expected to be read since they are just part of a very specific test.
2021-09-13 10:25:52 -07:00
Aaron Hill
88679e07f2
Implement [future-incompat-report] config section
Currently, I've just implemented the `always` and `never` frequencies
from the RFC, which don't require tracking any additional state.
2021-08-19 15:59:36 -05:00
Eric Huss
f0909c7a6c Fix value-after-table error with profiles. 2021-08-14 14:45:25 -07:00
Eric Huss
b9f15ab1f0 Remove got_symlink_permission, we already have one of those. 2021-06-16 09:44:29 -07:00
Eric Huss
24b8936c20 Remove normalized_lines_match, it is not needed. 2021-06-16 09:44:29 -07:00
Eric Huss
e132bb53ab Move comparison and diffing code to a new module.
This includes various minor refactorings to try to clean things up
and provide better error messages.
2021-06-16 09:44:29 -07:00
r00ster91
b381fdb71e Improve two error messages 2021-05-10 17:28:19 +02:00
Kornel
3f7f0942cd track_caller on custom assert functions 2021-03-03 17:17:07 +00:00
bors
b219f0eb7a Auto merge of #9181 - jyn514:computer-says-no, r=ehuss
Forbid setting `RUSTC_BOOTSTRAP` from a build script on stable

Instead, recommend `RUSTC_BOOTSTRAP=crate_name`. If cargo is using a nightly toolchain, or if RUSTC_BOOTSTRAP was set in *cargo*'s build environment, the error is downgraded to a warning, since the variable won't affect the build.

This is mostly the same as suggested in https://github.com/rust-lang/cargo/issues/7088#issuecomment-713867773, except that `RUSTC_BOOTSTRAP=` values other than 1 are treated the same as `RUSTC_BOOTSTRAP=1`. My reasoning was that https://github.com/rust-lang/rust/pull/77802 is now on 1.50 stable, so some crates may have started using it, and I would still prefer not to give hard errors when there's no workaround.

Closes https://github.com/rust-lang/cargo/issues/7088.

r? `@joshtriplett`
2021-03-03 03:19:33 +00:00
bors
f3e63d6ab4 Auto merge of #8939 - Andy-Python-Programmer:master, r=alexcrichton
Throw error if CARGO_TARGET_DIR is an empty string

This pull request makes the target dir to be target/ if `CARGO_TARGET_DIR` is `` with spaces trimmed and not delete the current project.

Fixes: #8866
2021-02-25 19:40:08 +00:00
unknown
b5b2e489d6 Fix tests 2021-02-25 18:48:05 +11:00
unknown
019b4e111e Fixes error message 2021-02-25 18:10:59 +11:00
Joshua Nelson
ecfdced0d8 Fix test that assumed tests always were run on the stable channel
Note that this has to be set in the builder, before
`config.configure()` gets run.
2021-02-24 15:11:34 -05:00
Joshua Nelson
a5720117fe Make nightly_features_allowed a field instead of a function
`nightly_features_allowed()` is no longer doing any work, so it can be
accessed directly. This also renames the `enable_nightly_features` field
to `nightly_features_allowed`.
2021-02-24 15:11:31 -05:00
Joshua Nelson
4b096beaed Fix masquerade_as_nightly_cargo in work threads
Previously, since `ENABLE_NIGHTLY_FEATURES` and
`NIGHTLY_FEATURES_ENABLED` were thread locals, reading them in any other
thread would always say nightly features were disabled. Now, they are
tied to the `Context` itself, so it is both more clear how the variables
are being set and fixes the behavior within work threads.

Note that `Context` is not thread-safe, so this passes a boolean through
to `BuildOutput::parse`.
2021-02-24 14:43:00 -05:00
unknown
97707a880e Add tests 2021-02-24 17:56:20 +11:00
Eric Huss
9cb8f41ec9 Prevent testsuite from loading config out of sandbox. 2021-02-10 17:39:38 -08:00
bors
0608fcd99d Allow true and false as options for strip option
This follows the convention of `lto` and `debug` that allow `true` for
the highest level, and `false` for disabled.

Signed-off-by: David Calavera <david.calavera@gmail.com>
2021-02-10 00:19:10 +00:00
unknown
7a69aafbf3 Add tests for target_dir; throw error if [build] target = '' and update messages 2021-01-23 18:18:28 +11:00
Eric Huss
ad34852f39 Update toml dependency 2020-10-12 11:22:45 -07:00
Eric Huss
6f8c7d5a87 Normalize raw string indentation. 2020-09-26 17:59:58 -07:00
Alex Berghage
d035daae4e Fix tests for handling env key overlaps / errors 2020-07-09 13:12:34 -06:00
Alex Berghage
e49b3aed79 Add tests verifying overlapping prefixes and defaults
These tests demonstrate the current failure mode around
overlapping env keys and inner structs. To some extent this
is a limitation of mapping on to environment variables with
an underscore as both the namespace separator and the
substitute for dashes in flag names in that the mapping is
not strictly one-to-one.
2020-07-09 12:53:42 -06:00
Alex Berghage
724273ed25 Minor test fix (error text comparison)
Serde's errors for missing fields are a lil' different than
the ones from our Deserializer.
2020-07-08 21:22:44 -06:00
Alex Berghage
08f1020f48 Drop broken test asserting invalid configs error on nightly
The current behavior, with the default-false workaround in place,
is not able to identify extra members of the `unstable` table, so
it can't error on unexpected members.

I'll add this test back in with a Deserializer refactor to clean up
the extra logic added to CliUnstable.
2020-07-07 23:38:26 -06:00
Alexander Berghage
bd938f077d Switch unstable config parsing to serde
Tests are currently failing, looks like there's something in the
Deserializer impl that's forcing field-missing errors even when
the serde `default` annotation is applied.
2020-07-07 23:38:26 -06:00
Alex Berghage
4aede8c784 Allow setting unstable options in .cargo/config
Obviously this only works with nightlies and all
that, but if you're e.g. testing resolver v2, want
to always have Ztiming on in your workspace, or
something like that, this makes it easier to do.
2020-07-07 23:38:26 -06:00
Gabriel Majeri
65fc4cec8d Implement enum config options deserialization 2020-07-06 22:12:15 +03:00