EmbarkStudios / rust-gpu

🐉 Making Rust a first-class language and ecosystem for GPU shaders 🚧
https://shader.rs
Apache License 2.0
7.29k stars 246 forks source link

Compile with Proc Macro #1126

Closed coolcatcoder closed 8 months ago

coolcatcoder commented 8 months ago

I notice that in the getting started guide, it says you must use the same rustc version that it is expecting. Could we have a proc macro that takes a path to a rust file, and then compiles it using the correct rustc version, and then returns the compiled stuff? (Sorry for sounding so vague, I just started reading the getting started guide, so I don't really know what I'm talking about, lol.) This seems like it should be simple by using Command::new("rustc") in some way.

charles-r-earp commented 8 months ago

Not really. spirv-builder invokes cargo with rustc_codegen_spirv as the backend for rustc. rustc_codegen_spirv links directly to rustc internals, and these are very unstable, so this needs to be the exact same toolchain, not just a nightly. So in theory spirv-builder itself could use an arbitrary toolchain, stable even, but rustc_codegen_spirv must be used with the same nightly it was compiled with. Proc macros are more or less supposed to consume and produce tokens, though some do read from files or even compile source code.

coolcatcoder commented 8 months ago

Surely there would be some way to check what toolchain it needs, and then check if it installed, and if not install it, then compile with that toolchain. It might be janky, but I reckon it would be possible. I'll close for now, but I'll mess around with it and see if I can get a basic implementation working.