From b24bdd966bf236912d7846eb3428aa6777efb785 Mon Sep 17 00:00:00 2001 From: Jeff Ward Date: Fri, 9 Aug 2024 23:25:58 -0400 Subject: [PATCH] feat: Update to Dart 3.5, fix build Updated to Dart 3.5, fixed a lot of build mistakes in various CMakeLists. --- .dart_version | 2 +- CMakeLists.txt | 2 +- examples/realtime_example/CMakeLists.txt | 10 +++--- examples/realtime_example/dart/main.dart | 15 +++++---- examples/realtime_example/dart/pubspec.yaml | 2 +- examples/realtime_example/main.cpp | 8 ++--- examples/simple_example/CMakeLists.txt | 2 +- examples/simple_example_ffi/CMakeLists.txt | 6 ++-- examples/simple_example_ffi/pubspec.yaml | 2 +- scripts/build_helpers/bin/build_dart.dart | 2 +- src/CMakeLists.txt | 2 ++ src/isolate_setup.cpp | 37 +++++++++++++++++++-- 12 files changed, 64 insertions(+), 26 deletions(-) diff --git a/.dart_version b/.dart_version index a2ec1a2..7c800b3 100644 --- a/.dart_version +++ b/.dart_version @@ -1,2 +1,2 @@ # This file contains the current Dart version we build against -3.3.0 \ No newline at end of file +3.5.0 \ No newline at end of file diff --git a/CMakeLists.txt b/CMakeLists.txt index 9c19b46..1915044 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -2,7 +2,7 @@ cmake_minimum_required(VERSION 3.21) project(DartSharedLibrary VERSION 0.1) -option(BUILD_SMAPLES "Build the Sampels" ON) +option(BUILD_SAMPLES "Build the Samples" ON) set(CMAKE_CXX_STANDARD 11) set(CMAKE_CXX_STANDARD_REQUIRED True) diff --git a/examples/realtime_example/CMakeLists.txt b/examples/realtime_example/CMakeLists.txt index 3ab28fb..ed8c728 100644 --- a/examples/realtime_example/CMakeLists.txt +++ b/examples/realtime_example/CMakeLists.txt @@ -3,8 +3,6 @@ cmake_minimum_required(VERSION 3.21) project(realtime_example) 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 @@ -14,6 +12,7 @@ include(FetchContent) FetchContent_Declare( cute GIT_REPOSITORY https://github.com/RandyGaul/cute_framework + GIT_TAG a2341c72f02e019e157cfc3997cd81d98c825004 ) FetchContent_MakeAvailable(cute) @@ -34,12 +33,11 @@ if(LINUX) set(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} -export-dynamic") endif() -add_custom_target(ALWAYS_DO_POST_BUILD - COMMAND ${CMAKE_COMMAND} -E copy -t $ $ - COMMAND ${CMAKE_COMMAND} -E copy_directory ${PROJECT_SOURCE_DIR}/dart $/dart +add_custom_command(TARGET realtime_example POST_BUILD + COMMAND ${CMAKE_COMMAND} -E copy -t $ $ + COMMAND ${CMAKE_COMMAND} -E copy_directory ${PROJECT_SOURCE_DIR}/dart/ $/dart COMMAND_EXPAND_LISTS ) -add_dependencies(realtime_example ALWAYS_DO_POST_BUILD) target_link_libraries(realtime_example PUBLIC dart_dll cute) diff --git a/examples/realtime_example/dart/main.dart b/examples/realtime_example/dart/main.dart index 7ec246c..6aeb051 100644 --- a/examples/realtime_example/dart/main.dart +++ b/examples/realtime_example/dart/main.dart @@ -20,9 +20,10 @@ class Wall { List walls = []; // Dot! +final int speed = 80; int dotEntity = 0; -int dotX = 0; -int dotY = 0; +double dotX = 0; +double dotY = 0; bool movingLeft = true; void main() { @@ -42,18 +43,20 @@ void main() { dotEntity = ffi.createEntity(0, 0, 10, 10); final drawable = ffi.getDrawable(dotEntity); + drawable.ref.color.r = 0.0; drawable.ref.color.g = 1.0; + drawable.ref.color.b = 0.0; } void frame(double dt) { if (movingLeft) { - dotX -= 3; + dotX -= (speed * dt); if (dotX < -200) { dotX = -200; movingLeft = false; } } else { - dotX += 3; + dotX += (speed * dt); if (dotX > 200) { dotX = 200; movingLeft = true; @@ -61,6 +64,6 @@ void frame(double dt) { } final dotDrawable = ffi.getDrawable(dotEntity); - dotDrawable.ref.x = dotX; - dotDrawable.ref.y = dotY; + dotDrawable.ref.x = dotX.floor(); + dotDrawable.ref.y = dotY.floor(); } diff --git a/examples/realtime_example/dart/pubspec.yaml b/examples/realtime_example/dart/pubspec.yaml index 44a39ab..f9e4f03 100644 --- a/examples/realtime_example/dart/pubspec.yaml +++ b/examples/realtime_example/dart/pubspec.yaml @@ -1,6 +1,6 @@ name: realtime_example environment: - sdk: ">=3.0.0 <=3.3.0" + sdk: ">=3.0.0 <4.0.0" dependencies: ffi: ^2.1.0 \ No newline at end of file diff --git a/examples/realtime_example/main.cpp b/examples/realtime_example/main.cpp index ca93829..56befff 100644 --- a/examples/realtime_example/main.cpp +++ b/examples/realtime_example/main.cpp @@ -1,6 +1,7 @@ #include using namespace Cute; +#include #include #include @@ -100,7 +101,7 @@ void render_drawables() { // These need to be exposed as "C" functions and be exported // #if defined(_WIN32) -#define WORM_EXPORT exten "C" __declspec(dllexport) +#define WORM_EXPORT extern "C" __declspec(dllexport) #else #define WORM_EXPORT extern "C" __attribute__((visibility("default"))) __attribute((used)) #endif @@ -137,10 +138,9 @@ WORM_EXPORT bool get_key_just_pressed(int key_code) { int main(int argc, char* argv[]) { // Create a window with a resolution of 640 x 480. - int options = - APP_OPTIONS_DEFAULT_GFX_CONTEXT | APP_OPTIONS_WINDOW_POS_CENTERED; + int options = APP_OPTIONS_WINDOW_POS_CENTERED; Result result = - make_app("Fancy Window Title", 0, 0, 640, 480, options, argv[0]); + make_app("Fancy Window Title", 0, 0, 0, 640, 480, options, argv[0]); if (is_error(result)) return -1; if (!init_dart()) return -1; diff --git a/examples/simple_example/CMakeLists.txt b/examples/simple_example/CMakeLists.txt index bcd7b36..00c0028 100644 --- a/examples/simple_example/CMakeLists.txt +++ b/examples/simple_example/CMakeLists.txt @@ -18,7 +18,7 @@ add_custom_command(TARGET simple_example POST_BUILD target_link_libraries(simple_example PUBLIC dart_dll) if (MSVC) - set_property(TARGET realtime_example PROPERTY VS_DEBUGGER_WORKING_DIRECTORY $) + set_property(TARGET simple_example PROPERTY VS_DEBUGGER_WORKING_DIRECTORY $) endif() set(EXECUTABLE_OUTPUT_PATH "${EXECUTABLE_OUTPUT_PATH}/simple_example") diff --git a/examples/simple_example_ffi/CMakeLists.txt b/examples/simple_example_ffi/CMakeLists.txt index f597690..9013093 100644 --- a/examples/simple_example_ffi/CMakeLists.txt +++ b/examples/simple_example_ffi/CMakeLists.txt @@ -16,8 +16,10 @@ add_custom_command(TARGET simple_example_ffi POST_BUILD COMMAND_EXPAND_LISTS ) +target_link_libraries(simple_example_ffi PUBLIC dart_dll) + if (MSVC) - set_property(TARGET realtime_example PROPERTY VS_DEBUGGER_WORKING_DIRECTORY $) + set_property(TARGET simple_example_ffi PROPERTY VS_DEBUGGER_WORKING_DIRECTORY $) endif() -target_link_libraries(simple_example_ffi PUBLIC dart_dll) \ No newline at end of file +set(EXECUTABLE_OUTPUT_PATH "${EXECUTABLE_OUTPUT_PATH}/simple_example_ffi") \ No newline at end of file diff --git a/examples/simple_example_ffi/pubspec.yaml b/examples/simple_example_ffi/pubspec.yaml index cab9123..49eae66 100644 --- a/examples/simple_example_ffi/pubspec.yaml +++ b/examples/simple_example_ffi/pubspec.yaml @@ -1,6 +1,6 @@ name: simple_example_ffi environment: - sdk: ">=3.0.0 <=3.3.0" + sdk: ">=3.0.0 <4.0.0" dependencies: ffi: ^2.1.0 \ No newline at end of file diff --git a/scripts/build_helpers/bin/build_dart.dart b/scripts/build_helpers/bin/build_dart.dart index 7e34742..c8e9cec 100644 --- a/scripts/build_helpers/bin/build_dart.dart +++ b/scripts/build_helpers/bin/build_dart.dart @@ -178,7 +178,7 @@ Future _buildDart(String buildType) async { final result = await inDir('dart-sdk/sdk', () async { logger.i("Building libdart"); var script = './tools/build.py'; - var args = ['--no-goma', '-m', buildType, 'libdart']; + var args = ['-m', buildType, 'libdart']; var command = script; if (Platform.isWindows) { command = 'python'; diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index f56d7a4..247004a 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -66,6 +66,8 @@ if(WIN32) Iphlpapi Psapi shlwapi + pathcch + ntdll ) set_property(TARGET dart_dll PROPERTY MSVC_RUNTIME_LIBRARY "MultiThreaded$<$:Debug>") diff --git a/src/isolate_setup.cpp b/src/isolate_setup.cpp index dc00911..bb501c1 100644 --- a/src/isolate_setup.cpp +++ b/src/isolate_setup.cpp @@ -9,6 +9,8 @@ #include #include #include +#include +#include using namespace dart::bin; @@ -158,11 +160,42 @@ Dart_Isolate CreateIsolate(bool is_main_isolate, void* callback_data, char** error) { Dart_Handle result; - uint8_t* kernel_buffer = nullptr; intptr_t kernel_buffer_size; + AppSnapshot* app_snapshot = nullptr; + std::shared_ptr kernel_buffer_ptr; + + bool isolate_run_app_snapshot = false; + const uint8_t* isolate_snapshot_data = kDartCoreIsolateSnapshotData; + const uint8_t* isolate_snapshot_instructions = + kDartCoreIsolateSnapshotInstructions; + + if (!is_main_isolate) { + app_snapshot = Snapshot::TryReadAppSnapshot(script_uri); + if (app_snapshot != nullptr && app_snapshot->IsJITorAOT()) { + if (app_snapshot->IsAOT()) { + *error = dart::Utils::SCreate( + "The uri(%s) provided to `Isolate.spawnUri()` is an " + "AOT snapshot and the JIT VM cannot spawn an isolate using it.", + script_uri); + delete app_snapshot; + return nullptr; + } + isolate_run_app_snapshot = true; + const uint8_t* ignore_vm_snapshot_data; + const uint8_t* ignore_vm_snapshot_instructions; + app_snapshot->SetBuffers( + &ignore_vm_snapshot_data, &ignore_vm_snapshot_instructions, + &isolate_snapshot_data, &isolate_snapshot_instructions); + } + } + + if (kernel_buffer == nullptr && !isolate_run_app_snapshot) { + dfe.ReadScript(script_uri, app_snapshot, &kernel_buffer, + &kernel_buffer_size, /*decode_uri=*/true, + &kernel_buffer_ptr); + } - dfe.ReadScript(script_uri, &kernel_buffer, &kernel_buffer_size); flags->null_safety = true; DllIsolateGroupData* isolate_group_data = new DllIsolateGroupData(