Skip to content

Commit

Permalink
save
Browse files Browse the repository at this point in the history
  • Loading branch information
rainyl committed Feb 19, 2025
1 parent 7ce2185 commit 0593346
Show file tree
Hide file tree
Showing 7 changed files with 46 additions and 215 deletions.
2 changes: 1 addition & 1 deletion example/lib/main.dart
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import 'dart:typed_data';

import 'package:flutter/foundation.dart';
import 'package:flutter/material.dart';
import 'package:opencv_dart/opencv_dart.dart' as cv;
import 'package:dartcv4/dartcv.dart' as cv;
import 'package:image_picker/image_picker.dart';

void main() {
Expand Down
47 changes: 2 additions & 45 deletions hook/build.dart
Original file line number Diff line number Diff line change
Expand Up @@ -4,54 +4,11 @@

import 'dart:io';

import 'package:dartcv4/src/hook_helpers/c_build.dart';
import 'package:dartcv4/src/hook_helpers/download.dart';
import 'package:dartcv4/src/hook_helpers/hashes.dart';
import 'package:logging/logging.dart';
import 'package:native_assets_cli/code_assets_builder.dart';
import 'package:dartcv4/src/hook_helpers/run_build.dart';
import 'package:native_assets_cli/native_assets_cli.dart';

void main(List<String> args) async {
// TODO(https://github.com/dart-lang/native/issues/39): Use user-defines to
// control this instead.
const localBuild = true;

Logger("").warning("AAAAAAAAAAA");

await build(args, (input, output) async {
// ignore: dead_code
if (localBuild) {
await runBuild(input, output);
} else {
final targetOS = input.config.code.targetOS;
final targetArchitecture = input.config.code.targetArchitecture;
final iOSSdk =
targetOS == OS.iOS ? input.config.code.iOS.targetSdk : null;
final outputDirectory = Directory.fromUri(input.outputDirectory);
final file = await downloadAsset(
targetOS,
targetArchitecture,
iOSSdk,
outputDirectory,
);
final fileHash = await hashAsset(file);
final expectedHash = assetHashes[createTargetName(
targetOS.name,
targetArchitecture.name,
iOSSdk?.type,
)];
if (fileHash != expectedHash) {
throw Exception('File $file was not downloaded correctly. '
'Found hash $fileHash, expected $expectedHash.');
}
output.assets.code.add(CodeAsset(
package: input.packageName,
name: 'native_add.dart',
linkMode: DynamicLoadingBundled(),
os: targetOS,
architecture: targetArchitecture,
file: file.uri,
));
}
await runBuild(input, output);
});
}
110 changes: 0 additions & 110 deletions lib/src/hook_helpers/c_build.dart

This file was deleted.

46 changes: 0 additions & 46 deletions lib/src/hook_helpers/download.dart

This file was deleted.

42 changes: 42 additions & 0 deletions lib/src/hook_helpers/run_build.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
// Copyright (c) 2025, 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/code_assets_builder.dart';
import 'package:native_toolchain_cmake/native_toolchain_cmake.dart';

Future<void> runBuild(BuildInput input, BuildOutputBuilder output, {List<String>? optionalModules}) async {
final builder = CMakeBuilder.create(
name: input.packageName,
sourceDir: input.packageRoot.resolve('src').toFilePath(),
targets: ['install'],
// Waiting for the support of user-defined variables,
// which can be used to choose the components
defines: {
'CMAKE_INSTALL_PREFIX': input.outputDirectory.resolve('install').toFilePath(),
},
);
await builder.run(
input: input,
output: output,
logger: Logger('')
..level = Level.ALL
..onRecord.listen((record) => print(record.message)),
);

final tgtName = input.config.code.targetOS.dylibFileName(input.packageName);

output.assets.code.addAll(
[
CodeAsset(
package: input.packageName,
name: "${input.packageName}.dart",
file: Uri.parse('${input.outputDirectory.resolve('install/$tgtName')}'),
linkMode: DynamicLoadingBundled(),
os: input.config.code.targetOS,
architecture: input.config.code.targetArchitecture,
),
],
);
}
13 changes: 0 additions & 13 deletions lib/src/hook_helpers/version.dart

This file was deleted.

1 change: 1 addition & 0 deletions pubspec.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ dependencies:
native_assets_cli: ^0.11.0
logging: ^1.2.0
native_toolchain_c: ^0.8.0
native_toolchain_cmake: ^0.0.1

dev_dependencies:
ffigen: ^16.1.0
Expand Down

0 comments on commit 0593346

Please sign in to comment.