I'm interested in embedding Rust (or more precisely, rustc) in my app much like one might embed Lua (which I have done). That is, users of the app would write rust code in the app. To avoid crashes, would have to disable unsafe. I can't invoke rustc and dynamically load the result because my app runs on iOS, where I can't launch processes.
You can do this, but it will take a fair bit of effort. Rustc exposes an interface through rustc_driver: rustc_driver and rustc_interface - Rust Compiler Development Guide
Rustc is more of a framework than a library; I'm not sure how easy it will be to embed it in another application. Note also that this will tie you to a specific version of the toolchain; if you want to update to a newer toolchain you'll have to also update your code to deal with breaking changes in the compiler interface.
Note also that if you can't launch processes you probably won't be able to use the LLVM backend, which uses the system linker. I think Cranelift has a JIT mode but I think that may also be banned by Apple's policies?
That seems possible, yes, Cranelift has a wasm backend. I haven't tried to use it but I know Fastly at least uses it in production and sponsors the work.
That looks quite nice (and perhaps I should have used that instead of Lua), but this is for writing DSP kernels so it should be statically typed and fast at least on some platforms where I can JIT.
I also recently looked into scripting support, but unlike you I'm not targeting a platform that doesn't allow me to spawn new processes. I stumbled across Extism in a Hacker News post, which allows you to embed WASM into your application. Looks fairly easy to embed a (simple) WASM file and execute a function from it. This section makes me believe that Extism can even run WebAssembly that uses WASI. I don't know how you'd get the Rust code compiled to WASM on iOS though...
As an aside, you're going to want to sandbox it anyway. There's more types of crashes than UB, and even if you don't care about that, rustc/stdare not soundness bug free.
Can you elaborate a bit? I can't sandbox anything on iOS since I can't use a separate process. That rustc could crash my app due to a bug is ok. I bet rustc is more stable than some of the 3rd party libraries I use, and my own code as well.
Also, another problem which I forgot to mention earlier is that I have to ensure the code doesn't run too long and lock up the audio thread. So I would have to get rustc to instrument the code with the occasional timer check. Currently I do that with Lua using a "debug hook."
It sounded like you wanted to modify the compiler to restrict what your users could do. If you don't care about crashes (e.g. users can only hurt themselves by writing bad code), it may not matter (but then why modify the compiler?).