Skip to content

Commit

Permalink
Refactor add link asset test
Browse files Browse the repository at this point in the history
  • Loading branch information
mosuem committed May 8, 2024
1 parent 12076be commit 60604a2
Show file tree
Hide file tree
Showing 11 changed files with 97 additions and 8 deletions.

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@
// for details. All rights reserved. Use of this source code is governed by a
// BSD-style license that can be found in the LICENSE file.

import 'dart:io';
import 'package:add_asset_link/add_asset_link.dart';

void main(List<String> arguments) {
print(File('assets/test.txt').readAsStringSync());
print('Hello world: ${MyMath.add(3, 4)}!');
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
// Copyright (c) 2024, the Dart project authors. Please see the AUTHORS file
// for details. All rights reserved. Use of this source code is governed by a
// BSD-style license that can be found in the LICENSE file.

import 'package:logging/logging.dart';
import 'package:native_assets_cli/native_assets_cli.dart';
import 'package:native_toolchain_c/native_toolchain_c.dart';

void main(List<String> arguments) async {
await build(arguments, (config, output) async {
final logger = Logger('')
..level = Level.ALL
..onRecord.listen((record) {
print('${record.level.name}: ${record.time}: ${record.message}');
});
await CBuilder.library(
name: 'add',
assetName: 'dylib_add_build',
sources: [
'src/native_add.c',
],
dartBuildFiles: ['hook/build.dart'],
linkModePreference: LinkModePreference.dynamic,
).run(
buildConfig: config,
buildOutput: output,
logger: logger,
linkInPackage: 'add_asset_link',
);
});
}
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,16 @@ import 'package:native_assets_cli/native_assets_cli.dart';

void main(List<String> arguments) async {
await link(arguments, (config, output) async {
final built_dylib = config.assets.first as NativeCodeAsset;
output
..addAsset(
DataAsset(
NativeCodeAsset(
package: 'add_asset_link',
name: 'test_text_file',
file: config.packageRoot.resolve('assets/test.txt'),
name: 'dylib_add_link',
linkMode: built_dylib.linkMode,
os: built_dylib.os,
architecture: built_dylib.architecture,
file: built_dylib.file,
),
)
..addDependency(config.packageRoot.resolve('hook/link.dart'));
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
// Copyright (c) 2024, the Dart project authors. Please see the AUTHORS file
// for details. All rights reserved. Use of this source code is governed by a
// BSD-style license that can be found in the LICENSE file.

export 'src/add_asset_link.dart';
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
// Copyright (c) 2024, the Dart project authors. Please see the AUTHORS file
// for details. All rights reserved. Use of this source code is governed by a
// BSD-style license that can be found in the LICENSE file.

import 'add_asset_link_bindings.dart' as bindings;

class MyMath {
static int add(int a, int b) => bindings.add(a, b);
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
// Copyright (c) 2024, the Dart project authors. Please see the AUTHORS file
// for details. All rights reserved. Use of this source code is governed by a
// BSD-style license that can be found in the LICENSE file.

import 'dart:ffi' as ffi;

@ffi.Native<ffi.Int32 Function(ffi.Int32, ffi.Int32)>(
assetId: 'package:add_asset_link/dylib_add_link')
external int add(
int a,
int b,
);
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,9 @@ dependencies:
meta: ^1.12.0
native_assets_cli:
path: ../../../native_assets_cli/
# native_toolchain_c: ^0.4.0
native_toolchain_c:
path: ../../../native_toolchain_c/

dev_dependencies:
lints: ^3.0.0
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
// Copyright (c) 2024, the Dart project authors. Please see the AUTHORS file
// for details. All rights reserved. Use of this source code is governed by a
// BSD-style license that can be found in the LICENSE file.

#include "native_add.h"

MYLIB_EXPORT int32_t add(int32_t a, int32_t b) {
return a + b;
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
// Copyright (c) 2024, the Dart project authors. Please see the AUTHORS file
// for details. All rights reserved. Use of this source code is governed by a
// BSD-style license that can be found in the LICENSE file.

#include <stdint.h>

#if _WIN32
#define MYLIB_EXPORT __declspec(dllexport)
#else
#define MYLIB_EXPORT
#endif

MYLIB_EXPORT int32_t add(int32_t a, int32_t b);
8 changes: 6 additions & 2 deletions pkgs/native_assets_builder/test_data/manifest.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,11 @@
- drop_dylib_link/hook/build.dart
- drop_dylib_link/bin/drop_dylib_link.dart
- add_asset_link/pubspec.yaml
- add_asset_link/assets/test.txt
- add_asset_link/README.md
- add_asset_link/hook/link.dart
- add_asset_link/bin/add_asset_link.dart
- add_asset_link/lib/add_asset_link.dart
- add_asset_link/lib/src/add_asset_link.dart
- add_asset_link/lib/src/add_asset_link_bindings.dart
- add_asset_link/src/native_add.h
- add_asset_link/src/native_add.c
- add_asset_link/hook/build.dart

0 comments on commit 60604a2

Please sign in to comment.