This is an automated email from the ASF dual-hosted git repository.

xuanwo pushed a commit to branch xuanwo/ocaml-dylib-link
in repository https://gitbox.apache.org/repos/asf/opendal.git

commit b1c13178cbf690c1986e47333db75b5c26acbbbf
Author: Xuanwo <[email protected]>
AuthorDate: Fri Dec 12 16:46:42 2025 +0800

    ci(bindings/ocaml): Use dyn link instead
    
    Signed-off-by: Xuanwo <[email protected]>
---
 bindings/ocaml/Cargo.toml |  2 +-
 bindings/ocaml/src/dune   | 22 ++++++++++++++++++----
 2 files changed, 19 insertions(+), 5 deletions(-)

diff --git a/bindings/ocaml/Cargo.toml b/bindings/ocaml/Cargo.toml
index 1b9cdc4fc..82bb8d277 100644
--- a/bindings/ocaml/Cargo.toml
+++ b/bindings/ocaml/Cargo.toml
@@ -27,7 +27,7 @@ repository = "https://github.com/apache/opendal";
 rust-version = "1.85"
 
 [lib]
-crate-type = ["staticlib", "cdylib"]
+crate-type = ["cdylib"]
 doc = false
 
 [dependencies]
diff --git a/bindings/ocaml/src/dune b/bindings/ocaml/src/dune
index bcd2d45a8..25668961b 100644
--- a/bindings/ocaml/src/dune
+++ b/bindings/ocaml/src/dune
@@ -16,16 +16,24 @@
 ; under the License.
 
 (rule
- (targets libopendal_core.a dllopendal_core.so)
+ (targets libopendal_core.a dllopendal_core.so libopendal_core.so)
  (deps
   (glob_files *.rs))
  (action
   (progn
    (run sh -c "cd %{project_root}/../.. && cargo build --release")
    (run sh -c
-     "mv %{project_root}/../../target/release/libopendal_ocaml.so 
./dllopendal_core.so 2> /dev/null || mv 
%{project_root}/../../target/release/libopendal_ocaml.dylib 
./dllopendal_core.so")
-   (run mv %{project_root}/../../target/release/libopendal_ocaml.a
-     libopendal_core.a))))
+     "if [ -f %{project_root}/../../target/release/libopendal_ocaml.so ]; then 
\
+        cp %{project_root}/../../target/release/libopendal_ocaml.so 
./dllopendal_core.so; \
+        cp %{project_root}/../../target/release/libopendal_ocaml.so 
./libopendal_core.so; \
+      else \
+        cp %{project_root}/../../target/release/libopendal_ocaml.dylib 
./dllopendal_core.so; \
+        cp %{project_root}/../../target/release/libopendal_ocaml.dylib 
./libopendal_core.so; \
+      fi")
+   (run sh -c
+     "echo 'void __opendal_core_dummy(void) {}' | cc -c -x c - -o 
opendal_core_dummy.o && \
+      ar crs libopendal_core.a opendal_core_dummy.o && \
+      rm opendal_core_dummy.o"))))
 
 (library
  (name opendal_core)
@@ -33,3 +41,9 @@
  (foreign_archives opendal_core)
  (c_library_flags
   (-lpthread -lc -lm)))
+
+(install
+ (section lib)
+ (package opendal)
+ (files
+  (libopendal_core.so as opendal_core/libopendal_core.so)))

Reply via email to