Skip to content

Commit 343d3b1

Browse files
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 * fzyzcjy/flutter_rust_bridge#2460 * fix path * add log * put bin to pos * Update opendal.dart * dup key * add build to default pos
1 parent 1ecd699 commit 343d3b1

File tree

5 files changed

+163
-5
lines changed

5 files changed

+163
-5
lines changed

.github/workflows/ci_bindings_dart.yml

+13-1
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,16 @@ jobs:
5151
- name: Setup Rust toolchain
5252
uses: ./.github/actions/setup
5353

54+
- uses: actions/cache@v4
55+
with:
56+
path: |
57+
~/.cargo/bin/
58+
~/.cargo/registry/index/
59+
~/.cargo/registry/cache/
60+
~/.cargo/git/db/
61+
bindings/dart/rust/target/
62+
key: ${{ runner.os }}-cargo-${{ hashFiles('**/Cargo.toml') }}
63+
5464
- name: Install Flutter
5565
uses: subosito/flutter-action@v2
5666
with:
@@ -71,7 +81,9 @@ jobs:
7181
working-directory: bindings/dart/rust
7282
run: |
7383
set -eux -o pipefail
74-
cargo build -r # frb will load the so in release/, so release build here
84+
cargo build -r
85+
cargo build -r --target x86_64-unknown-linux-gnu
86+
ls -R .
7587
7688
- name: test
7789
working-directory: bindings/dart

.github/workflows/release_dart.yml

+127
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,127 @@
1+
# Licensed to the Apache Software Foundation (ASF) under one
2+
# or more contributor license agreements. See the NOTICE file
3+
# distributed with this work for additional information
4+
# regarding copyright ownership. The ASF licenses this file
5+
# to you under the Apache License, Version 2.0 (the
6+
# "License"); you may not use this file except in compliance
7+
# with the License. You may obtain a copy of the License at
8+
#
9+
# http://www.apache.org/licenses/LICENSE-2.0
10+
#
11+
# Unless required by applicable law or agreed to in writing,
12+
# software distributed under the License is distributed on an
13+
# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
14+
# KIND, either express or implied. See the License for the
15+
# specific language governing permissions and limitations
16+
# under the License.
17+
18+
# This workflow is used for publish all rust based packages
19+
20+
name: Release Dart
21+
22+
on:
23+
push:
24+
tags:
25+
- "*"
26+
pull_request:
27+
branches:
28+
- main
29+
paths:
30+
- ".github/workflows/release_dart.yml"
31+
workflow_dispatch:
32+
33+
concurrency:
34+
group: ${{ github.workflow }}-${{ github.ref }}-${{ github.event_name }}
35+
cancel-in-progress: true
36+
37+
permissions:
38+
contents: read
39+
40+
jobs:
41+
build:
42+
runs-on: ${{ matrix.os }}
43+
strategy:
44+
matrix:
45+
include:
46+
- os: ubuntu-latest
47+
target: x86_64-unknown-linux-gnu
48+
target_suffix: x86_64
49+
- os: ubuntu-latest
50+
target: aarch64-unknown-linux-gnu
51+
target_suffix: aarch64
52+
- os: windows-latest
53+
target: x86_64-pc-windows-msvc
54+
target_suffix: win_x86_64
55+
- os: macos-latest
56+
target: aarch64-apple-darwin
57+
target_suffix: macos_aarch64
58+
steps:
59+
- name: Checkout code
60+
uses: actions/checkout@v3
61+
- uses: actions/cache@v4
62+
with:
63+
path: |
64+
~/.cargo/bin/
65+
~/.cargo/registry/index/
66+
~/.cargo/registry/cache/
67+
~/.cargo/git/db/
68+
bindings/dart/rust/target/
69+
key: ${{ runner.os }}-cargo-${{ hashFiles('**/Cargo.toml') }}-${{ matrix.target }} # Include target in cache key
70+
- name: Setup Rust toolchain
71+
uses: ./.github/actions/setup
72+
73+
- name: Install cross
74+
run: cargo install cross --git https://github.com/cross-rs/cross --force
75+
76+
- name: Build on linux
77+
if: runner.os == 'Linux'
78+
run: |
79+
cd bindings/dart/rust
80+
cross build --release --target ${{ matrix.target }}
81+
82+
- name: Build not on linux
83+
if: runner.os != 'Linux'
84+
run: |
85+
cd bindings/dart/rust
86+
cargo build --release --target ${{ matrix.target }}
87+
88+
- name: Upload build artifact (per platform)
89+
uses: actions/upload-artifact@v4
90+
with:
91+
name: ${{ matrix.target }}
92+
path: bindings/dart/rust/target/${{ matrix.target }}/release/*opendal*
93+
94+
combine-artifacts:
95+
needs: build
96+
runs-on: ubuntu-latest
97+
steps:
98+
- name: Checkout code
99+
uses: actions/checkout@v3
100+
- name: create release dir
101+
run: |
102+
cd bindings/dart/rust
103+
mkdir -p target/release/
104+
105+
- name: Download all artifacts
106+
uses: actions/download-artifact@v4
107+
with:
108+
path: artifacts
109+
110+
- name: Move artifacts to release
111+
run: |
112+
cp -av ./artifacts/* bindings/dart/rust/target/release/
113+
find . -name "*.a" -print -delete
114+
find . -name "*.d" -print -delete
115+
find . -name "*.pdb" -print -delete
116+
find . -name "*.exp" -print -delete
117+
find . -name "*.lib" -print -delete
118+
- name: Show Result
119+
run: |
120+
cd bindings/dart/rust
121+
ls -R .
122+
- name: Upload combined build artifacts
123+
uses: actions/upload-artifact@v4
124+
with:
125+
name: combined-release
126+
path: bindings/dart/rust/target/release/
127+
# todo: add pub step

bindings/dart/README.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@ dart run tests/opendal_test.dart
4848
flutter pub get
4949
flutter_rust_bridge_codegen generate
5050
cd rust
51-
cargo build -r
51+
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
5252
```
5353

5454
## Update generated code

bindings/dart/lib/opendal.dart

+17-1
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,9 @@
1515
// specific language governing permissions and limitations
1616
// under the License.
1717

18+
import 'dart:io';
19+
import 'package:system_info2/system_info2.dart';
20+
import 'package:flutter_rust_bridge/flutter_rust_bridge_for_generated_io.dart';
1821
import 'src/rust/frb_generated.dart';
1922
import 'src/rust/api/opendal_api.dart';
2023
export 'src/rust/frb_generated.dart';
@@ -30,7 +33,20 @@ class Storage {
3033
required Map<String, String> map,
3134
}) async {
3235
if (!RustLib.instance.initialized) {
33-
await RustLib.init();
36+
var path = "rust/target/release/"; // default path
37+
final name = Platform.operatingSystem;
38+
final arch = SysInfo.kernelArchitecture;
39+
// if (name == "linux" && arch == "x86_64"){
40+
// path = "rust/target/x86_64-unknown-linux-gnu/release/";
41+
// }
42+
// todo: more system and arch
43+
44+
var config = ExternalLibraryLoaderConfig( // https://github.com/fzyzcjy/flutter_rust_bridge/issues/2460
45+
stem: 'opendal_dart',
46+
ioDirectory: path,
47+
webPrefix: 'pkg/',
48+
);
49+
await RustLib.init(externalLibrary: await loadExternalLibrary(config));
3450
}
3551
return Storage._(Operator(schemeStr: schemeStr, map: map));
3652
}

bindings/dart/pubspec.yaml

+5-2
Original file line numberDiff line numberDiff line change
@@ -17,15 +17,18 @@
1717

1818
name: opendal
1919
description: Apache OpenDAL™ Dart Binding
20-
version: 0.0.0
21-
publish_to: none
20+
version: 0.0.1
21+
homepage: https://opendal.apache.org/
22+
repository: https://github.com/apache/opendal
23+
issue_tracker: https://github.com/apache/opendal/issues
2224
environment:
2325
sdk: '>=3.3.0 <4.0.0'
2426
dependencies:
2527
lints: ^2.0.1
2628
flutter_rust_bridge: 2.8.0
2729
freezed_annotation: ^2.2.0
2830
collection: ^1.18.0
31+
system_info2: 4.0.0
2932
dev_dependencies:
3033
test: ^1.21.4
3134
freezed: ^2.1.0+1

0 commit comments

Comments
 (0)