yew icon indicating copy to clipboard operation
yew copied to clipboard

yew-macro: remove transitive dependency on syn 1

Open Alextopher opened this issue 1 year ago • 4 comments

Description

I've been enjoying yew and wanted to find a place I could make small contributions. I'm happy to put in some effort to remove duplicate dependencies.

There's a rustsec release out on proc-macro-error, the issue being the crate is unmaintained. Potential replacements include proc-macro-error2 which seems to be API compatible. proc-macro-error2 also removes some needless build scripts improving compilation times.

Overall, replacing proc-macro-error with proc-macro-error2 leads to an 8% reduction in (single threaded) compilation of yew.

cargo build --release --timings -j1 results below.

Before image

After image

Checklist

The existing test suite passes, I don't believe there is a test I could write for this PR.

Before

$ cargo tree -d | grep syn
syn v1.0.109
syn v2.0.79

After

$ cargo tree -d | grep syn

Alextopher avatar Oct 21 '24 13:10 Alextopher

I think this will fix the nightly test, but will trigger stable failures.

Alextopher avatar Oct 21 '24 16:10 Alextopher

Using yew-nightly as a cargo feature means using the --all-features flag on stable causes build failures. I imagine that could be a pretty big cost, and might be why you use cargo attributes instead.

Maybe it's possible to remove usage of nightly features from proc-macro-errors2 but that was out of scope of my original goal.

I'm sorry, I'm not sure how else to work around this.

Alextopher avatar Oct 21 '24 16:10 Alextopher

Further research - removal of those build scripts I was speaking of (in favor of using a feature nightly) means we can't just drop-in replace yew's usage of proc-macro-error with proc-macro-error2.

Maybe we could use a build script to enable that feature using the version-check crate. Is there some way to conditionally enable a feature-flag based on the usage of a nightly compiler?

Alextopher avatar Oct 21 '24 16:10 Alextopher

I attempted a fix in 37452a5 but it seems cargo does not allow this: https://github.com/rust-lang/cargo/issues/8170

We cannot switch to using feature flag for nightly (see https://github.com/yewstack/yew/issues/2754). I wanted to use buildscript to enable the feature but that is not possible either. I raised https://github.com/GnomedDev/proc-macro-error-2/issues/7 to allow using cfg here, which can be used from build.rs

ranile avatar Dec 13 '24 09:12 ranile