Skip to content

Commit d0c34d5

Browse files
thoughtpolicenagisa
authored andcommitted
psm: allow manual opt out of #cfg[link("psm_s")]
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]>
1 parent 9f8cf8f commit d0c34d5

File tree

2 files changed

+3
-2
lines changed

2 files changed

+3
-2
lines changed

psm/build.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ fn find_assembly(
77
env: &str,
88
masm: bool,
99
) -> Option<(&'static str, bool)> {
10-
println!("cargo::rustc-check-cfg=cfg(switchable_stack,asm)");
10+
println!("cargo::rustc-check-cfg=cfg(switchable_stack,asm,link_asm)");
1111
match (arch, endian, os, env) {
1212
// The implementations for stack switching exist, but, officially, doing so without Fibers
1313
// is not supported in Windows. For x86_64 the implementation actually works locally,
@@ -79,6 +79,7 @@ fn main() {
7979

8080
let asm = if let Some((asm, canswitch)) = find_assembly(&arch, &endian, &os, &env, masm) {
8181
println!("cargo:rustc-cfg=asm");
82+
println!("cargo:rustc-cfg=link_asm");
8283
if canswitch {
8384
println!("cargo:rustc-cfg=switchable_stack")
8485
}

psm/src/lib.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,7 @@ macro_rules! extern_item {
5656
// NB: this could be nicer across multiple blocks but we cannot do it because of
5757
// https://github.com/rust-lang/rust/issues/65847
5858
extern_item! { {
59-
#![cfg_attr(asm, link(name="psm_s"))]
59+
#![cfg_attr(link_asm, link(name="psm_s"))]
6060

6161
#[cfg(asm)]
6262
fn rust_psm_stack_direction() -> u8;

0 commit comments

Comments
 (0)