Skip to content

Commit

Permalink
feat: Update to Dart 3.5, fix build
Browse files Browse the repository at this point in the history
Updated to Dart 3.5, fixed a lot of build mistakes in various CMakeLists.
  • Loading branch information
fuzzybinary committed Aug 10, 2024
1 parent ccef86b commit b24bdd9
Show file tree
Hide file tree
Showing 12 changed files with 64 additions and 26 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.3.0
3.5.0
2 changes: 1 addition & 1 deletion CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
10 changes: 4 additions & 6 deletions examples/realtime_example/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -14,6 +12,7 @@ include(FetchContent)
FetchContent_Declare(
cute
GIT_REPOSITORY https://github.com/RandyGaul/cute_framework
GIT_TAG a2341c72f02e019e157cfc3997cd81d98c825004
)
FetchContent_MakeAvailable(cute)

Expand All @@ -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 $<TARGET_FILE_DIR:realtime_example> $<TARGET_RUNTIME_DLLS:simple_example_ffi>
COMMAND ${CMAKE_COMMAND} -E copy_directory ${PROJECT_SOURCE_DIR}/dart $<TARGET_FILE_DIR:realtime_example>/dart
add_custom_command(TARGET realtime_example POST_BUILD
COMMAND ${CMAKE_COMMAND} -E copy -t $<TARGET_FILE_DIR:realtime_example> $<TARGET_RUNTIME_DLLS:realtime_example>
COMMAND ${CMAKE_COMMAND} -E copy_directory ${PROJECT_SOURCE_DIR}/dart/ $<TARGET_FILE_DIR:realtime_example>/dart
COMMAND_EXPAND_LISTS
)
add_dependencies(realtime_example ALWAYS_DO_POST_BUILD)

target_link_libraries(realtime_example PUBLIC dart_dll cute)

Expand Down
15 changes: 9 additions & 6 deletions examples/realtime_example/dart/main.dart
Original file line number Diff line number Diff line change
Expand Up @@ -20,9 +20,10 @@ class Wall {
List<Wall> 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() {
Expand All @@ -42,25 +43,27 @@ 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;
}
}

final dotDrawable = ffi.getDrawable(dotEntity);
dotDrawable.ref.x = dotX;
dotDrawable.ref.y = dotY;
dotDrawable.ref.x = dotX.floor();
dotDrawable.ref.y = dotY.floor();
}
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: realtime_example
environment:
sdk: ">=3.0.0 <=3.3.0"
sdk: ">=3.0.0 <4.0.0"

dependencies:
ffi: ^2.1.0
8 changes: 4 additions & 4 deletions examples/realtime_example/main.cpp
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
#include <cute.h>
using namespace Cute;

#include <iostream>
#include <dart_dll.h>

#include <dart_tools_api.h>
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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;
Expand Down
2 changes: 1 addition & 1 deletion examples/simple_example/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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 $<TARGET_FILE_DIR:simple_example>)
set_property(TARGET simple_example PROPERTY VS_DEBUGGER_WORKING_DIRECTORY $<TARGET_FILE_DIR:simple_example>)
endif()

set(EXECUTABLE_OUTPUT_PATH "${EXECUTABLE_OUTPUT_PATH}/simple_example")
6 changes: 4 additions & 2 deletions examples/simple_example_ffi/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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 $<TARGET_FILE_DIR:simple_example_ffi>)
set_property(TARGET simple_example_ffi PROPERTY VS_DEBUGGER_WORKING_DIRECTORY $<TARGET_FILE_DIR:simple_example_ffi>)
endif()

target_link_libraries(simple_example_ffi PUBLIC dart_dll)
set(EXECUTABLE_OUTPUT_PATH "${EXECUTABLE_OUTPUT_PATH}/simple_example_ffi")
2 changes: 1 addition & 1 deletion 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: ">=3.0.0 <=3.3.0"
sdk: ">=3.0.0 <4.0.0"

dependencies:
ffi: ^2.1.0
2 changes: 1 addition & 1 deletion scripts/build_helpers/bin/build_dart.dart
Original file line number Diff line number Diff line change
Expand Up @@ -178,7 +178,7 @@ Future<bool> _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';
Expand Down
2 changes: 2 additions & 0 deletions src/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,8 @@ if(WIN32)
Iphlpapi
Psapi
shlwapi
pathcch
ntdll
)
set_property(TARGET dart_dll PROPERTY
MSVC_RUNTIME_LIBRARY "MultiThreaded$<$<CONFIG:Debug>:Debug>")
Expand Down
37 changes: 35 additions & 2 deletions src/isolate_setup.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@
#include <bin/dfe.h>
#include <bin/isolate_data.h>
#include <bin/loader.h>
#include <bin/snapshot_utils.h>
#include <platform/utils.h>

using namespace dart::bin;

Expand Down Expand Up @@ -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<uint8_t> 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(
Expand Down

0 comments on commit b24bdd9

Please sign in to comment.