Skip to content

fix release build failures due to libpython linking #125

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

Merged
merged 1 commit into from
Apr 30, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 4 additions & 4 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ jobs:
uses: PyO3/maturin-action@v1
with:
target: ${{ matrix.platform.target }}
args: --release --out dist --find-interpreter
args: --release --out dist --find-interpreter --features extension-module
sccache: "true"
manylinux: auto

Expand Down Expand Up @@ -82,7 +82,7 @@ jobs:
uses: PyO3/maturin-action@v1
with:
target: ${{ matrix.platform.target }}
args: --release --out dist --find-interpreter
args: --release --out dist --find-interpreter --features extension-module
manylinux: musllinux_1_2

- name: Upload wheels
Expand Down Expand Up @@ -112,7 +112,7 @@ jobs:
uses: PyO3/maturin-action@v1
with:
target: ${{ matrix.platform.target }}
args: --release --out dist --find-interpreter
args: --release --out dist --find-interpreter --features extension-module
sccache: "true"

- name: Upload wheels
Expand Down Expand Up @@ -141,7 +141,7 @@ jobs:
uses: PyO3/maturin-action@v1
with:
target: ${{ matrix.platform.target }}
args: --release --out dist --find-interpreter
args: --release --out dist --find-interpreter --features extension-module
sccache: "true"

- name: Upload wheels
Expand Down
32 changes: 20 additions & 12 deletions crates/djls-dev/src/build.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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.");
}
}
}
4 changes: 4 additions & 0 deletions crates/djls-project/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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"] }
Expand Down
4 changes: 4 additions & 0 deletions crates/djls-server/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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 }
Expand Down
11 changes: 10 additions & 1 deletion crates/djls/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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 }
Expand Down
Loading