Skip to content

Commit daadf3c

Browse files
committed
Try to fix SONAME...
1 parent 74b3b58 commit daadf3c

File tree

4 files changed

+92
-3
lines changed

4 files changed

+92
-3
lines changed

.cargo/cargo.toml

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
[target.x86_64-unknown-linux-gnu]
2+
rustflags = ["-C", "link-args=-Wl,-export-dynamic"]
3+
4+
[target.aarch64-unknown-linux-gnu]
5+
rustflags = ["-C", "link-args=-Wl,-export-dynamic"]

.github/workflows/CI.yml

Lines changed: 42 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -326,15 +326,55 @@ jobs:
326326
uses: addnab/docker-run-action@v3
327327
with:
328328
image: ${{ steps.docker.outputs.IMAGE }}
329-
options: -v ${{ steps.docker.outputs.PNPM_STORE_PATH }}:${{ steps.docker.outputs.PNPM_STORE_PATH }} -v ${{ github.workspace }}:${{ github.workspace }} -w ${{ github.workspace }} --platform ${{ steps.docker.outputs.PLATFORM }}
329+
options: -v ${{ steps.docker.outputs.PNPM_STORE_PATH }}:${{ steps.docker.outputs.PNPM_STORE_PATH }} -v ${{ github.workspace }}:${{ github.workspace }} -w ${{ github.workspace }} --platform ${{ steps.docker.outputs.PLATFORM }} -e CI=true -e GITHUB_ACTIONS=true
330330
run: |
331-
# Install Python 3.9+ (any version will work with abi3-py39)
331+
# Install Python 3.x
332332
apt-get update -y
333333
apt-get install -y python3 python3-dev
334334
335+
echo "=== Starting test setup ==="
336+
echo "Current directory: $(pwd)"
337+
echo "Python version: $(python3 --version)"
338+
echo "Patchelf version: $(patchelf --version)"
339+
echo "CI environment: CI=$CI, GITHUB_ACTIONS=$GITHUB_ACTIONS"
340+
341+
# Check what .node files exist
342+
echo "=== Available .node files ==="
343+
ls -la *.node || echo "No .node files found"
344+
345+
# Check what .node files exist and their Python dependencies
346+
echo "=== Checking .node file Python dependencies ==="
347+
for file in *.node; do
348+
if [ -f "$file" ]; then
349+
case "$file" in
350+
*linux*)
351+
echo "Checking $file..."
352+
echo "Python dependencies:"
353+
ldd "$file" 2>/dev/null | grep python || echo "No Python dependencies found"
354+
echo "---"
355+
;;
356+
*)
357+
echo "Skipping non-Linux file: $file"
358+
;;
359+
esac
360+
fi
361+
done
362+
335363
# Install pnpm and run tests
364+
echo "=== Installing pnpm ==="
336365
corepack disable
337366
npm i -gf pnpm
367+
368+
echo "=== Running pnpm install ==="
369+
# Should be non-interactive in CI environment
370+
pnpm install --prefer-offline
371+
372+
echo "=== Setting up Python library path ==="
373+
export LD_LIBRARY_PATH=/usr/lib/x86_64-linux-gnu:$LD_LIBRARY_PATH
374+
echo "LD_LIBRARY_PATH: $LD_LIBRARY_PATH"
375+
376+
377+
echo "=== Running tests ==="
338378
pnpm test
339379
340380
publish:

Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ http-rewriter = { git = "ssh://git@github.com/platformatic/http-rewriter.git" }
2727
# Default enable napi4 feature, see https://nodejs.org/api/n-api.html#node-api-version-matrix
2828
napi = { version = "3.0.0-beta.8", default-features = false, features = ["napi4"], optional = true }
2929
napi-derive = { version = "3.0.0-beta.8", optional = true }
30-
pyo3 = { version = "0.25.1", features = ["auto-initialize", "experimental-async", "abi3-py39"] }
30+
pyo3 = { version = "0.25.1", features = ["auto-initialize", "experimental-async"] }
3131
pyo3-async-runtimes = { version = "0.25.0", features = ["tokio-runtime"] }
3232
thiserror = "2.0.12"
3333
tokio = { version = "1.45.1", features = ["full"] }

src/asgi/mod.rs

Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,19 @@ use std::{
55
path::{Path, PathBuf},
66
};
77

8+
#[cfg(target_os = "linux")]
9+
use std::os::raw::c_void;
10+
11+
#[cfg(target_os = "linux")]
12+
unsafe extern "C" {
13+
fn dlopen(filename: *const i8, flag: i32) -> *mut c_void;
14+
}
15+
16+
#[cfg(target_os = "linux")]
17+
const RTLD_GLOBAL: i32 = 0x100;
18+
#[cfg(target_os = "linux")]
19+
const RTLD_NOW: i32 = 0x2;
20+
821
use bytes::BytesMut;
922
use http_handler::{Handler, Request, RequestExt, Response, extensions::DocumentRoot};
1023
use pyo3::exceptions::PyRuntimeError;
@@ -35,6 +48,34 @@ pub use websocket::{
3548
WebSocketConnectionScope, WebSocketReceiveMessage, WebSocketSendException, WebSocketSendMessage,
3649
};
3750

51+
/// Load Python library with RTLD_GLOBAL on Linux to make symbols available
52+
#[cfg(target_os = "linux")]
53+
fn ensure_python_symbols_global() {
54+
unsafe {
55+
// Try common Python library names
56+
let python_libs = [
57+
"libpython3.12.so.1.0\0",
58+
"libpython3.11.so.1.0\0",
59+
"libpython3.10.so.1.0\0",
60+
"libpython3.9.so.1.0\0",
61+
"libpython3.8.so.1.0\0",
62+
];
63+
64+
for lib_name in &python_libs {
65+
let handle = dlopen(lib_name.as_ptr() as *const i8, RTLD_NOW | RTLD_GLOBAL);
66+
if !handle.is_null() {
67+
// Successfully loaded Python library with RTLD_GLOBAL
68+
break;
69+
}
70+
}
71+
}
72+
}
73+
74+
#[cfg(not(target_os = "linux"))]
75+
fn ensure_python_symbols_global() {
76+
// On non-Linux platforms, this is typically not needed
77+
}
78+
3879
/// Core ASGI handler that loads and manages a Python ASGI application
3980
pub struct Asgi {
4081
app_function: PyObject,
@@ -47,6 +88,9 @@ impl Asgi {
4788
docroot: Option<String>,
4889
app_target: Option<PythonHandlerTarget>,
4990
) -> Result<Self, HandlerError> {
91+
// Ensure Python symbols are globally available before initializing
92+
ensure_python_symbols_global();
93+
5094
// Determine document root
5195
let docroot = PathBuf::from(if let Some(docroot) = docroot {
5296
docroot

0 commit comments

Comments
 (0)