-
-
Notifications
You must be signed in to change notification settings - Fork 115
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
Figure out a better story around optional proc_macro #139
Comments
I would put this effort into rust-lang/rust#49219 instead. In a perfect world:
|
To pave a way to not use |
^ @eddyb any issues with providing token stream parsing in proc_macro to make it possible to use standalone from a build script or main.rs? |
IIRC there was some resistance to supporting Perhaps we could factor out the pieces of Unless we can do that, I think we're going to continue to need |
@mystor If a binary crate depends on proc_macro, wouldn't only the parts of libsyntax that are used by proc_macro end up in the result? How would we do better by refactoring libsyntax? This seems like the intended behavior. |
Currently libsyntax is a dylib, so depending on it would create a dynamic dependency, rather than a static one. We'd have to be able to link libsyntax both statically & dynamically IIRC. |
@dtolnay It's not just parsing, @alexcrichton was summarizing. It's an RPC system with compiler objects being controlled from the proc macro client. However, with that PR, anyone (on nightly) can use the So if you really wanted, you could put a copy of Beware of putting the public The whole system is hardened pretty well, no client will ever see the same object handle being used more than once, so cross-session object use will deterministically result in a panic inside the server, which will be propagated to the client - but it is a potential footgun. Also, yes, I still need to finish that PR... |
I think that would be a potential solution here to eliminate proc-macro2. It would be nice to have some mechanism for proc_macro-based code to run as a standalone library without dynamically linking to or using RPC to talk to the compiler in any way. From my POV, the nicest solution there would be to have a fallback "loopback" server built into proc_macro which is used when there is no compiler session, and doesn't work against real rustc objects. This would have to be done within rustc itself, as we wouldn't want to require an perma-unstable API to do this. I don't think the way that proc-macro2 implements it is a solution we'd want to upstream, but if we want to do that I can try to find some time to write up a cleaner & more maintainable loopback implementation.
❤️ |
It'd be done entirely within |
@eddyb yup, that's more accurate. Should've said something like "within rust-lang/rust" or "not crates.io" :-) |
Any update on this? I was rather disappointed to find that many of the programs I use fail to compile on my new musl based system due to this crate. |
@ifreund proc-macros work on musl / Alpine if you set |
@kevinmehall thats great to hear thanks! |
Registering @alexcrichton's ideas from #137 (comment) so they don't get lost:
We've got the following state of affairs:
proc_macro
proc_macro2
doesn't link toproc_macro
then the dependencies ofproc_macro2
aren't ready for that.I think it's sort of a bummer that this crate doesn't work by default on the standard musl target, and I think it'd be great to fix this. Here's an idea, though, of how we could get this working:
proc_macro
links = "proc-macro2-04x"
proc_macro
syn
have a build script.syn
reads the env varDEP_PROC_MACRO2_04X
, learning about whetherproc_macro
was linked.syn
's build script then prints out something likecargo:rustc-args=--cfg proc_macro_works
and is compiled appropriatelyThis is sort of heinously complex unfortunately though. It also requires this crate's build script to figure out whether to depend on
proc_macro
or not (which I'm not sure how to do)The text was updated successfully, but these errors were encountered: