Skip to content
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

Option to show macro expansion of input #47

Closed
lilyball opened this issue Mar 25, 2022 · 1 comment
Closed

Option to show macro expansion of input #47

lilyball opened this issue Mar 25, 2022 · 1 comment
Labels
enhancement New feature or request

Comments

@lilyball
Copy link

I'd love a flag that makes this print the macro expansion of the input instead of compiling and running it. This could be done as a flag like --macro-expand that selects the nightly toolchain (if not otherwise set) and runs cargo rustc --profile=check -- -Zunpretty=expanded.

Alternatives considered

rust-script could have a flag for simply changing the cargo command being run, such that if I have cargo-expand installed I could write something like rust-script --cargo-cmd expand script.rs. This is more flexible (e.g. I could also use it to run cargo clippy or cargo check if I'm just trying to see any warnings or errors), though it does require the user to install cargo-expand first.

With this approach the --test and --bench flags could potentially be obsoleted in favor of just specifying the test and bench cargo commands, though in this case the syntax for specifying the command should be simpler. I notice that right now rust-script lists its syntax as rust-script [OPTIONS] [--] [script]... but if I actually run rust-script foo bar it treats foo as a script and ignores bar completely (also it indicates script as being optional and yet it is not). This could be updated to the syntax rust-script [OPTIONS] [--] [cmd] <script> instead such that I could write rust-script test foo.rs to run cargo test or rust-script expand foo.rs to run cargo expand.

@fornwall fornwall added the enhancement New feature or request label Mar 25, 2023
@fornwall
Copy link
Owner

Version 0.23.0 has just been released.

There the -p/--project parameter can be used to generate the package and print the package path, without doing any build step.

This allows things such as cargo tree --manifest-path $(rust-script -p test.rs)/Cargo.toml or cd "$(rust-script --package script.ers), so should provide flexibility.

Let me know how it works!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

2 participants