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

Update to Dart 3.3.0 and little changes for Building on Windows #12

Merged
merged 5 commits into from
Feb 22, 2024
Merged
Show file tree
Hide file tree
Changes from 4 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
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.2.6
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
Copy link
Owner

Choose a reason for hiding this comment

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

I think the windows SDK is always going to be the same, so I think the answer is VS 2019+ with Windows SDK 10.0.20348.0

* 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
2 changes: 1 addition & 1 deletion examples/realtime_example/dart/pubspec.yaml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
name: worm_example
environment:
sdk: ">=2.17.0 <3.0.0"
sdk: ">=3.0.0 <4.0.0"

dependencies:
ffi: ^2.0.1
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)
Copy link
Owner

@fuzzybinary fuzzybinary Feb 21, 2024

Choose a reason for hiding this comment

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

Do you have to wrap this in MSVC? VS_DEBUGGER_WORKING_DIRECTORY should silently fail for anything other than MSVC.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

No i build with VSCode but you have it on other samples why not in simple ?
There ist also an "Problem" realtime_example is the only sample wich is in the Debug folder all other samples only
in example<name>\ debug folder. I understand not why.

my practice is put the output too an bin folder i no that makes small count of developer it is easier to wirte launch.json for debugging

Copy link
Owner

Choose a reason for hiding this comment

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

Yeah, to be honest I'm not as good with CMake as I'd like, so I'm not surprised there are weird issues.

I'll leave this in if it's working for you and take another pass at the CMake files at some point.

set_property(TARGET simple_example PROPERTY VS_DEBUGGER_WORKING_DIRECTORY $<TARGET_FILE_DIR:simple_example>)
endif()
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
51 changes: 42 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,33 @@ 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.addOption('buildType',
abbr: 't',
help: 'build typ release or debug. all for both',
allowed: ['all', 'debug', 'release']);

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

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,
);

String buildType = argResults['buildType'] ?? "all";
Copy link
Owner

Choose a reason for hiding this comment

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

I think the default should be release not all

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Default working without ?? all i think. it looks on my tests now


BuildToolsLogger.shared.d('Build Typ $buildType');

if (!checkRightDirectory()) {
// Not run from root. Exit.
Expand Down Expand Up @@ -47,8 +66,21 @@ void main(List<String> args) async {
exit(-1);
}

if (!await _buildDart()) {
exit(-1);
if (buildType == "all") {
Copy link
Owner

Choose a reason for hiding this comment

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

I think there's a simpler way to do this. I'll take a stab at it and modify the PR this evening.

Copy link
Owner

Choose a reason for hiding this comment

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

if (!await _buildDart('release')) {
exit(-1);
}
if (!await _buildDart('debug')) {
exit(-1);
}
} else if (buildType == "release") {
if (!await _buildDart('release')) {
exit(-1);
}
} else if (buildType == "debug") {
if (!await _buildDart('debug')) {
exit(-1);
}
}
} catch (e) {
BuildToolsLogger.shared.f('Caught an exception building the Dart SDK:');
Expand Down Expand Up @@ -125,7 +157,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 +167,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(
Copy link
Owner

Choose a reason for hiding this comment

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

Why this change?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Please Debug your Code. Without this the shared Logger hast always the Level Info so the Init do not work
for other Logger called in Script. I have Teste with more Debug log and Can't see the Logoutput.

final logger = BuildToolsLogger.shared;

static Logger get shared {
_shared ??= initLogger();
return _shared!;
}

Add First Call shared ist null and creates new one with default level. so i Init in Init...

filter: ProductionFilter(),
level: logLevel,
printer: SimplePrinter(),
);
return shared;
}
}

Expand Down
Loading