Runtime compilation of Rust for testing


I’m developing a library in Rust for efficient mathematical computation. Essentially, I want to make it agnostic to any languages (e.g. it will possible be a binary + API) and it will be able (at least for now) to do source code generation to different languages. This will be done using some form of optimisation on the compute graph as well as producing good code on the source side. However, for testing this I can try to look at the intermediate compute graph, but that always changes and is not too reliable for testing. I would like to run several computations on my own, get the results, and during test after I apply the optimisation to generate Rust code for the computation, compile it, run it with some predefine examples and compare to answers to the one are also predefined as correct. Does anyone know how to do the runtime compilation and call part of the produced Rust code?