Open RyanGlScott opened 11 months ago
A related issue is that the name of the JSON file includes a cargo-generated hash that changes sometimes, such as when adding a library dependency, so we may need saw-build
to copy the file to a more predictable path.
Another option would be to have cargo saw-run foo.saw
actually invoke saw foo.saw
, but with an additional variable in the initial scope that gives the path to the JSON file. This might require adding a SAW command-line option along the lines of gcc/clang's -D NAME=VALUE
.
Is there always only a single .linked-mir.json
file in the target/<target>/<profile>/deps
directory?
That's right. mir-json
takes all of the intermediate build artifacts and links them together into a single .json
file at the end.
This is an awful hack but it seems to work
json_path <- exec "find" ["target/<target>/<profile>/deps", "-name", "<crate>*.linked-mir.json", "-printf", "%p"] "";
m <- mir_load_module json_path;
It's probably a better idea just to have mir-json
output it to a fixed path like <crate>.linked-mir.json
or something though.
Is there always only a single
.linked-mir.json
file in thetarget/<target>/<profile>/deps
directory?
On a clean build, there will be only one. But the filename includes a hash of crate metadata, so if you build, add/remove a dependency, and build again, you might end up with two different .linked-mir.json
files.
Currently, the process of going from a Rust project to a SAW file is somewhat clunky. You must undergo the following steps:
cargo saw-build
.linking <N> mir files into example.linked-mir.json
.example.linked-mir.json
file name from the build output..saw
file containingmir_load_module "example.linked-mir.json"
.This is all doable, but a bit tiresome. It would be convenient to have a
cargo run-saw
command that automates the process. That is, starting from a Rust project,cargo run-saw
would build the code, grab the name of the resulting MIR JSON file, and then emit a.saw
template that already contains the appropriate call tomir_load_module
. From there, users can build upon the.saw
template further, and if they need to rebuild their Rust code, they can usecargo saw-build
instead ofrun-saw
.This idea is similar in spirit to
cargo crux-test
's ability to generate a separate test script involving the compiled MIR JSON file, except thatrun-saw
's functionality would be separate fromsaw-build
.