Skip to content

feat(binding/dart): add pubspec info #5751

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 13 commits into from
Mar 15, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 13 additions & 1 deletion .github/workflows/ci_bindings_dart.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand All @@ -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
Expand Down
127 changes: 127 additions & 0 deletions .github/workflows/release_dart.yml
Original file line number Diff line number Diff line change
@@ -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:
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We should build only for RC tags and publish only for formal tags.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

how to modify it?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We need something like

if: ${{ startsWith(github.ref, 'refs/tags/') && contains(github.ref, '-') }}

We can implement in next PR.

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
2 changes: 1 addition & 1 deletion bindings/dart/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
18 changes: 17 additions & 1 deletion bindings/dart/lib/opendal.dart
Original file line number Diff line number Diff line change
Expand Up @@ -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';
Expand All @@ -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));
}
Expand Down
7 changes: 5 additions & 2 deletions bindings/dart/pubspec.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -17,15 +17,18 @@

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:
lints: ^2.0.1
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
Expand Down