Skip to content

Commit b24bdd9

Browse files
committed
feat: Update to Dart 3.5, fix build
Updated to Dart 3.5, fixed a lot of build mistakes in various CMakeLists.
1 parent ccef86b commit b24bdd9

File tree

12 files changed

+64
-26
lines changed

12 files changed

+64
-26
lines changed

Diff for: .dart_version

+1-1
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.3.0
2+
3.5.0

Diff for: CMakeLists.txt

+1-1
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ cmake_minimum_required(VERSION 3.21)
22

33
project(DartSharedLibrary VERSION 0.1)
44

5-
option(BUILD_SMAPLES "Build the Sampels" ON)
5+
option(BUILD_SAMPLES "Build the Samples" ON)
66

77
set(CMAKE_CXX_STANDARD 11)
88
set(CMAKE_CXX_STANDARD_REQUIRED True)

Diff for: examples/realtime_example/CMakeLists.txt

+4-6
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,6 @@ cmake_minimum_required(VERSION 3.21)
33
project(realtime_example)
44
set(CMAKE_CXX_STANDARD 17)
55

6-
set(CMAKE_RUNTIME_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR})
7-
86
set(CUTE_FRAMEWORK_STATIC ON)
97
set(CF_FRAMEWORK_BUILD_TESTS OFF)
108
# Samples Build on Windows Falied
@@ -14,6 +12,7 @@ include(FetchContent)
1412
FetchContent_Declare(
1513
cute
1614
GIT_REPOSITORY https://github.com/RandyGaul/cute_framework
15+
GIT_TAG a2341c72f02e019e157cfc3997cd81d98c825004
1716
)
1817
FetchContent_MakeAvailable(cute)
1918

@@ -34,12 +33,11 @@ if(LINUX)
3433
set(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} -export-dynamic")
3534
endif()
3635

37-
add_custom_target(ALWAYS_DO_POST_BUILD
38-
COMMAND ${CMAKE_COMMAND} -E copy -t $<TARGET_FILE_DIR:realtime_example> $<TARGET_RUNTIME_DLLS:simple_example_ffi>
39-
COMMAND ${CMAKE_COMMAND} -E copy_directory ${PROJECT_SOURCE_DIR}/dart $<TARGET_FILE_DIR:realtime_example>/dart
36+
add_custom_command(TARGET realtime_example POST_BUILD
37+
COMMAND ${CMAKE_COMMAND} -E copy -t $<TARGET_FILE_DIR:realtime_example> $<TARGET_RUNTIME_DLLS:realtime_example>
38+
COMMAND ${CMAKE_COMMAND} -E copy_directory ${PROJECT_SOURCE_DIR}/dart/ $<TARGET_FILE_DIR:realtime_example>/dart
4039
COMMAND_EXPAND_LISTS
4140
)
42-
add_dependencies(realtime_example ALWAYS_DO_POST_BUILD)
4341

4442
target_link_libraries(realtime_example PUBLIC dart_dll cute)
4543

Diff for: examples/realtime_example/dart/main.dart

+9-6
Original file line numberDiff line numberDiff line change
@@ -20,9 +20,10 @@ class Wall {
2020
List<Wall> walls = [];
2121

2222
// Dot!
23+
final int speed = 80;
2324
int dotEntity = 0;
24-
int dotX = 0;
25-
int dotY = 0;
25+
double dotX = 0;
26+
double dotY = 0;
2627
bool movingLeft = true;
2728

2829
void main() {
@@ -42,25 +43,27 @@ void main() {
4243

4344
dotEntity = ffi.createEntity(0, 0, 10, 10);
4445
final drawable = ffi.getDrawable(dotEntity);
46+
drawable.ref.color.r = 0.0;
4547
drawable.ref.color.g = 1.0;
48+
drawable.ref.color.b = 0.0;
4649
}
4750

4851
void frame(double dt) {
4952
if (movingLeft) {
50-
dotX -= 3;
53+
dotX -= (speed * dt);
5154
if (dotX < -200) {
5255
dotX = -200;
5356
movingLeft = false;
5457
}
5558
} else {
56-
dotX += 3;
59+
dotX += (speed * dt);
5760
if (dotX > 200) {
5861
dotX = 200;
5962
movingLeft = true;
6063
}
6164
}
6265

6366
final dotDrawable = ffi.getDrawable(dotEntity);
64-
dotDrawable.ref.x = dotX;
65-
dotDrawable.ref.y = dotY;
67+
dotDrawable.ref.x = dotX.floor();
68+
dotDrawable.ref.y = dotY.floor();
6669
}

Diff for: examples/realtime_example/dart/pubspec.yaml

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
name: realtime_example
22
environment:
3-
sdk: ">=3.0.0 <=3.3.0"
3+
sdk: ">=3.0.0 <4.0.0"
44

55
dependencies:
66
ffi: ^2.1.0

Diff for: examples/realtime_example/main.cpp

+4-4
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
#include <cute.h>
22
using namespace Cute;
33

4+
#include <iostream>
45
#include <dart_dll.h>
56

67
#include <dart_tools_api.h>
@@ -100,7 +101,7 @@ void render_drawables() {
100101
// These need to be exposed as "C" functions and be exported
101102
//
102103
#if defined(_WIN32)
103-
#define WORM_EXPORT exten "C" __declspec(dllexport)
104+
#define WORM_EXPORT extern "C" __declspec(dllexport)
104105
#else
105106
#define WORM_EXPORT extern "C" __attribute__((visibility("default"))) __attribute((used))
106107
#endif
@@ -137,10 +138,9 @@ WORM_EXPORT bool get_key_just_pressed(int key_code) {
137138

138139
int main(int argc, char* argv[]) {
139140
// Create a window with a resolution of 640 x 480.
140-
int options =
141-
APP_OPTIONS_DEFAULT_GFX_CONTEXT | APP_OPTIONS_WINDOW_POS_CENTERED;
141+
int options = APP_OPTIONS_WINDOW_POS_CENTERED;
142142
Result result =
143-
make_app("Fancy Window Title", 0, 0, 640, 480, options, argv[0]);
143+
make_app("Fancy Window Title", 0, 0, 0, 640, 480, options, argv[0]);
144144
if (is_error(result)) return -1;
145145

146146
if (!init_dart()) return -1;

Diff for: examples/simple_example/CMakeLists.txt

+1-1
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ add_custom_command(TARGET simple_example POST_BUILD
1818
target_link_libraries(simple_example PUBLIC dart_dll)
1919

2020
if (MSVC)
21-
set_property(TARGET realtime_example PROPERTY VS_DEBUGGER_WORKING_DIRECTORY $<TARGET_FILE_DIR:simple_example>)
21+
set_property(TARGET simple_example PROPERTY VS_DEBUGGER_WORKING_DIRECTORY $<TARGET_FILE_DIR:simple_example>)
2222
endif()
2323

2424
set(EXECUTABLE_OUTPUT_PATH "${EXECUTABLE_OUTPUT_PATH}/simple_example")

Diff for: examples/simple_example_ffi/CMakeLists.txt

+4-2
Original file line numberDiff line numberDiff line change
@@ -16,8 +16,10 @@ add_custom_command(TARGET simple_example_ffi POST_BUILD
1616
COMMAND_EXPAND_LISTS
1717
)
1818

19+
target_link_libraries(simple_example_ffi PUBLIC dart_dll)
20+
1921
if (MSVC)
20-
set_property(TARGET realtime_example PROPERTY VS_DEBUGGER_WORKING_DIRECTORY $<TARGET_FILE_DIR:simple_example_ffi>)
22+
set_property(TARGET simple_example_ffi PROPERTY VS_DEBUGGER_WORKING_DIRECTORY $<TARGET_FILE_DIR:simple_example_ffi>)
2123
endif()
2224

23-
target_link_libraries(simple_example_ffi PUBLIC dart_dll)
25+
set(EXECUTABLE_OUTPUT_PATH "${EXECUTABLE_OUTPUT_PATH}/simple_example_ffi")

Diff for: examples/simple_example_ffi/pubspec.yaml

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
name: simple_example_ffi
22
environment:
3-
sdk: ">=3.0.0 <=3.3.0"
3+
sdk: ">=3.0.0 <4.0.0"
44

55
dependencies:
66
ffi: ^2.1.0

Diff for: scripts/build_helpers/bin/build_dart.dart

+1-1
Original file line numberDiff line numberDiff line change
@@ -178,7 +178,7 @@ Future<bool> _buildDart(String buildType) async {
178178
final result = await inDir('dart-sdk/sdk', () async {
179179
logger.i("Building libdart");
180180
var script = './tools/build.py';
181-
var args = ['--no-goma', '-m', buildType, 'libdart'];
181+
var args = ['-m', buildType, 'libdart'];
182182
var command = script;
183183
if (Platform.isWindows) {
184184
command = 'python';

Diff for: src/CMakeLists.txt

+2
Original file line numberDiff line numberDiff line change
@@ -66,6 +66,8 @@ if(WIN32)
6666
Iphlpapi
6767
Psapi
6868
shlwapi
69+
pathcch
70+
ntdll
6971
)
7072
set_property(TARGET dart_dll PROPERTY
7173
MSVC_RUNTIME_LIBRARY "MultiThreaded$<$<CONFIG:Debug>:Debug>")

Diff for: src/isolate_setup.cpp

+35-2
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,8 @@
99
#include <bin/dfe.h>
1010
#include <bin/isolate_data.h>
1111
#include <bin/loader.h>
12+
#include <bin/snapshot_utils.h>
13+
#include <platform/utils.h>
1214

1315
using namespace dart::bin;
1416

@@ -158,11 +160,42 @@ Dart_Isolate CreateIsolate(bool is_main_isolate,
158160
void* callback_data,
159161
char** error) {
160162
Dart_Handle result;
161-
162163
uint8_t* kernel_buffer = nullptr;
163164
intptr_t kernel_buffer_size;
165+
AppSnapshot* app_snapshot = nullptr;
166+
std::shared_ptr<uint8_t> kernel_buffer_ptr;
167+
168+
bool isolate_run_app_snapshot = false;
169+
const uint8_t* isolate_snapshot_data = kDartCoreIsolateSnapshotData;
170+
const uint8_t* isolate_snapshot_instructions =
171+
kDartCoreIsolateSnapshotInstructions;
172+
173+
if (!is_main_isolate) {
174+
app_snapshot = Snapshot::TryReadAppSnapshot(script_uri);
175+
if (app_snapshot != nullptr && app_snapshot->IsJITorAOT()) {
176+
if (app_snapshot->IsAOT()) {
177+
*error = dart::Utils::SCreate(
178+
"The uri(%s) provided to `Isolate.spawnUri()` is an "
179+
"AOT snapshot and the JIT VM cannot spawn an isolate using it.",
180+
script_uri);
181+
delete app_snapshot;
182+
return nullptr;
183+
}
184+
isolate_run_app_snapshot = true;
185+
const uint8_t* ignore_vm_snapshot_data;
186+
const uint8_t* ignore_vm_snapshot_instructions;
187+
app_snapshot->SetBuffers(
188+
&ignore_vm_snapshot_data, &ignore_vm_snapshot_instructions,
189+
&isolate_snapshot_data, &isolate_snapshot_instructions);
190+
}
191+
}
192+
193+
if (kernel_buffer == nullptr && !isolate_run_app_snapshot) {
194+
dfe.ReadScript(script_uri, app_snapshot, &kernel_buffer,
195+
&kernel_buffer_size, /*decode_uri=*/true,
196+
&kernel_buffer_ptr);
197+
}
164198

165-
dfe.ReadScript(script_uri, &kernel_buffer, &kernel_buffer_size);
166199
flags->null_safety = true;
167200

168201
DllIsolateGroupData* isolate_group_data = new DllIsolateGroupData(

0 commit comments

Comments
 (0)