-
Notifications
You must be signed in to change notification settings - Fork 2.4k
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
Tracking Issue for cargo-script RFC 3424 #12207
Comments
This comment was marked as resolved.
This comment was marked as resolved.
This comment was marked as resolved.
This comment was marked as resolved.
feat: Initial support for single-file packages ### What does this PR try to resolve? This is the first step towards #12207. In particular, this focuses on pulling in the [demo](https://github.com/epage/cargo-script-mvs) roughly as-is to serve as a baseline for further PRs. I have a couple months of runtime (multiple times a week) using the version of the demo included here. ### How should we test and review this PR? Commit-by-commit. Most likely, the last (docs) commit should be done first to provide context for the others. Naming is hard. I came up with these terms just so we can have ways to refer to them. Feedback is welcome. - `-Zscript` for this general feature (not great but didn't want to spend too long coming up with a throwaway name) - "single-file package": Rust code and a cargo manifest in a single file - "embedded manifest": the explicit manifest inside of a single-file package - "manifest command": when we interpret `cargo <name>` as referring to a single-file package, and similar to "built-in commands" and "external commands". Keep in mind that this is a very hacky solution with many deficiencies and is mostly starting as a baseline for implementing and reviewing those improvements, including - Switching from `regex` to `syn` for extracting manifests for greater resilience - Matching `cargo new`s logic when sanitizing the inferred package name - Allowing `cargo <name>` to also be a `Cargo.toml` file (for consistency in where manifests are accepted) - Allowing single-file packages to be used wherever a manifest is accepted To minimize conflict pain, I would ask that we consider what feedback can be handled in a follow up (though still mention it!). It'll be much easier creating multiple, independent PRs once this baseline is merged to address concerns. ### Additional information The only affect for people on stable is that they may get a warning if they have an external subcommand that will be shadowed when this feature is implemented. This will allow us to collect feedback, without blocking people, so we can have an idea of how "safe" our precedence scheme is for interpreting `cargo <name>`. As of right now, aliases with a `.` in them will be ignored (well, technically their suffix will be exposed as an alias). We directly inject the name into a lookup string into the config that uses `.` as the separator, so we drill down until we get to the leaf element. Ideally, we would be generating / parsing the lookup key using TOML key syntax so we can better report that this won't be supported after this change :)
This comment was marked as resolved.
This comment was marked as resolved.
This comment was marked as resolved.
This comment was marked as resolved.
fix(embedded): Align package name sanitization with cargo-new ### What does this PR try to resolve? This is a follow up to #12245 which is working to resolve the tracking issue #12207 This first aligns sanitization of package names with the central package name validation logic, putting the code next to each other so they can more easily stay in sync. Oddly enough, cargo-new is stricter than our normal package-name validation. I went ahead and sanitized along with that as well. In working on this, I was bothered by - the mix of `-` and `_` in file names because of sanitization, so I made it more consistent by detecting which the user is using - -using `_` in bins, so I switched the default to `-` ### How should we test and review this PR? One existing test covers a variety of sanitization needs Another existing test hit one of the other cases (`test` being reserved) ### Additional information For implementation convenience, I changed the directory we write the manifest to. The impact of this should be minimal since - We reuse the full file name, so if it worked for the user it should work for us - We should be moving away from the temp manifest in future commits
refactor(embedded): Switch to `syn` for parsing doc comments This is a follow up to #12245 which is working to resolve #12207 The hope is this will result in more resilient comment handling, being more consistent with rustdoc. I also hoped for less code but `syn` is doing less than I had expected, requiring us to copy code over from other parts of rust. It seems every proc macro has to do this but there is no guide to it, so they all do it differently, only covering the cases they thought to test for. Note that this still won't support `include_str!()`.
This comment was marked as resolved.
This comment was marked as resolved.
This comment was marked as resolved.
This comment was marked as resolved.
fix(embeded): Don't pollute the scripts dir with `target/` ### What does this PR try to resolve? This PR is part of #12207. This specific behavior was broken in #12268 when we stopped using an intermediate `Cargo.toml` file. Unlike pre-#12268, - We are hashing the path, rather than the content, with the assumption that people change content more frequently than the path - We are using a simpler hash than `blake3` in the hopes that we can get away with it Unlike the Pre-RFC demo - We are not forcing a single target dir for all scripts in the hopes that we get #5931 ### How should we test and review this PR? A new test was added specifically to show the target dir behavior, rather than overloading an existing test or making all tests sensitive to changes in this behavior. ### Additional information In the future, we might want to resolve symlinks before we get to this point
This comment was marked as resolved.
This comment was marked as resolved.
This comment was marked as resolved.
This comment was marked as resolved.
This comment was marked as resolved.
This comment was marked as resolved.
This comment was marked as resolved.
This comment was marked as resolved.
CARGO_TARGET_DIR
to make it the parent of all target directories
rust-lang/rfcs#3371
How is this supposed to work on Windows? Will rustup extend In this case all Rust source files would become executable, which is confusing, especially when using Windows Explorer. I think it might be better to use a separate extension, for example |
How does python handle this on Windows? They don't use a separate extension for executable and non-executable files either. |
True, but it doesn't mean we have to follow them if we can do better. |
All MS should definitely add shebang (and magic-numbers) support to Windows! It's overdue since many years ago |
This might be a better conversation on the relevant section in the RFC: https://github.com/epage/rfcs/blob/script/text/3502-cargo-script.md#file-association-on-windows |
I sent you a PR. |
They won't do that because it does not make sense on Windows, since the interpreter can be in an installation-dependent place and is not necessarily found in |
well, magic number support can look for a file starting with |
Please stop, many people watching for progress, not for discussion |
The github issue linkifiers give links such as [`https://github.com/rust-lang/cargo/issue/12207`](https://github.com/rust-lang/cargo/issue/12207) (on https://rust-lang.github.io/rust-project-goals/2024h2/cargo-script.html) which 404s and should instead be [`https://github.com/rust-lang/cargo/issues/12207`](https://github.com/rust-lang/cargo/issues/12207) Seems to be from rust-lang@8b2c635#diff-5ba8f0fb0be6c41cd7ab7b18176816db5e5172549b614d6a219c4905c918e218R27-R28
Hi @epage, as a daily user of |
@Rustin170506 any of the tasks in the task list without a PR is good for grabbing. Some clarifications
The use case for this is that we allow I had wondered if we should do just always resolve symlinks but that breaks some use cases. Instead, when determining whether its embedded or not and there is no extension, we should resolve it to see what the
cargo/src/bin/cargo/commands/run.rs Lines 176 to 181 in 0461165
When we talked about this as a Cargo team, we decided this need to reload to cargo home, like This might require an RFC but likely a trivial one
This will be messy. We'll likely need to change |
One thing that occurred to me while just reading this is as you mention downloaded files : Should cargo check for a Mark of the Web when running/building scripts on Windows/NTFS-drives? |
I don't think so, but if it does, it should do it on macOS too, by checking additional file attributes. |
feat: add CARGO_MANIFEST_PATH env variable Adds `CARGO_MANIFEST_PATH` variable as part of #12207 Context: `CARGO_MANIFEST_DIR` is not very useful, because there is no `Cargo.toml` file when running a cargo script. In cases when multiple scripts are stored in the same folder, we can't tell which script exactly is being run using `CARGO_MANIFEST_DIR`
I will give this one a try. |
This avoids syntax errors until Rust supports the syntax in its tooling: rust-lang/cargo#12207 (comment)
This avoids syntax errors until Rust supports the syntax in its tooling: rust-lang/cargo#12207 (comment)
Summary
eRFC: #3424
RFC: rust-lang/rfcs#3502, rust-lang/rfcs#3503
Testing steps
Implementation:
syn
for parsing doc comments #12258cargo Cargo.toml
#12281Cargo.toml
of the cargo-script #14670target/
#12282CARGO_MANIFEST_PATH
variable to replaceCARGO_MANIFEST_DIR
(feat: add CARGO_MANIFEST_PATH env variable #14404)cargo install
ignores therust-toolchain.toml
or uses the wrong one #11036)version
field optional in Cargo.toml #9829cargo pkgid
support[lib]
(Cargo scripts try to build a nearbysrc/lib.rs
if present #14476)cargo add
/cargo rm
supportcargo clippy
supportcargo fmt
support (Styling of Rust Frontmatter rustfmt#6388)cargo fix
supportDeferred / non-blocking:
cargo publish
(including setting theincludes
implicitly)cargo foo.rs
output noiseCARGO_TARGET_DIR
to make it the parent of all target directories rfcs#3371 and last-seen zulip discussion for shared cache rather than a sharedCARGO_TARGET_DIR
like in the Pre-RFCpackage.name
optional #12689-Zscript
should overridecurrent_exe
#12870cargo Cargo.toml
support, see Remove the support forCargo.toml
of the cargo-script #14670Documentation: https://doc.rust-lang.org/nightly/cargo/reference/unstable.html#script
Issues: Z-scriptNightly: cargo script
More design updates and exploration can be found at: https://github.com/epage/cargo-script-mvs/blob/main/0000-cargo-script.md
This is an experimental feature to add unstable support for single-file packages in cargo so we can explore the design and resolve questions with an implementation to collect feedback on.
Note: third-party support
Unresolved Issues
See also the Pre-RFC for more discussion
Future Extensions
No response
About tracking issues
Tracking issues are used to record the overall progress of implementation.
They are also used as hubs connecting to other relevant issues, e.g., bugs or open design questions.
A tracking issue is however not meant for large scale discussion, questions, or bug reports about a feature.
Instead, open a dedicated issue for the specific matter and add the relevant feature gate label.
The text was updated successfully, but these errors were encountered: