Skip to content

Commit 7ef503d

Browse files
fix release build failures due to libpython linking (#125)
1 parent 9398df6 commit 7ef503d

File tree

5 files changed

+42
-17
lines changed

5 files changed

+42
-17
lines changed

.github/workflows/release.yml

+4-4
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@ jobs:
4848
uses: PyO3/maturin-action@v1
4949
with:
5050
target: ${{ matrix.platform.target }}
51-
args: --release --out dist --find-interpreter
51+
args: --release --out dist --find-interpreter --features extension-module
5252
sccache: "true"
5353
manylinux: auto
5454

@@ -82,7 +82,7 @@ jobs:
8282
uses: PyO3/maturin-action@v1
8383
with:
8484
target: ${{ matrix.platform.target }}
85-
args: --release --out dist --find-interpreter
85+
args: --release --out dist --find-interpreter --features extension-module
8686
manylinux: musllinux_1_2
8787

8888
- name: Upload wheels
@@ -112,7 +112,7 @@ jobs:
112112
uses: PyO3/maturin-action@v1
113113
with:
114114
target: ${{ matrix.platform.target }}
115-
args: --release --out dist --find-interpreter
115+
args: --release --out dist --find-interpreter --features extension-module
116116
sccache: "true"
117117

118118
- name: Upload wheels
@@ -141,7 +141,7 @@ jobs:
141141
uses: PyO3/maturin-action@v1
142142
with:
143143
target: ${{ matrix.platform.target }}
144-
args: --release --out dist --find-interpreter
144+
args: --release --out dist --find-interpreter --features extension-module
145145
sccache: "true"
146146

147147
- name: Upload wheels

crates/djls-dev/src/build.rs

+20-12
Original file line numberDiff line numberDiff line change
@@ -26,22 +26,30 @@ pub fn setup_python_linking() {
2626
// Get the Python interpreter configuration directly
2727
let config = pyo3_build_config::get();
2828

29-
// Add the library search path if available
29+
let is_extension_module = std::env::var("CARGO_FEATURE_EXTENSION_MODULE").is_ok();
30+
31+
// Only link libpython explicitly if we are NOT building an extension module.
32+
if !is_extension_module {
33+
if let Some(lib_name) = &config.lib_name {
34+
println!("cargo:rustc-link-lib=dylib={}", lib_name);
35+
} else {
36+
// Warn only if linking is actually needed but we can't find the lib name
37+
println!("cargo:warning=Python library name not found in config (needed for non-extension module
38+
builds).");
39+
}
40+
}
41+
42+
// Add the library search path and RPATH if available.
43+
// These are needed for test executables and potential future standalone binaries,
44+
// and generally harmless for extension modules.
3045
if let Some(lib_dir) = &config.lib_dir {
3146
println!("cargo:rustc-link-search=native={}", lib_dir);
32-
33-
// Add RPATH linker argument for Unix-like systems (Linux, macOS)
34-
// This helps the test executable find the Python library at runtime.
3547
#[cfg(not(windows))]
3648
println!("cargo:rustc-link-arg=-Wl,-rpath,{}", lib_dir);
3749
} else {
38-
println!("cargo:warning=Python library directory not found in config.");
39-
}
40-
41-
// Add the library link directive if available
42-
if let Some(lib_name) = &config.lib_name {
43-
println!("cargo:rustc-link-lib=dylib={}", lib_name);
44-
} else {
45-
println!("cargo:warning=Python library name not found in config.");
50+
// Warn only if linking is actually needed but we can't find the lib dir
51+
if !is_extension_module {
52+
println!("cargo:warning=Python library directory not found in config.");
53+
}
4654
}
4755
}

crates/djls-project/Cargo.toml

+4
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,10 @@ name = "djls-project"
33
version = "0.1.0"
44
edition = "2021"
55

6+
[features]
7+
extension-module = []
8+
default = []
9+
610
[dependencies]
711
pyo3 = { workspace = true }
812
tower-lsp-server = { workspace = true, features = ["proposed"] }

crates/djls-server/Cargo.toml

+4
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,10 @@ name = "djls-server"
33
version = "0.1.0"
44
edition = "2021"
55

6+
[features]
7+
extension-module = []
8+
default = []
9+
610
[dependencies]
711
djls-conf = { workspace = true }
812
djls-project = { workspace = true }

crates/djls/Cargo.toml

+10-1
Original file line numberDiff line numberDiff line change
@@ -7,11 +7,20 @@ edition = "2021"
77
name = "djls"
88
crate-type = ["cdylib"]
99

10+
[features]
11+
extension-module = [
12+
"djls-server/extension-module",
13+
"djls-project/extension-module",
14+
"pyo3/extension-module"
15+
]
16+
default = []
17+
1018
[dependencies]
19+
djls-project = { workspace = true }
1120
djls-server = { workspace = true }
1221

1322
anyhow = { workspace = true }
14-
pyo3 = { workspace = true, features = ["extension-module"] }
23+
pyo3 = { workspace = true }
1524
pyo3-async-runtimes = { workspace = true, features = ["tokio-runtime"] }
1625
serde_json = { workspace = true }
1726
tokio = { workspace = true }

0 commit comments

Comments
 (0)