Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Working with cargo #47

Merged
merged 20 commits into from
Feb 17, 2025
Merged

Working with cargo #47

merged 20 commits into from
Feb 17, 2025

Conversation

dkcumming
Copy link
Collaborator

@dkcumming dkcumming commented Feb 13, 2025

This didn't end up looking anything like what I had imagined. But I was having a lot of trouble getting this working at all and I may have had my environment set up in a way that was self defeating as I feel I suddenly started having things work when trying the same thing. Not sure.

But right now this is creating a .stable_mir_json directory at a given directory or ~/.stable_mir_json directory (linux only right now) and that is populated with the binary for stable_mir_json, a file containing the LD_LIBRARY_PATH that was used to create the binary, and scripts to set the library path so that RUSTC can be overwritten when calling cargo.

To test this out:

  1. Fetch and switch to this branch
  2. run cargo build and cargo build --release
  3. run cargo run --bin cargo_stable_mir_json -- $PWD [optional-dir-path] from the root of the repo (this creates .stable_mir_json)
  4. create or navigate to another cargo project you want to test
  5. run RUSTC=~/.stable_mir_json/debug.sh cargo build (or the file that .stable_mir_json was built in). Or for release RUSTC=~/.stable_mir_json/release.sh cargo build

Fixes #39

Currently defaulting to `stable_mir_json` which is this package that runs
`main.rs`. But if flag `--bin cargo_stable_mir_json` is added it runs the
`src/bin/cargo_stable_mir_json.rs`
@dkcumming dkcumming self-assigned this Feb 13, 2025
Copy link
Member

@jberthold jberthold left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Comments are a few nit-picks on details...
The approach as a whole seems reasonable for distribution - maybe there would be a more canonical way to place things inside $HOME/.cargo but if this works we can go with this for now.

Can you add a usage example here, and a description in the README.md?

@jberthold
Copy link
Member

Might be good to give users the option of a custom install path.

@dkcumming dkcumming marked this pull request as ready for review February 15, 2025 08:53
Copy link
Member

@jberthold jberthold left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sorry, I still have a few comments on details... and should we maybe add a smoke test in CI that runs this in docker and tries to use the resulting installation?

We can also merge this and refactor on a follow-up PR to make progress

fn setup(repo_dir: PathBuf, maybe_user_provided_dir: Option<PathBuf>) -> Result<()> {
let smir_json_dir = smir_json_dir(maybe_user_provided_dir)?;
println!("Creating {} directory", smir_json_dir.display());
std::fs::create_dir(&smir_json_dir)?; // This errors is the directory already exists
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This errors is the directory already exists ... not sure that's desirable. We can leave it that way for now, though...
Also, when I suggested the user-defined location I thought this would be the final destination, not that a directory would be created there.

dkcumming and others added 3 commits February 17, 2025 12:51
@dkcumming
Copy link
Collaborator Author

Added the other issue here #48

@dkcumming dkcumming merged commit c87f13c into master Feb 17, 2025
2 checks passed
@dkcumming dkcumming deleted the dc/cargo-stable-mir-json branch February 17, 2025 03:25
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Support calling smir_pretty from inside another cargo project
2 participants