#Dynamic JIT compilation of Rust string at runtime without external commands like rustc

4 messages · Page 1 of 1 (latest)

spring rampart
#

My goal is to be able to compile a string of code, for example

fn main() {
    println!("Hello, world!");
}```
Dynamically at runtime for an end user who does not have rust compilation software installed.
Then hopefully I could save this to a new executeable. Im not well versed in rust so maybe there is an easy souloution to this.

After consulting AI, libraries like rustc embedded inside the crate were reccomended, yet none seemed to exist. I also looked into LLVM libraries, they didnt seem to do what I wanted either.

I am using a windows 64 bit system and hopefully the compiled file should be compatible.
crude hound
#

There is a rustc crate, but there are some caveats:

  • It's not on crates.io (since everyone has it installed anyway)
  • It's unstable (possibly forever)
  • You need a nightly toolchain
  • you need to opt-in to #!feature(rustc_private)
#

Do you specifically need the full rust language embedded?

#

Also, embedding the full compiler probably makes for a big binary