fix release build failures due to libpython linking (#125)

This commit is contained in:
Josh Thomas 2025-04-30 15:02:00 -05:00 committed by GitHub
parent 9398df6a21
commit 7ef503d866
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
5 changed files with 42 additions and 17 deletions

View file

@ -26,22 +26,30 @@ pub fn setup_python_linking() {
// Get the Python interpreter configuration directly
let config = pyo3_build_config::get();
// Add the library search path if available
let is_extension_module = std::env::var("CARGO_FEATURE_EXTENSION_MODULE").is_ok();
// Only link libpython explicitly if we are NOT building an extension module.
if !is_extension_module {
if let Some(lib_name) = &config.lib_name {
println!("cargo:rustc-link-lib=dylib={}", lib_name);
} else {
// Warn only if linking is actually needed but we can't find the lib name
println!("cargo:warning=Python library name not found in config (needed for non-extension module
builds).");
}
}
// Add the library search path and RPATH if available.
// These are needed for test executables and potential future standalone binaries,
// and generally harmless for extension modules.
if let Some(lib_dir) = &config.lib_dir {
println!("cargo:rustc-link-search=native={}", lib_dir);
// Add RPATH linker argument for Unix-like systems (Linux, macOS)
// This helps the test executable find the Python library at runtime.
#[cfg(not(windows))]
println!("cargo:rustc-link-arg=-Wl,-rpath,{}", lib_dir);
} else {
println!("cargo:warning=Python library directory not found in config.");
}
// Add the library link directive if available
if let Some(lib_name) = &config.lib_name {
println!("cargo:rustc-link-lib=dylib={}", lib_name);
} else {
println!("cargo:warning=Python library name not found in config.");
// Warn only if linking is actually needed but we can't find the lib dir
if !is_extension_module {
println!("cargo:warning=Python library directory not found in config.");
}
}
}

View file

@ -3,6 +3,10 @@ name = "djls-project"
version = "0.1.0"
edition = "2021"
[features]
extension-module = []
default = []
[dependencies]
pyo3 = { workspace = true }
tower-lsp-server = { workspace = true, features = ["proposed"] }

View file

@ -3,6 +3,10 @@ name = "djls-server"
version = "0.1.0"
edition = "2021"
[features]
extension-module = []
default = []
[dependencies]
djls-conf = { workspace = true }
djls-project = { workspace = true }

View file

@ -7,11 +7,20 @@ edition = "2021"
name = "djls"
crate-type = ["cdylib"]
[features]
extension-module = [
"djls-server/extension-module",
"djls-project/extension-module",
"pyo3/extension-module"
]
default = []
[dependencies]
djls-project = { workspace = true }
djls-server = { workspace = true }
anyhow = { workspace = true }
pyo3 = { workspace = true, features = ["extension-module"] }
pyo3 = { workspace = true }
pyo3-async-runtimes = { workspace = true, features = ["tokio-runtime"] }
serde_json = { workspace = true }
tokio = { workspace = true }