Skip to content
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

Add all packages #4

Open
wants to merge 1 commit into
base: empty_repository
Choose a base branch
from
Open
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
1 change: 1 addition & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,2 +1,3 @@
[workspace]
members = ["example/dart_package/rust", "example/flutter_package/rust"]
resolver = "2"
7 changes: 7 additions & 0 deletions example/dart_package/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
# https://dart.dev/guides/libraries/private-files
# Created by `dart pub`
.dart_tool/

# Avoid committing pubspec.lock for library packages; see
# https://dart.dev/guides/libraries/private-files#pubspeclock.
pubspec.lock
3 changes: 3 additions & 0 deletions example/dart_package/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
## 1.0.0

- Initial version.
20 changes: 20 additions & 0 deletions example/dart_package/LICENSE
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
Copyright 2024 Matej Knopp

MIT LICENSE

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies
of the Software, and to permit persons to whom the Software is furnished to do
so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS
OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR
IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
39 changes: 39 additions & 0 deletions example/dart_package/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
<!--
Copy link

Choose a reason for hiding this comment

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

An actual readme would be nice ;)

This README describes the package. If you publish this package to pub.dev,
this README's contents appear on the landing page for your package.

For information about how to write a good package README, see the guide for
[writing package pages](https://dart.dev/guides/libraries/writing-package-pages).

For general information about developing packages, see the Dart guide for
[creating packages](https://dart.dev/guides/libraries/create-library-packages)
and the Flutter guide for
[developing packages and plugins](https://flutter.dev/developing-packages).
-->

TODO: Put a short description of the package here that helps potential users
know whether this package might be useful for them.

## Features

TODO: List what your package can do. Maybe include images, gifs, or videos.

## Getting started

TODO: List prerequisites and provide or point to information on how to
start using the package.

## Usage

TODO: Include short and useful examples for package users. Add longer examples
to `/example` folder.

```dart
const like = 'sample';
```

## Additional information

TODO: Tell users more about the package: where to find more information, how to
contribute to the package, how to file issues, what response they can expect
from the package authors, and more.
1 change: 1 addition & 0 deletions example/dart_package/analysis_options.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
include: package:lints/recommended.yaml
6 changes: 6 additions & 0 deletions example/dart_package/example/dart_package_example.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
import 'package:dart_package/dart_package.dart';

void main() {
final value = sum(10, 15);
print('sum(10, 15) = $value');
}
20 changes: 20 additions & 0 deletions example/dart_package/hook/build.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
import 'dart:io';

import 'package:native_toolchain_rust/native_toolchain_rust.dart';
import 'package:native_assets_cli/native_assets_cli.dart';

void main(List<String> args) async {
try {
await build(args, (BuildConfig buildConfig, BuildOutput output) async {
final builder = RustBuilder(
package: 'dart_package',
crateManifestPath: 'rust/Cargo.toml',
buildConfig: buildConfig,
);
await builder.run(output: output);
});
} catch (e) {
print(e);
exit(1);
}
}
8 changes: 8 additions & 0 deletions example/dart_package/lib/dart_package.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
/// Support for doing something awesome.
///
/// More dartdocs go here.
library;

export 'src/dart_package_base.dart';

// TODO: Export any libraries intended for clients of this package.
3 changes: 3 additions & 0 deletions example/dart_package/lib/src/dart_package_base.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
import 'ffi_rust.dart' as ffi_rust;

int sum(int a, int b) => ffi_rust.sum(a, b);
10 changes: 10 additions & 0 deletions example/dart_package/lib/src/ffi_rust.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
@ffi.DefaultAsset('package:dart_package/dart_ffi_plugin')
library rust;

import 'dart:ffi' as ffi;

@ffi.Native<ffi.IntPtr Function(ffi.IntPtr, ffi.IntPtr)>()
external int sum(
int a,
int b,
);
5 changes: 5 additions & 0 deletions example/dart_package/native_manifest.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
version: 0.1.0
requirements:
rust:
stable:
version: 1.77.2
15 changes: 15 additions & 0 deletions example/dart_package/pubspec.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
name: dart_package
description: A starting point for Dart libraries or applications.
version: 1.0.0
publish_to: none

environment:
sdk: ^3.5.0-90.0.dev

dependencies:
native_toolchain_rust: ^0.1.0-dev.2
Copy link

Choose a reason for hiding this comment

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

As native_toolchain_rust is only used in build.dart, might as well be a dev dependency. Same for native_assets_cli. Also, for examples, I personally prefer them to be path dependencies on the package in the repo.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I'd prefer that, but even the example flutter ffi package has native_toolchain_cli and native_toolchain_c declared as dependencies. I'm wondering if maybe having them inside dev_dependencies causes problem when the package is a transient dependency? Or is there some other reason for that?

Copy link

Choose a reason for hiding this comment

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

Choose a reason for hiding this comment

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

build hook and link hook dependencies cannot be dev dependencies. Details:

TL;DR: You don't want version skew between what version of helper packages where used to run the hooks and that are used at runtime later.

(Some more related discussions around managing dependencies and running hooks during the build: dart-lang/pub#3794)

native_assets_cli: ^0.5.4

dev_dependencies:
lints: ^3.0.0
test: ^1.24.0
7 changes: 7 additions & 0 deletions example/dart_package/rust/Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

11 changes: 11 additions & 0 deletions example/dart_package/rust/Cargo.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
[package]
name = "dart_ffi_plugin"
version = "0.1.0"
edition = "2021"

[lib]
crate-type = ["cdylib", "staticlib"]

# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html

[dependencies]
18 changes: 18 additions & 0 deletions example/dart_package/rust/src/lib.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
use std::usize;

#[no_mangle]
pub extern "C" fn sum(a: usize, b: usize) -> usize {
println!("Hello from rust {a} + {b}");
a + b
}

#[cfg(test)]
mod tests {
use super::*;

#[test]
fn it_works() {
let result = sum(2, 2);
assert_eq!(result, 4);
}
}
12 changes: 12 additions & 0 deletions example/dart_package/test/dart_package_test.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
import 'package:dart_package/dart_package.dart';

import 'package:test/test.dart';

void main() {
group('A group of tests', () {
test('FFI call works', () {
final result = sum(10, 15);
expect(result, 25);
});
});
}
29 changes: 29 additions & 0 deletions example/flutter_package/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
# Miscellaneous
*.class
*.log
*.pyc
*.swp
.DS_Store
.atom/
.buildlog/
.history
.svn/
migrate_working_dir/

# IntelliJ related
*.iml
*.ipr
*.iws
.idea/

# The .vscode folder contains launch configuration and tasks you configure in
# VS Code which you may wish to be included in version control, so this line
# is commented out by default.
#.vscode/

# Flutter/Dart/Pub related
# Libraries should not include pubspec.lock, per https://dart.dev/guides/libraries/private-files#pubspeclock.
/pubspec.lock
**/doc/api/
.dart_tool/
build/
10 changes: 10 additions & 0 deletions example/flutter_package/.metadata
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
# This file tracks properties of this Flutter project.
# Used by Flutter tool to assess capabilities and perform upgrades etc.
#
# This file should be version controlled and should not be manually edited.

version:
revision: "9689f7f89c9821b344321668fd144bdd6b957d41"
channel: "main"

project_type: package
3 changes: 3 additions & 0 deletions example/flutter_package/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
## 0.0.1

* TODO: Describe initial release.
20 changes: 20 additions & 0 deletions example/flutter_package/LICENSE
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
Copyright 2024 Matej Knopp

MIT LICENSE

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies
of the Software, and to permit persons to whom the Software is furnished to do
so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS
OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR
IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
39 changes: 39 additions & 0 deletions example/flutter_package/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
<!--
This README describes the package. If you publish this package to pub.dev,
this README's contents appear on the landing page for your package.
For information about how to write a good package README, see the guide for
[writing package pages](https://dart.dev/guides/libraries/writing-package-pages).
For general information about developing packages, see the Dart guide for
[creating packages](https://dart.dev/guides/libraries/create-library-packages)
and the Flutter guide for
[developing packages and plugins](https://flutter.dev/developing-packages).
-->

TODO: Put a short description of the package here that helps potential users
know whether this package might be useful for them.

## Features

TODO: List what your package can do. Maybe include images, gifs, or videos.

## Getting started

TODO: List prerequisites and provide or point to information on how to
start using the package.

## Usage

TODO: Include short and useful examples for package users. Add longer examples
to `/example` folder.

```dart
const like = 'sample';
```

## Additional information

TODO: Tell users more about the package: where to find more information, how to
contribute to the package, how to file issues, what response they can expect
from the package authors, and more.
4 changes: 4 additions & 0 deletions example/flutter_package/analysis_options.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
include: package:flutter_lints/flutter.yaml

# Additional information about this file can be found at
# https://dart.dev/guides/language/analysis-options
43 changes: 43 additions & 0 deletions example/flutter_package/example/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
# Miscellaneous
*.class
*.log
*.pyc
*.swp
.DS_Store
.atom/
.buildlog/
.history
.svn/
migrate_working_dir/

# IntelliJ related
*.iml
*.ipr
*.iws
.idea/

# The .vscode folder contains launch configuration and tasks you configure in
# VS Code which you may wish to be included in version control, so this line
# is commented out by default.
#.vscode/

# Flutter/Dart/Pub related
**/doc/api/
**/ios/Flutter/.last_build_id
.dart_tool/
.flutter-plugins
.flutter-plugins-dependencies
.pub-cache/
.pub/
/build/

# Symbolication related
app.*.symbols

# Obfuscation related
app.*.map.json

# Android Studio will place build artifacts here
/android/app/debug
/android/app/profile
/android/app/release
Loading
Loading