Skip to content

Commit

Permalink
Merge pull request #12 from DerKleinePunk/Update326andBuild
Browse files Browse the repository at this point in the history
Update to Dart 3.3.0 and little changes for Building on Windows
  • Loading branch information
fuzzybinary authored Feb 22, 2024
2 parents fa78740 + 37f1e07 commit 7c88b6e
Show file tree
Hide file tree
Showing 21 changed files with 103 additions and 411 deletions.
2 changes: 1 addition & 1 deletion .dart_version
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
# This file contains the current Dart version we build against
3.1.3
3.3.0
2 changes: 1 addition & 1 deletion .github/workflows/build.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ jobs:
- run: dart pub get
working-directory: ./scripts/build_helpers
- name: Build Dart
run: dart ./scripts/build_helpers/bin/build_dart.dart
run: dart ./scripts/build_helpers/bin/build_dart.dart -v
- uses: threeal/[email protected]
- name: Build Shared Library
run: cmake --build build --config release
Expand Down
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
dart-sdk/*
.build/*
build/*
artifacts/*
15 changes: 11 additions & 4 deletions .vscode/launch.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,17 @@
"version": "0.2.0",
"configurations": [
{
"name": "Dart: Attach to Simple",
"type": "dart",
"request": "attach",
"vmServiceUri": "http://127.0.0.1:5858/"

"name": "(WIN)RealTime Sample",
"type": "cppvsdbg",
"request": "launch",
//"preLaunchTask": "buildSimpelTest",
"program": "${workspaceFolder}/build/Debug/realtime_example.exe",
"args": [],
"stopAtEntry": false,
"cwd": "${fileDirname}",
"environment": [],
"console": "externalTerminal"
}
]
}
13 changes: 12 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,12 @@ Github Actions currently builds a Windows x64 `.dll`, A Linux x64 `.so`, and a m
You need:
* git
* Dart 3+
* C++ build tools for your platform (Visual Studio, XCode, gcc, etc)
* C++ build tools for your platform (Visual Studio, XCode, gcc, etc)
* For Windows
* 2019 16.61 with 10.0.20348.0 SDK don't forget install Debugger Tools
* 2022 17 with ? SDK don't forget install Debugger Tools
* 2017 15 with ? SDK don't forget install Debugger Tools
* see dart-sdk\sdk\build\vs_toolchain.py
* CMake

Optionally, I recommend installing [`depot_tools`](https://www.chromium.org/developers/how-tos/depottools/) and making sure it is on your path before running setup scripts. Without depot_tools, the scripts will download them anyway, but having them already set up will save you some time with subsequent builds.
Expand All @@ -38,8 +43,14 @@ Optionally, I recommend installing [`depot_tools`](https://www.chromium.org/deve
> This will set up some environment variables that will be needed to build Dart properly.
The first step is to build a statically linkable verison of Dart. This requires that we download Dart, patch some of the Dart build files, and then run the actual build. Thankfully there is a Dart script to do this.
build_dart commandline
* -v -> Verbose Log
* -t -> Build Type all, release, debug

```bash
cd ./scripts/build_helpers
dart pub get
cd ../..
dart ./scripts/build_helpers/bin/build_dart.dart
```

Expand Down
3 changes: 3 additions & 0 deletions examples/realtime_example/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,9 @@ set(CMAKE_CXX_STANDARD 17)
set(CMAKE_RUNTIME_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR})

set(CUTE_FRAMEWORK_STATIC ON)
set(CF_FRAMEWORK_BUILD_TESTS OFF)
# Samples Build on Windows Falied
set(CF_FRAMEWORK_BUILD_SAMPLES OFF)

include(FetchContent)
FetchContent_Declare(
Expand Down
4 changes: 2 additions & 2 deletions examples/realtime_example/dart/drawable.dart
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import 'dart:ffi';

class CF_Color extends Struct {
final class CF_Color extends Struct {
@Float()
external double r;

Expand All @@ -14,7 +14,7 @@ class CF_Color extends Struct {
external double a;
}

class Drawable extends Struct {
final class Drawable extends Struct {
@Int32()
external int x;

Expand Down
6 changes: 3 additions & 3 deletions examples/realtime_example/dart/pubspec.yaml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
name: worm_example
name: realtime_example
environment:
sdk: ">=2.17.0 <3.0.0"
sdk: ">=3.0.0 <=3.3.0"

dependencies:
ffi: ^2.0.1
ffi: ^2.1.0
1 change: 1 addition & 0 deletions examples/realtime_example/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ bool init_dart() {
DartDllConfig config;
DartDll_Initialize(config);

//if package_config.json not exits run pub get
_dart_isolate = DartDll_LoadScript("dart/main.dart",
"dart/.dart_tool/package_config.json");
if (_dart_isolate == nullptr) {
Expand Down
8 changes: 7 additions & 1 deletion examples/simple_example/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -15,4 +15,10 @@ add_custom_command(TARGET simple_example POST_BUILD
COMMAND_EXPAND_LISTS
)

target_link_libraries(simple_example PUBLIC dart_dll)
add_dependencies(simple_example ALWAYS_DO_POST_BUILD)

target_link_libraries(simple_example PUBLIC dart_dll)

if (MSVC)
set_property(TARGET simple_example PROPERTY VS_DEBUGGER_WORKING_DIRECTORY $<TARGET_FILE_DIR:simple_example>)
endif()
2 changes: 2 additions & 0 deletions examples/simple_example_ffi/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,8 @@ target_include_directories(simple_example_ffi PRIVATE

add_custom_command(TARGET simple_example_ffi POST_BUILD
COMMAND ${CMAKE_COMMAND} -E copy -t $<TARGET_FILE_DIR:simple_example_ffi> $<TARGET_RUNTIME_DLLS:simple_example_ffi>
COMMAND ${CMAKE_COMMAND} -E copy -t $<TARGET_FILE_DIR:simple_example_ffi> ${PROJECT_SOURCE_DIR}/hello_world_ffi.dart
COMMAND ${CMAKE_COMMAND} -E copy_directory ${PROJECT_SOURCE_DIR}/.dart_tool $<TARGET_FILE_DIR:simple_example_ffi>/.dart_tool
COMMAND_EXPAND_LISTS
)

Expand Down
2 changes: 1 addition & 1 deletion examples/simple_example_ffi/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ int main() {

// Load your main isolate file, also providing the path to a package config if one exists.
// The build makes sure these are coppied to the output directory for running the example
Dart_Isolate isolate = DartDll_LoadScript("hello_world.dart", ".dart_tool/package_config.json");
Dart_Isolate isolate = DartDll_LoadScript("hello_world_ffi.dart", ".dart_tool/package_config.json");
if (isolate == nullptr) {
return -1;
}
Expand Down
4 changes: 2 additions & 2 deletions examples/simple_example_ffi/pubspec.yaml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
name: simple_example_ffi
environment:
sdk: ">=2.17.0 <3.0.0"
sdk: ">=3.0.0 <=3.3.0"

dependencies:
ffi: ^2.0.1
ffi: ^2.1.0
1 change: 1 addition & 0 deletions scripts/build_helpers/.gitignore
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
# https://dart.dev/guides/libraries/private-files
# Created by `dart pub`
.dart_tool/
pubspec.lock
56 changes: 47 additions & 9 deletions scripts/build_helpers/bin/build_dart.dart
Original file line number Diff line number Diff line change
Expand Up @@ -8,14 +8,45 @@ import 'package:path/path.dart' as path;

void main(List<String> args) async {
final parser = ArgParser();
parser.addFlag('verbose', abbr: 'v');
parser.addFlag('verbose', abbr: 'v', help: 'enable all debug');
parser.addMultiOption(
'target',
abbr: 't',
help: 'Target to build (release or debug)',
allowed: ['debug', 'release', 'all'],
defaultsTo: ['release'],
);
parser.addFlag('help', abbr: 'h');

ArgResults? argResults;
try {
argResults = parser.parse(args);
} catch (error) {
if (error is! FormatException) rethrow;
print(parser.usage);
exit(-1);
}

if (argResults['help'] == true) {
print(parser.usage);
return;
}

final argResults = parser.parse(args);
Level logLevel = Level.info;
if (argResults['verbose'] == true) {
logLevel = Level.debug;
logLevel = Level.all;
}
BuildToolsLogger.initLogger(logLevel: logLevel);

BuildToolsLogger.initLogger(
logLevel: logLevel,
);

var buildTargets = argResults['target'] as List<String>;
if (buildTargets.contains('all')) {
buildTargets = ['debug', 'release'];
}

BuildToolsLogger.shared.d('Build Targets $buildTargets');

if (!checkRightDirectory()) {
// Not run from root. Exit.
Expand All @@ -29,6 +60,10 @@ void main(List<String> args) async {
'DEPOT_TOOLS_WIN_TOOOLCHAIN not set! Run ./setup_env.ps1 before running this script!');
exit(-1);
}
final gypMsysVersion = Platform.environment['GYP_MSVS_VERSION'];
final gypMsysOverridePath = Platform.environment['GYP_MSVS_OVERRIDE_PATH'];
BuildToolsLogger.shared.d('GYP_MSVS_VERSION $gypMsysVersion');
BuildToolsLogger.shared.d('GYP_MSVS_OVERRIDE_PATH $gypMsysOverridePath');
}

if (!await checkForDepotTools()) {
Expand All @@ -47,8 +82,10 @@ void main(List<String> args) async {
exit(-1);
}

if (!await _buildDart()) {
exit(-1);
for (var target in buildTargets) {
if (!await _buildDart(target)) {
exit(-1);
}
}
} catch (e) {
BuildToolsLogger.shared.f('Caught an exception building the Dart SDK:');
Expand Down Expand Up @@ -125,7 +162,7 @@ Future<bool> _patchDartSdk() async {
logger.i("Patching the Dart SDK to create libdart");
var result = await Process.run('git', ['apply', '../../dart_sdk.patch'],
runInShell: true);
logger.d(result.stdout);
logger.d('Patch result is ${result.exitCode}');
return result.exitCode;
});
if (result != 0) {
Expand All @@ -135,12 +172,13 @@ Future<bool> _patchDartSdk() async {
return result == 0;
}

Future<bool> _buildDart() async {
Future<bool> _buildDart(String buildType) async {
final logger = BuildToolsLogger.shared;
logger.d('starting build for $buildType');
final result = await inDir('dart-sdk/sdk', () async {
logger.i("Building libdart");
var script = './tools/build.py';
var args = ['--no-goma', '-m', 'release', 'libdart'];
var args = ['--no-goma', '-m', buildType, 'libdart'];
var command = script;
if (Platform.isWindows) {
command = 'python';
Expand Down
3 changes: 2 additions & 1 deletion scripts/build_helpers/lib/build_helpers.dart
Original file line number Diff line number Diff line change
Expand Up @@ -15,11 +15,12 @@ class BuildToolsLogger {
}

static Logger initLogger({Level logLevel = Level.info}) {
return Logger(
_shared = Logger(
filter: ProductionFilter(),
level: logLevel,
printer: SimplePrinter(),
);
return shared;
}
}

Expand Down
Loading

0 comments on commit 7c88b6e

Please sign in to comment.