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

Expose the C runtime library to Rust library users #314

Merged
merged 2 commits into from
Mar 29, 2024
Merged

Expose the C runtime library to Rust library users #314

merged 2 commits into from
Mar 29, 2024

Conversation

Alex-Fischman
Copy link
Contributor

Adds a c_runtime function.

@sampsyo
Copy link
Owner

sampsyo commented Mar 26, 2024

Ah, looks interesting! I can see potentially how this would be useful—any chance you could write a few sentences about the use case and why it's helpful to have this embedded in the library/executable instead of on the filesystem?

One somewhat annoying thing: the path ../rt.c depends on the directory where rustc is run. It will run into problems when, for example, doing cargo publish. I think the solution is to use the $CARGO_MANIFEST_DIR environment variable, which Cargo sets to the appropriate path. This SO answer suggests one possible way, for instance. Can you give that a try and see if it works the way you expect?

@Alex-Fischman
Copy link
Contributor Author

This is useful because the alternative for library users is to go into this repo, download the file, and then move it into their repository. However, this will fail if this repo ever changes rt.c, because the local copy will not match. This is reasonably likely to happen in the future, for example if char becomes supported rt.c will need to add _bril_print_char.

@Alex-Fischman
Copy link
Contributor Author

It's also useful as a way to remind maintainers that rt.c is a necessary part of the API for brilift.

@Pat-Lafon
Copy link
Contributor

This is useful because the alternative for library users is to go into this repo, download the file, and then move it into their repository. However, this will fail if this repo ever changes rt.c, because the local copy will not match. This is reasonably likely to happen in the future, for example if char becomes supported rt.c will need to add _bril_print_char.

Maybe not the best solution but if you include bril as a git-submodule and then add it via a path versus having cargo look at git directly, you can have a symlink to rt.c in your repository. It also exists at a deterministic location on your machine in $HOME/.cargo/ though maybe that is a little less clean

@Alex-Fischman
Copy link
Contributor Author

We've considered using git submodules for our project, but the consensus was that they can be fragile and hard to fix. This seems like a cleaner solution.

@sampsyo
Copy link
Owner

sampsyo commented Mar 29, 2024

Looks good; thank you for the extra explanation and the environment-variable magic to make this more portable!

One day, I think it would be great if the Rust runtime (rt.rs) could be made useful for the AOT compiler, but that is probably more trouble than it's worth…

@sampsyo sampsyo merged commit b20cc2d into sampsyo:main Mar 29, 2024
16 checks passed
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.

3 participants