-
Notifications
You must be signed in to change notification settings - Fork 11
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
201/pass cfg flags #214
201/pass cfg flags #214
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is a nice start. I haven't tested the cfg part myself yet, but believe that this will work, based on your comments in the issue.
For testing the environment value, I can recommend using the --test-setup
argument for dogfood. It'll print out the environment values, instead of running marker, after everything is compiled. For me, it roughly looked like this:
$ cargo dogfood --test-setup
# [...]
env:RUSTC_WORKSPACE_WRAPPER=.../marker/target/debug/marker_rustc_driver
env:MARKER_LINT_CRATES=marker_lints:.../marker/target/marker/lints/libmarker_lints.so;marker_uilints:.../marker/target/marker/lints/libmarker_uilints.so
info:toolchain=nightly-2023-07-13
info:marker-api=0.1.1
(With #213 merged it will become cargo dogfood test-setup
).
I left some comments, as always, please don't hesitate to ask if you have any questions.
for lint_src in sources { | ||
build_lint(lint_src, config)?; | ||
} | ||
|
||
// Find lint lint crates | ||
match std::fs::read_dir(&lints_dir) { | ||
Ok(dir) => { | ||
let ending = OsStr::new(DYNAMIC_LIB_FILE_ENDING); | ||
let mut lints = vec![]; | ||
for file in dir { | ||
let file = file.unwrap().path(); | ||
if file.extension() == Some(ending) { | ||
lints.push(LintCrate { file }); | ||
match std::fs::read_dir(&lints_dir) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
As you noted above, it feels inefficient to scan the directory after every compilation. cargo metadata
sadly doesn't provide any information how the build file will be called.
I see a few solutions:
-
Leaving it like this, it seems to work
-
Your suggestion of changing the target directory per crate
-
Guess the output file name and error if the name can't be found. The dynamic library names are constructed by adding a
lib
prefix on unix systems and the OS-specific file ending. Here is a draft of the code:// Probably store these above as constants with `DYNAMIC_LIB_FILE_ENDING` #[cfg(unix)] let lib_file_prefix = "lib"; #[cfg(windows)] let lib_file_prefix = ""; // ... let dir = &lints_dir; for lint_src in sources { build_lint(lint_src, config)?; let name = lint_src.name.clone(); let file = dir.join(format!("{lib_file_prefix}{name}.{DYNAMIC_LIB_FILE_ENDING}")); if file.exists() { lints.push(LintCrate { name, file }); } }
-
Guess the file name with more confidence. Option 3 would fail, if the user specified a
name
field in the[lib]
section, as that changes the name. This is where we can do some more hackery:Cargo's build command supports the
--config
KEY=VALUE argument, to override parts of the manifest (At least from my understanding). We should be able to use this during lint compilation to prevent any weird renames, by setting the name ourself:--config "lib.name = '<lint_crate_name>'"
. Then we can just apply option 3 to confidently guess that the file actually exists and uses the name we expect.
Would you mind looking at option 4? It's totally fine if not, this is already a really nice addition to Marker. Option 2, 3 and 4 can also be added later :)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I can absolutely look into number 4, But I'd like to focus on getting this in and the user documentation ready first. I'm inclined to handle making this path more efficient as a separate issue, but If you think it should be part of this, I can work on it here.
I was trying to think if we'd get any real sandboxing type benefits from option 2, but I don't really see a point in making sure that some lints can't use build artifacts of others. it would just be more file system usage with little benefit. Besides, if there's one thing I learned writing C#, it's that windows doesn't like deeply nested files, so don't make folders unless you need them :)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
For me it's fine if we continue this implementation and do the path cleanup in a later PR. This system should have the same robustness level :)
Btw, can you also add a test case in the uilints crate? The CI checks that the cargo-marker crate builds on stable, we can use this to test that |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This version looks good to me, I have three comments, which will hopefully be simple. Thank you for writing the documentation!
docs/book/src/usage.md
Outdated
@@ -1,3 +1,29 @@ | |||
# Usage | |||
|
|||
This section is intended for users who want to install Marker and run provided lints. | |||
|
|||
## Controlling Marker Lints |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can you move this into a separate file/section in the usage folder? (Similar to #212)
And maybe Setting Lint Levels would be a more descriptive title
docs/book/src/usage.md
Outdated
Marker provides this functionality via the `#[register_tool()]` attribute currently available in | ||
[nightly](https://github.com/rust-lang/rust/issues/66079). If your crate is compiled using nightly, then controlling | ||
lints is as simple as placing `#![feature(register_tool)]` and `#![register_tool(marker)]` at the top of your crate | ||
`lib.rs` or `mod.rs` file. You can then use all of the normal lint attributes you might usually use, on marker provided | ||
lints, like `#[allow(marker::my_lint)]`. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I would make this statement a bit stronger, saying that rustc requires the feature. Maybe:
Marker's lints use the `marker::` tool prefix. Rustc requires the [`register_tool` feature](https://github.com/rust-lang/rust/issues/66079) to allow this prefix in the normal lint level attributes, like `#[allow(...)]` and `#[deny(...)]`....
Marker's lints use the
marker::
tool prefix. Rustc requires theregister_tool
feature to allow this prefix in the normal lint level attributes, like#[allow(...)]
and#[deny(...)]
....
It's likely that most projects use a stable version by default. It would be nice to have a small code block, which could be directly copied. This should probably work:
#[cfg_attr(marker, feature(register_tool))]
#[cfg_attr(marker, register_tool(marker))]
@xFrednet I know I've been absent from the project for a minute. I'm going on vacation after this week and would like to get this in, rather than leave you hanging waiting on the few changes left on here. I plan to rebase to current and make the changes mentioned above, is there anything else? I saw you self-assigned a few days ago. |
bd9d3c6
to
793ff79
Compare
Hey @NathanFrasier, no problem at all, thank you for coming back and wanting to finish it! This week, I'm also taking it a bit easy. For the PR, only the documentation and test update were left. I'll review your rebased changes tomorrow. The self assignment, was just to give me an overview :) |
58abfd1
to
3977556
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thank you! This version looks perfect, I just have three small remarks about the docs. Do you have the time to push an update before your vacation? Otherwise, I'm more than happy to merge this and add them on master. The implementation is really solid, and I'm looking forward to including this in v0.2.0
3977556
to
77993c1
Compare
77993c1
to
1fb3b1e
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This version looks excellent, thank you for working on this issue and finishing the PR!
Enjoy your vacation! ⛱️
bors r+
Build succeeded! The publicly hosted instance of bors-ng is deprecated and will go away soon. If you want to self-host your own instance, instructions are here. If you want to switch to GitHub's built-in merge queue, visit their help page. |
This is a little rough. I feel like there has to be a better way to get rid of some of the calls to
.push()
and.extend()
but I wasn't thinking of them.This still needs documentation as well.
Addresses #201