Skip to content

Commit be00ad7

Browse files
committed
Explicilty list .a paths for rdma
Make sure we link to the rdma libraries we built. Ensure we do not pick up something with additional library requiements (libnl). Differential Revision: [D89575917](https://our.internmc.facebook.com/intern/diff/D89575917/) **NOTE FOR REVIEWERS**: This PR has internal Meta-specific changes or comments, please review them on [Phabricator](https://our.internmc.facebook.com/intern/diff/D89575917/)! ghstack-source-id: 330569694 Pull Request resolved: #2193
1 parent 2f9570e commit be00ad7

File tree

3 files changed

+43
-39
lines changed

3 files changed

+43
-39
lines changed

build_utils/src/lib.rs

Lines changed: 23 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -352,44 +352,43 @@ pub fn link_libstdcpp_static() {
352352
/// Configuration for rdma-core static libraries from monarch_cpp_static_libs.
353353
///
354354
/// Use `CppStaticLibsConfig::from_env()` to get the paths, then use the include
355-
/// paths for bindgen/cc, and call `emit_link_directives()` to link.
355+
/// directory for bindgen/cc, and call `emit_link_directives()` to link.
356356
pub struct CppStaticLibsConfig {
357-
pub rdma_include: String,
358-
pub rdma_lib_dir: String,
359-
pub rdma_util_dir: String,
357+
/// Include directory for rdma-core headers
358+
pub rdma_include_dir: String,
359+
/// Paths to static libraries (.a files) to link
360+
pub rdma_static_libraries: Vec<String>,
360361
}
361362

362363
impl CppStaticLibsConfig {
363364
/// Load configuration from DEP_* environment variables set by monarch_cpp_static_libs.
364365
///
365366
/// The monarch_cpp_static_libs crate must be listed as a build-dependency.
366367
pub fn from_env() -> Self {
368+
let rdma_include_dir = std::env::var("DEP_MONARCH_CPP_STATIC_LIBS_RDMA_INCLUDE_DIR")
369+
.expect("DEP_MONARCH_CPP_STATIC_LIBS_RDMA_INCLUDE_DIR not set - add monarch_cpp_static_libs as build-dependency");
370+
371+
let rdma_static_libraries = std::env::var("DEP_MONARCH_CPP_STATIC_LIBS_RDMA_STATIC_LIBRARIES")
372+
.expect("DEP_MONARCH_CPP_STATIC_LIBS_RDMA_STATIC_LIBRARIES not set - add monarch_cpp_static_libs as build-dependency")
373+
.split(';')
374+
.map(|s| s.to_string())
375+
.collect();
376+
367377
Self {
368-
rdma_include: std::env::var("DEP_MONARCH_CPP_STATIC_LIBS_RDMA_INCLUDE")
369-
.expect("DEP_MONARCH_CPP_STATIC_LIBS_RDMA_INCLUDE not set - add monarch_cpp_static_libs as build-dependency"),
370-
rdma_lib_dir: std::env::var("DEP_MONARCH_CPP_STATIC_LIBS_RDMA_LIB_DIR")
371-
.expect("DEP_MONARCH_CPP_STATIC_LIBS_RDMA_LIB_DIR not set - add monarch_cpp_static_libs as build-dependency"),
372-
rdma_util_dir: std::env::var("DEP_MONARCH_CPP_STATIC_LIBS_RDMA_UTIL_DIR")
373-
.expect("DEP_MONARCH_CPP_STATIC_LIBS_RDMA_UTIL_DIR not set - add monarch_cpp_static_libs as build-dependency"),
378+
rdma_include_dir,
379+
rdma_static_libraries,
374380
}
375381
}
376382

377383
/// Emit all cargo link directives for static linking of rdma-core.
378384
///
379-
/// This emits search paths and link-lib directives for:
380-
/// - libmlx5.a
381-
/// - libibverbs.a
382-
/// - librdma_util.a
385+
/// This uses direct paths to the .a files we built, avoiding any path ordering
386+
/// issues where the linker might find system libraries or libraries built with
387+
/// different flags (e.g., ENABLE_RESOLVE_NEIGH=1).
383388
pub fn emit_link_directives(&self) {
384-
// Emit link search paths
385-
println!("cargo::rustc-link-search=native={}", self.rdma_lib_dir);
386-
println!("cargo::rustc-link-search=native={}", self.rdma_util_dir);
387-
388-
println!("cargo::rustc-link-lib=static=mlx5");
389-
println!("cargo::rustc-link-lib=static=ibverbs");
390-
391-
// rdma_util helper library
392-
println!("cargo::rustc-link-lib=static=rdma_util");
389+
for lib_path in &self.rdma_static_libraries {
390+
println!("cargo::rustc-link-arg={}", lib_path);
391+
}
393392
}
394393
}
395394

@@ -401,7 +400,7 @@ impl CppStaticLibsConfig {
401400
/// Example:
402401
/// ```ignore
403402
/// let config = build_utils::setup_cpp_static_libs();
404-
/// // Use config.rdma_include for bindgen/cc
403+
/// // Use config.rdma_include_dir for bindgen/cc
405404
/// ```
406405
pub fn setup_cpp_static_libs() -> CppStaticLibsConfig {
407406
let config = CppStaticLibsConfig::from_env();

monarch_cpp_static_libs/build.rs

Lines changed: 19 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -247,27 +247,32 @@ fn emit_link_directives(rdma_build_dir: &Path) {
247247
let rdma_static_dir = rdma_build_dir.join("lib/statics");
248248
let rdma_util_dir = rdma_build_dir.join("util");
249249

250-
// Emit search paths
251-
println!(
252-
"cargo:rustc-link-search=native={}",
253-
rdma_static_dir.display()
254-
);
255-
println!("cargo:rustc-link-search=native={}", rdma_util_dir.display());
256-
257-
println!("cargo:rustc-link-lib=static=mlx5");
258-
println!("cargo:rustc-link-lib=static=ibverbs");
250+
// Link directly to the specific .a files we built, rather than using search paths.
251+
// This avoids any path ordering issues where the linker might find system libraries
252+
// or libraries built with different flags (e.g., ENABLE_RESOLVE_NEIGH=1).
253+
let libmlx5_path = rdma_static_dir.join("libmlx5.a");
254+
let libibverbs_path = rdma_static_dir.join("libibverbs.a");
255+
let librdma_util_path = rdma_util_dir.join("librdma_util.a");
259256

260-
// rdma_util helper library
261-
println!("cargo:rustc-link-lib=static=rdma_util");
257+
println!("cargo:rustc-link-arg={}", libmlx5_path.display());
258+
println!("cargo:rustc-link-arg={}", libibverbs_path.display());
259+
println!("cargo:rustc-link-arg={}", librdma_util_path.display());
262260

263261
// Export metadata for dependent crates
264262
// Use cargo:: (double colon) format for proper DEP_<LINKS>_<KEY> env vars
265263
println!(
266-
"cargo::metadata=RDMA_INCLUDE={}",
264+
"cargo::metadata=RDMA_INCLUDE_DIR={}",
267265
rdma_build_dir.join("include").display()
268266
);
269-
println!("cargo::metadata=RDMA_LIB_DIR={}", rdma_static_dir.display());
270-
println!("cargo::metadata=RDMA_UTIL_DIR={}", rdma_util_dir.display());
267+
268+
// Export library paths as a semicolon-separated list
269+
let lib_paths = format!(
270+
"{};{};{}",
271+
libmlx5_path.display(),
272+
libibverbs_path.display(),
273+
librdma_util_path.display()
274+
);
275+
println!("cargo::metadata=RDMA_STATIC_LIBRARIES={}", lib_paths);
271276

272277
// Re-run if build scripts change
273278
println!("cargo:rerun-if-changed=build.rs");

rdmaxcel-sys/build.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ fn main() {}
1717
fn main() {
1818
// Get rdma-core config from cpp_static_libs (includes are used, links emitted by monarch_extension)
1919
let cpp_static_libs_config = build_utils::CppStaticLibsConfig::from_env();
20-
let rdma_include = &cpp_static_libs_config.rdma_include;
20+
let rdma_include = &cpp_static_libs_config.rdma_include_dir;
2121

2222
// Link against dl for dynamic loading
2323
println!("cargo:rustc-link-lib=dl");

0 commit comments

Comments
 (0)