Repository navigation
feat: add syntax macro + maintenance - #764
Conversation
| license.workspace = true | ||
| repository.workspace = true | ||
| description = "Syntax macro for SmallVec" | ||
| publish = false |
There was a problem hiding this comment.
Won't this make it impossible to publish a new version of smallvec?
There was a problem hiding this comment.
yes, I just checked with cargo package. but because it uses a path import on ./Cargo.toml
I'll find another way
Signed-off-by: Alejandro Vaz <alejandro.vaz.myt@gmail.com>
| // Compile the bundled macro directly so it does not need to be published | ||
| // as a separate Cargo package. | ||
| let manifest_dir = PathBuf::from(env::var_os("CARGO_MANIFEST_DIR").unwrap()); | ||
| let out_dir = PathBuf::from(env::var_os("OUT_DIR").unwrap()); | ||
| let status = Command::new(env::var_os("RUSTC").expect("Cargo must set RUSTC")) | ||
| .current_dir(&manifest_dir) | ||
| .args([ | ||
| "--crate-name=syntax", | ||
| "--crate-type=proc-macro", | ||
| "--edition=2024", | ||
| "--extern=proc_macro", | ||
| "syntax.rs", | ||
| "--out-dir" | ||
| ]) | ||
| .arg(&out_dir) | ||
| .status() | ||
| .expect("failed to run rustc for the syntax proc-macro"); | ||
|
|
There was a problem hiding this comment.
Building a separate crate inside of the build script for this crate is wild. What's the problem with using the proc macro crate as a real dependency that gets published? I don't think trying to work around that is a good idea.
There was a problem hiding this comment.
do we really want to publish another crate??
if we are willing to do that we may as well simply use https://crates.io/crates/add-syntax which does exactly that
what we have is basically a copy-paste of it
we can either:
- hack ourselves around it
- make a
smallvec-macrocrate that would be really weird - use that crate with 3k total downloads
honestly I like the first alternative more than either of the other two
There was a problem hiding this comment.
on #754 it allows us to have conditional exports by prepending pub to our current implementations instead of having to duplicate the code. since there is at least 5-10 methods in which we have that kind of conditional visibility, that can easily be 100-200 lines of code that we have to maintain in sync but that is otherwise the same
on #762 it removes the necessity of having to add a separate impl block by adding the conditional unsafe and the conditional may_dangle. all else stays the same. it saves around 45 lines of code
There was a problem hiding this comment.
the current implementations of those PRs which I delayed simply duplicate code which makes it a significant burden on maintenance, goes against DRY, bloats the codebase, and can be a painful source of errors if we don't keep them in sync
I don't think it's worth publishing a new crate, and using the 3k downloads one is very risky, whilst doing it like this is not very complex and just works
There was a problem hiding this comment.
not that sure of the impact I mentioned on #754 (I believe it is not complete, because we would also have to modify rawsmallvec and a few more things), would have to check it again, but key idea is that it removes duplication
There was a problem hiding this comment.
I am strongly against running rustc from a build script. If we want the macro and don't want to take on the external dependency then we should publish the crate.
To make my objections more concrete: I worry about the impact on any non-default build configuration like cross-compilation, or changes to Rust/cargo build defaults, or interactions with RUSTFLAGS, etc. We should stay on the supported path of using a proc macro crate dependency with cargo.
There was a problem hiding this comment.
that makes sense
it's a shame because it's just a little tiny helper
we then have two alternatives:
- make our own
smallvec-macrocrate for helpers, or however we want to call it - use
add-syntaxand pin it down
will we need additional procedural macros for smallvec?? maybe, I wouldn't discard it. so I think we should go with smallvec-macro then
agree??
There was a problem hiding this comment.
I'm ok with a new smallvec-macro crate!
Signed-off-by: Alejandro Vaz <alejandro.vaz.myt@gmail.com>
Signed-off-by: Alejandro Vaz <alejandro.vaz.myt@gmail.com>
this PR adds a small private procedural macro that allows for syntax inserting like the
add-syntax::prependmacro doesit reduces code bloat by conditionally inserting syntax where needed, ensuring the codebase is DRY. unblocks #754 and #762
other maintenance changes
proptestrequiresstdlib.rs