Skip to content

Use single Rust staticlib for FFI #9588

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

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

mszabo-wikia
Copy link
Contributor

Currently, each Rust FFI library is built and linked into the HHVM binaries as separate static libraries. This is explicitly unsupported by the cxx crate, which recommends either using rustc as the final linker or using a single Rust staticlib for the Rust components, and has been the cause of linking errors for the last couple of years (see T146965521).

The former does not seem to be feasible for HHVM OSS, so go with the latter approach and combine Rust FFI libraries into a single staticlib, then link that into HHVM. This will likely need corresponding changes in the internal buck2 build.

Currently, each Rust FFI library is built and linked into the HHVM
binaries as separate static libraries. This is [explicitly
unsupported](https://cxx.rs/build/other.html#linking-the-c-and-rust-together)
by the `cxx` crate, which recommends either using rustc as the final
linker or using a single Rust staticlib for the Rust components, and has
been the cause of linking errors for the last couple of years (see
T146965521).

The former does not seem to be feasible for HHVM OSS, so go with the
latter approach and combine Rust FFI libraries into a single staticlib,
then link that into HHVM. This will likely need corresponding changes in
the internal buck2 build.
@facebook-github-bot
Copy link
Contributor

@facebook-github-bot has imported this pull request. If you are a Meta employee, you can view this diff on Phabricator. (Because this pull request was imported automatically, there will not be any future comments.)

@mszabo-wikia
Copy link
Contributor Author

Gentle ping for @dtolnay—I'm curious whether you think this approach might be feasible. I find it a bit curious that the present arrangement worked for as long as it did (until 4b12ed4 / 90d3e33) despite multiple staticlibs being linked even before that. Although in fairness the docs do say that "[multiple staticlibs] are likely to conflict" rather than "will conflict", so perhaps it was just the straw that broke the camel's back.

Copy link

@dtolnay dtolnay left a comment

Choose a reason for hiding this comment

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

The internal build uses Buck2 "advanced unstable linking" which correctly handles arbitrary dependency graphs between Rust and C++.

I don't work on HHVM but the HHVM team will need to decide whether it's time to move the OSS build to Buck2, instead of this PR.

@mszabo-wikia
Copy link
Contributor Author

Thanks for your quick response! This is exactly the kind of valuable context I was looking for.

I'm fine with either a continuation of the preexisting CMake-based approach (#9564 takes care of most build issues) or a community-driven Buck2 build.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants