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

xuanwo pushed a commit to branch main
in repository https://gitbox.apache.org/repos/asf/opendal.git


The following commit(s) were added to refs/heads/main by this push:
     new 343d3b183 feat(binding/dart): add pubspec info (#5751)
343d3b183 is described below

commit 343d3b183badf0939b067ee9a263a4dbfd73fec0
Author: Asuka Minato <[email protected]>
AuthorDate: Sat Mar 15 12:11:42 2025 +0900

    feat(binding/dart): add pubspec info (#5751)
    
    * add pubspec info
    
    * try add
    
    * Update release_dart.yml
    
    * support multi arch
    
    * pass the ci
    
    * try fix type
    
    * https://github.com/fzyzcjy/flutter_rust_bridge/issues/2460
    
    * fix path
    
    * add log
    
    * put bin to pos
    
    * Update opendal.dart
    
    * dup key
    
    * add build to default pos
---
 .github/workflows/ci_bindings_dart.yml |  14 +++-
 .github/workflows/release_dart.yml     | 127 +++++++++++++++++++++++++++++++++
 bindings/dart/README.md                |   2 +-
 bindings/dart/lib/opendal.dart         |  18 ++++-
 bindings/dart/pubspec.yaml             |   7 +-
 5 files changed, 163 insertions(+), 5 deletions(-)

diff --git a/.github/workflows/ci_bindings_dart.yml 
b/.github/workflows/ci_bindings_dart.yml
index 5e9390c01..d32bd4343 100644
--- a/.github/workflows/ci_bindings_dart.yml
+++ b/.github/workflows/ci_bindings_dart.yml
@@ -51,6 +51,16 @@ jobs:
       - name: Setup Rust toolchain
         uses: ./.github/actions/setup
 
+      - uses: actions/cache@v4
+        with:
+          path: |
+            ~/.cargo/bin/
+            ~/.cargo/registry/index/
+            ~/.cargo/registry/cache/
+            ~/.cargo/git/db/
+            bindings/dart/rust/target/
+          key: ${{ runner.os }}-cargo-${{ hashFiles('**/Cargo.toml') }}
+
       - name: Install Flutter
         uses: subosito/flutter-action@v2
         with:
@@ -71,7 +81,9 @@ jobs:
         working-directory: bindings/dart/rust
         run: |
           set -eux -o pipefail
-          cargo build -r # frb will load the so in release/, so release build 
here
+          cargo build -r
+          cargo build -r --target x86_64-unknown-linux-gnu
+          ls -R .
 
       - name: test
         working-directory: bindings/dart
diff --git a/.github/workflows/release_dart.yml 
b/.github/workflows/release_dart.yml
new file mode 100644
index 000000000..6482379f2
--- /dev/null
+++ b/.github/workflows/release_dart.yml
@@ -0,0 +1,127 @@
+# Licensed to the Apache Software Foundation (ASF) under one
+# or more contributor license agreements.  See the NOTICE file
+# distributed with this work for additional information
+# regarding copyright ownership.  The ASF licenses this file
+# to you under the Apache License, Version 2.0 (the
+# "License"); you may not use this file except in compliance
+# with the License.  You may obtain a copy of the License at
+#
+#   http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing,
+# software distributed under the License is distributed on an
+# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+# KIND, either express or implied.  See the License for the
+# specific language governing permissions and limitations
+# under the License.
+
+# This workflow is used for publish all rust based packages
+
+name: Release Dart
+
+on:
+  push:
+    tags:
+      - "*"
+  pull_request:
+    branches:
+      - main
+    paths:
+      - ".github/workflows/release_dart.yml"
+  workflow_dispatch:
+
+concurrency:
+  group: ${{ github.workflow }}-${{ github.ref }}-${{ github.event_name }}
+  cancel-in-progress: true
+
+permissions:
+  contents: read
+
+jobs:
+  build:
+    runs-on: ${{ matrix.os }}
+    strategy:
+      matrix:
+        include:
+          - os: ubuntu-latest
+            target: x86_64-unknown-linux-gnu
+            target_suffix: x86_64
+          - os: ubuntu-latest
+            target: aarch64-unknown-linux-gnu
+            target_suffix: aarch64
+          - os: windows-latest
+            target: x86_64-pc-windows-msvc
+            target_suffix: win_x86_64
+          - os: macos-latest
+            target: aarch64-apple-darwin
+            target_suffix: macos_aarch64
+    steps:
+      - name: Checkout code
+        uses: actions/checkout@v3
+      - uses: actions/cache@v4
+        with:
+          path: |
+            ~/.cargo/bin/
+            ~/.cargo/registry/index/
+            ~/.cargo/registry/cache/
+            ~/.cargo/git/db/
+            bindings/dart/rust/target/
+          key: ${{ runner.os }}-cargo-${{ hashFiles('**/Cargo.toml') }}-${{ 
matrix.target }} # Include target in cache key
+      - name: Setup Rust toolchain
+        uses: ./.github/actions/setup
+
+      - name: Install cross
+        run: cargo install cross --git https://github.com/cross-rs/cross 
--force
+
+      - name: Build on linux
+        if: runner.os == 'Linux'
+        run: |
+          cd bindings/dart/rust
+          cross build --release --target ${{ matrix.target }}
+
+      - name: Build not on linux
+        if: runner.os != 'Linux'
+        run: |
+          cd bindings/dart/rust
+          cargo build --release --target ${{ matrix.target }}
+
+      - name: Upload build artifact (per platform)
+        uses: actions/upload-artifact@v4
+        with:
+          name: ${{ matrix.target }}
+          path: bindings/dart/rust/target/${{ matrix.target 
}}/release/*opendal*
+
+  combine-artifacts:
+      needs: build
+      runs-on: ubuntu-latest
+      steps:
+        - name: Checkout code
+          uses: actions/checkout@v3
+        - name: create release dir
+          run: |
+            cd bindings/dart/rust
+            mkdir -p target/release/
+
+        - name: Download all artifacts
+          uses: actions/download-artifact@v4
+          with:
+            path: artifacts
+
+        - name: Move artifacts to release
+          run: |
+            cp -av ./artifacts/* bindings/dart/rust/target/release/
+            find . -name "*.a" -print -delete
+            find . -name "*.d" -print -delete
+            find . -name "*.pdb" -print -delete
+            find . -name "*.exp" -print -delete
+            find . -name "*.lib" -print -delete
+        - name: Show Result
+          run: |
+            cd bindings/dart/rust
+            ls -R .
+        - name: Upload combined build artifacts
+          uses: actions/upload-artifact@v4
+          with:
+              name: combined-release
+              path: bindings/dart/rust/target/release/
+# todo: add pub step
diff --git a/bindings/dart/README.md b/bindings/dart/README.md
index 57e0d32ea..eefcf6a74 100644
--- a/bindings/dart/README.md
+++ b/bindings/dart/README.md
@@ -48,7 +48,7 @@ dart run tests/opendal_test.dart
 flutter pub get
 flutter_rust_bridge_codegen generate
 cd rust
-cargo build -r
+cargo build -r --target x86_64-unknown-linux-gnu # change to your arch, refer 
to https://doc.rust-lang.org/beta/rustc/platform-support.html
 ```
 
 ## Update generated code
diff --git a/bindings/dart/lib/opendal.dart b/bindings/dart/lib/opendal.dart
index 0736c68b9..16faa66a1 100644
--- a/bindings/dart/lib/opendal.dart
+++ b/bindings/dart/lib/opendal.dart
@@ -15,6 +15,9 @@
 // specific language governing permissions and limitations
 // under the License.
 
+import 'dart:io';
+import 'package:system_info2/system_info2.dart';
+import 'package:flutter_rust_bridge/flutter_rust_bridge_for_generated_io.dart';
 import 'src/rust/frb_generated.dart';
 import 'src/rust/api/opendal_api.dart';
 export 'src/rust/frb_generated.dart';
@@ -30,7 +33,20 @@ class Storage {
     required Map<String, String> map,
   }) async {
     if (!RustLib.instance.initialized) {
-      await RustLib.init();
+      var path = "rust/target/release/";  // default path
+      final name = Platform.operatingSystem;
+      final arch = SysInfo.kernelArchitecture;
+      // if (name == "linux" && arch == "x86_64"){
+      //   path = "rust/target/x86_64-unknown-linux-gnu/release/";
+      // }
+      // todo: more system and arch
+
+      var config = ExternalLibraryLoaderConfig( // 
https://github.com/fzyzcjy/flutter_rust_bridge/issues/2460
+        stem: 'opendal_dart',
+        ioDirectory: path,
+        webPrefix: 'pkg/',
+      );
+      await RustLib.init(externalLibrary: await loadExternalLibrary(config));
     }
     return Storage._(Operator(schemeStr: schemeStr, map: map));
   }
diff --git a/bindings/dart/pubspec.yaml b/bindings/dart/pubspec.yaml
index e75c60e8a..f7406a0b9 100644
--- a/bindings/dart/pubspec.yaml
+++ b/bindings/dart/pubspec.yaml
@@ -17,8 +17,10 @@
 
 name: opendal
 description: Apache OpenDALâ„¢ Dart Binding
-version: 0.0.0
-publish_to: none
+version: 0.0.1
+homepage: https://opendal.apache.org/
+repository: https://github.com/apache/opendal
+issue_tracker: https://github.com/apache/opendal/issues
 environment:
   sdk: '>=3.3.0 <4.0.0'
 dependencies:
@@ -26,6 +28,7 @@ dependencies:
   flutter_rust_bridge: 2.8.0
   freezed_annotation: ^2.2.0
   collection: ^1.18.0
+  system_info2: 4.0.0
 dev_dependencies:
   test: ^1.21.4
   freezed: ^2.1.0+1

Reply via email to