Skip to content

Commit 7c88b6e

Browse files
authored
Merge pull request #12 from DerKleinePunk/Update326andBuild
Update to Dart 3.3.0 and little changes for Building on Windows
2 parents fa78740 + 37f1e07 commit 7c88b6e

File tree

21 files changed

+103
-411
lines changed

21 files changed

+103
-411
lines changed

.dart_version

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,2 @@
11
# This file contains the current Dart version we build against
2-
3.1.3
2+
3.3.0

.github/workflows/build.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ jobs:
2727
- run: dart pub get
2828
working-directory: ./scripts/build_helpers
2929
- name: Build Dart
30-
run: dart ./scripts/build_helpers/bin/build_dart.dart
30+
run: dart ./scripts/build_helpers/bin/build_dart.dart -v
3131
- uses: threeal/[email protected]
3232
- name: Build Shared Library
3333
run: cmake --build build --config release

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
11
dart-sdk/*
22
.build/*
3+
build/*
34
artifacts/*

.vscode/launch.json

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5,10 +5,17 @@
55
"version": "0.2.0",
66
"configurations": [
77
{
8-
"name": "Dart: Attach to Simple",
9-
"type": "dart",
10-
"request": "attach",
11-
"vmServiceUri": "http://127.0.0.1:5858/"
8+
9+
"name": "(WIN)RealTime Sample",
10+
"type": "cppvsdbg",
11+
"request": "launch",
12+
//"preLaunchTask": "buildSimpelTest",
13+
"program": "${workspaceFolder}/build/Debug/realtime_example.exe",
14+
"args": [],
15+
"stopAtEntry": false,
16+
"cwd": "${fileDirname}",
17+
"environment": [],
18+
"console": "externalTerminal"
1219
}
1320
]
1421
}

README.md

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,12 @@ Github Actions currently builds a Windows x64 `.dll`, A Linux x64 `.so`, and a m
2727
You need:
2828
* git
2929
* Dart 3+
30-
* C++ build tools for your platform (Visual Studio, XCode, gcc, etc)
30+
* C++ build tools for your platform (Visual Studio, XCode, gcc, etc)
31+
* For Windows
32+
* 2019 16.61 with 10.0.20348.0 SDK don't forget install Debugger Tools
33+
* 2022 17 with ? SDK don't forget install Debugger Tools
34+
* 2017 15 with ? SDK don't forget install Debugger Tools
35+
* see dart-sdk\sdk\build\vs_toolchain.py
3136
* CMake
3237

3338
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.
@@ -38,8 +43,14 @@ Optionally, I recommend installing [`depot_tools`](https://www.chromium.org/deve
3843
> This will set up some environment variables that will be needed to build Dart properly.
3944
4045
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.
46+
build_dart commandline
47+
* -v -> Verbose Log
48+
* -t -> Build Type all, release, debug
4149

4250
```bash
51+
cd ./scripts/build_helpers
52+
dart pub get
53+
cd ../..
4354
dart ./scripts/build_helpers/bin/build_dart.dart
4455
```
4556

examples/realtime_example/CMakeLists.txt

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,9 @@ set(CMAKE_CXX_STANDARD 17)
66
set(CMAKE_RUNTIME_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR})
77

88
set(CUTE_FRAMEWORK_STATIC ON)
9+
set(CF_FRAMEWORK_BUILD_TESTS OFF)
10+
# Samples Build on Windows Falied
11+
set(CF_FRAMEWORK_BUILD_SAMPLES OFF)
912

1013
include(FetchContent)
1114
FetchContent_Declare(

examples/realtime_example/dart/drawable.dart

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import 'dart:ffi';
22

3-
class CF_Color extends Struct {
3+
final class CF_Color extends Struct {
44
@Float()
55
external double r;
66

@@ -14,7 +14,7 @@ class CF_Color extends Struct {
1414
external double a;
1515
}
1616

17-
class Drawable extends Struct {
17+
final class Drawable extends Struct {
1818
@Int32()
1919
external int x;
2020

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
1-
name: worm_example
1+
name: realtime_example
22
environment:
3-
sdk: ">=2.17.0 <3.0.0"
3+
sdk: ">=3.0.0 <=3.3.0"
44

55
dependencies:
6-
ffi: ^2.0.1
6+
ffi: ^2.1.0

examples/realtime_example/main.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ bool init_dart() {
2020
DartDllConfig config;
2121
DartDll_Initialize(config);
2222

23+
//if package_config.json not exits run pub get
2324
_dart_isolate = DartDll_LoadScript("dart/main.dart",
2425
"dart/.dart_tool/package_config.json");
2526
if (_dart_isolate == nullptr) {

examples/simple_example/CMakeLists.txt

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,4 +15,10 @@ add_custom_command(TARGET simple_example POST_BUILD
1515
COMMAND_EXPAND_LISTS
1616
)
1717

18-
target_link_libraries(simple_example PUBLIC dart_dll)
18+
add_dependencies(simple_example ALWAYS_DO_POST_BUILD)
19+
20+
target_link_libraries(simple_example PUBLIC dart_dll)
21+
22+
if (MSVC)
23+
set_property(TARGET simple_example PROPERTY VS_DEBUGGER_WORKING_DIRECTORY $<TARGET_FILE_DIR:simple_example>)
24+
endif()

examples/simple_example_ffi/CMakeLists.txt

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,8 @@ target_include_directories(simple_example_ffi PRIVATE
1111

1212
add_custom_command(TARGET simple_example_ffi POST_BUILD
1313
COMMAND ${CMAKE_COMMAND} -E copy -t $<TARGET_FILE_DIR:simple_example_ffi> $<TARGET_RUNTIME_DLLS:simple_example_ffi>
14+
COMMAND ${CMAKE_COMMAND} -E copy -t $<TARGET_FILE_DIR:simple_example_ffi> ${PROJECT_SOURCE_DIR}/hello_world_ffi.dart
15+
COMMAND ${CMAKE_COMMAND} -E copy_directory ${PROJECT_SOURCE_DIR}/.dart_tool $<TARGET_FILE_DIR:simple_example_ffi>/.dart_tool
1416
COMMAND_EXPAND_LISTS
1517
)
1618

examples/simple_example_ffi/main.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ int main() {
3434

3535
// Load your main isolate file, also providing the path to a package config if one exists.
3636
// The build makes sure these are coppied to the output directory for running the example
37-
Dart_Isolate isolate = DartDll_LoadScript("hello_world.dart", ".dart_tool/package_config.json");
37+
Dart_Isolate isolate = DartDll_LoadScript("hello_world_ffi.dart", ".dart_tool/package_config.json");
3838
if (isolate == nullptr) {
3939
return -1;
4040
}
Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
name: simple_example_ffi
22
environment:
3-
sdk: ">=2.17.0 <3.0.0"
3+
sdk: ">=3.0.0 <=3.3.0"
44

55
dependencies:
6-
ffi: ^2.0.1
6+
ffi: ^2.1.0

scripts/build_helpers/.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
11
# https://dart.dev/guides/libraries/private-files
22
# Created by `dart pub`
33
.dart_tool/
4+
pubspec.lock

scripts/build_helpers/bin/build_dart.dart

Lines changed: 47 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -8,14 +8,45 @@ import 'package:path/path.dart' as path;
88

99
void main(List<String> args) async {
1010
final parser = ArgParser();
11-
parser.addFlag('verbose', abbr: 'v');
11+
parser.addFlag('verbose', abbr: 'v', help: 'enable all debug');
12+
parser.addMultiOption(
13+
'target',
14+
abbr: 't',
15+
help: 'Target to build (release or debug)',
16+
allowed: ['debug', 'release', 'all'],
17+
defaultsTo: ['release'],
18+
);
19+
parser.addFlag('help', abbr: 'h');
20+
21+
ArgResults? argResults;
22+
try {
23+
argResults = parser.parse(args);
24+
} catch (error) {
25+
if (error is! FormatException) rethrow;
26+
print(parser.usage);
27+
exit(-1);
28+
}
29+
30+
if (argResults['help'] == true) {
31+
print(parser.usage);
32+
return;
33+
}
1234

13-
final argResults = parser.parse(args);
1435
Level logLevel = Level.info;
1536
if (argResults['verbose'] == true) {
16-
logLevel = Level.debug;
37+
logLevel = Level.all;
1738
}
18-
BuildToolsLogger.initLogger(logLevel: logLevel);
39+
40+
BuildToolsLogger.initLogger(
41+
logLevel: logLevel,
42+
);
43+
44+
var buildTargets = argResults['target'] as List<String>;
45+
if (buildTargets.contains('all')) {
46+
buildTargets = ['debug', 'release'];
47+
}
48+
49+
BuildToolsLogger.shared.d('Build Targets $buildTargets');
1950

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

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

50-
if (!await _buildDart()) {
51-
exit(-1);
85+
for (var target in buildTargets) {
86+
if (!await _buildDart(target)) {
87+
exit(-1);
88+
}
5289
}
5390
} catch (e) {
5491
BuildToolsLogger.shared.f('Caught an exception building the Dart SDK:');
@@ -125,7 +162,7 @@ Future<bool> _patchDartSdk() async {
125162
logger.i("Patching the Dart SDK to create libdart");
126163
var result = await Process.run('git', ['apply', '../../dart_sdk.patch'],
127164
runInShell: true);
128-
logger.d(result.stdout);
165+
logger.d('Patch result is ${result.exitCode}');
129166
return result.exitCode;
130167
});
131168
if (result != 0) {
@@ -135,12 +172,13 @@ Future<bool> _patchDartSdk() async {
135172
return result == 0;
136173
}
137174

138-
Future<bool> _buildDart() async {
175+
Future<bool> _buildDart(String buildType) async {
139176
final logger = BuildToolsLogger.shared;
177+
logger.d('starting build for $buildType');
140178
final result = await inDir('dart-sdk/sdk', () async {
141179
logger.i("Building libdart");
142180
var script = './tools/build.py';
143-
var args = ['--no-goma', '-m', 'release', 'libdart'];
181+
var args = ['--no-goma', '-m', buildType, 'libdart'];
144182
var command = script;
145183
if (Platform.isWindows) {
146184
command = 'python';

scripts/build_helpers/lib/build_helpers.dart

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,11 +15,12 @@ class BuildToolsLogger {
1515
}
1616

1717
static Logger initLogger({Level logLevel = Level.info}) {
18-
return Logger(
18+
_shared = Logger(
1919
filter: ProductionFilter(),
2020
level: logLevel,
2121
printer: SimplePrinter(),
2222
);
23+
return shared;
2324
}
2425
}
2526

0 commit comments

Comments
 (0)