Stream: wasi

Topic: proc macro - recompile if witx changes


view this post on Zulip Pat Hickey (Jan 24 2020 at 00:53):

something I just ran into - the wiggle proc macro that i'm working on with @kubkon, as an eventual replacement for wig, needs to be rerun if the witx file it reads in changes.

view this post on Zulip Pat Hickey (Jan 24 2020 at 00:54):

the suggested solution here is to use include_str https://users.rust-lang.org/t/equivalent-of-cargo-rerun-if-changed-for-procedural-macros/37036 - however I cant rewrite the file loading logic in terms of include_str because witx contains use directives that point to other files.

Hello there 👋 I'm currently writing a procedural macro that looks like my_macro!("../foo/bar"). It performs some computation on the files within the ../foo/bar directory, then "returns" the outcome. It works fine, except that I would like the code that calls this macro to be recompiled if the content of foo/bar changes. In other words, I would like an equivalent to printing cargo:rerun-if-changed from a build script but for procedural macros. As a tentative solution, I've tried tweakin...

view this post on Zulip Pat Hickey (Jan 24 2020 at 00:56):

is this issue on the radar for cargo / rustc teams? @Alex Crichton @Josh Triplett

view this post on Zulip Pat Hickey (Jan 24 2020 at 01:21):

and on the same lines - is any work underway on making proc macro error messages show the actual tokens that caused it? basically my workflow now is to get an error out of cargo build and then go hunting through cargo expand's output to guess what may have caused it

view this post on Zulip Alex Crichton (Jan 24 2020 at 01:50):

@Pat Hickey this isn't currently on the radar, no, unfortunately

view this post on Zulip Alex Crichton (Jan 24 2020 at 01:50):

currently if the tokens are purely synthesized by a macro I don't think there's a way to get spans to point at those tokens

view this post on Zulip Alex Crichton (Jan 24 2020 at 01:51):

but calling .to_string().parse() may be a lil better, in general debugging proc macros isn't a great experience :(

view this post on Zulip Alex Crichton (Jan 24 2020 at 01:51):

the sol'n for rerunning would actually probably be on the rustc side of things, a function in the proc_macro crate itself most likely

view this post on Zulip Alex Crichton (Jan 24 2020 at 01:51):

(or something like that)

view this post on Zulip Pat Hickey (Jan 24 2020 at 01:51):

i read something in the cargo expand docs that basically said that the string repr it gives is lossy, and may not even show the same error

view this post on Zulip Alex Crichton (Jan 24 2020 at 01:51):

that is true yeah, primarily b/c of hygiene I believe

view this post on Zulip Alex Crichton (Jan 24 2020 at 01:51):

although there may be other subtelties I'm forgetting

view this post on Zulip Pat Hickey (Jan 24 2020 at 01:52):

yeah its probably something like that but i dont fully understand the hygiene story... this is my first time really using proc macros

view this post on Zulip Alex Crichton (Jan 24 2020 at 01:52):

unforutnately I don't know a great workaround for the "rerun on witx file change"

view this post on Zulip Pat Hickey (Jan 24 2020 at 01:52):

and yeah the debug experience is less than great presently. not quite bad enough to switch to just printing a syntax tree... but not great

view this post on Zulip Alex Crichton (Jan 24 2020 at 01:52):

other than having the proc-macro also have a build script which prints the various directives

view this post on Zulip Alex Crichton (Jan 24 2020 at 01:53):

you can typically fiddle around with spans enough to get user input to show the right errors

view this post on Zulip Alex Crichton (Jan 24 2020 at 01:53):

but not afaik for code synthesized by the macro tiself

view this post on Zulip Pat Hickey (Jan 24 2020 at 01:53):

right

view this post on Zulip Pat Hickey (Jan 24 2020 at 01:54):

well, ill keep at it for now

view this post on Zulip Pat Hickey (Jan 24 2020 at 01:54):

too many things on my plate to take any side tracks into rustc to see if i can make the debug experience better


Last updated: Dec 23 2024 at 12:05 UTC