-
Notifications
You must be signed in to change notification settings - Fork 57
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
psm: allow manual opt out of #cfg[link("psm_s")]
#95
psm: allow manual opt out of #cfg[link("psm_s")]
#95
Conversation
Err, well, I shouldn't be looking at code when its one past midnight outside. I'll look at this again tomorrow. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The only thing I think would be an improvement here is to invert the newly added cfg here, have the build.rs script enable it whenever this link(...)
attribute has to be emitted.
So the code in psm/src/lib.rs
looks more like
#![cfg_attr(link_asm, link(name="psm_s"))]
and then in your buck2-specific build.rs you can remove the print that enables the cfg. Since build.rs
is going to have a println!
to enable emission of this attribute, that is going to be a perfect location to also add a short comment motivating the split of attributes (just one sentence is fine.)
That said, there is one important detail. Not using link(...)
on extern
is actually depriving rustc of sufficient information to correctly invoke the linker. Unless you're invoking the linker directly, omitting this isn't actually correct.
OK, thanks! I wasn't sure if you wanted it on or off by default, but I can make that change.
Yeah, speaking briefly, in Buck the dependency graph might look something like The real thing is mainly just that the library name can't be made identical to |
Currenty, when using the `asm` configuration, the `lib.rs` file will manually add a `link("psm_s")` attribute to the build causing a flag like `-lpsm_s` to appear on the link line. `psm_s` is the library of assembly code, built by `build.rs` in Cargo projects. However, when using Cargo packages with build systems like Buck2, we have to manually replace the `build.rs` script, and build the bits of C/assembly code that come with `psm` and `stacker` as a separate build item (an actual library), then link them into the Rust libraries. The name of the library often can't be easily made identical to `psm_s` as desired by the `link()` call, meaning that just blindly compiling this crate causes an inevitable linking failure. But we're building the code and explicitly linking the library anyway, removing the need for this `#[link]` clause. Therefore, introduce a new `link_asm` cfg option to give "expert" users the ability to link in code manually. This is always enabled by the Cargo build for `asm`-compatible targets, but Buck users can leave it off. Signed-off-by: Austin Seipp <[email protected]>
bc1c9d7
to
dc3e1ad
Compare
Fixed with your review comments. |
Currenty, when using the
asm
configuration, thelib.rs
file will manually add alink("psm_s")
attribute to the build causing a flag like-lpsm_s
to appear on the link line.psm_s
is the library of assembly code, built bybuild.rs
in Cargo projects.However, when using Cargo packages with build systems like Buck2, we have to manually replace the
build.rs
script, and build the bits of C/assembly code that come withpsm
andstacker
as a separate build item (an actual library), then link them into the Rust libraries.The name of the library often can't be easily made identical to
psm_s
as desired by thelink()
call, but we're building and explicitly linking the library anyway, removing the need for this.Therefore, introduce a new
asm_manual_link
cfg option to give "expert" users the ability to link in code manually.