diff --git a/.github/workflows/build.yaml b/.github/workflows/build.yaml index ce8dc10..67efe9e 100644 --- a/.github/workflows/build.yaml +++ b/.github/workflows/build.yaml @@ -8,12 +8,14 @@ jobs: build: strategy: matrix: - os: [windows-latest, ubuntu-latest] + os: [windows-latest, ubuntu-latest, macos-latest] include: - os: windows-latest postfix: win - os: ubuntu-latest postfix: linux + - os: macos-latest + postfix: macos-x64 env: DEPOT_TOOLS_WIN_TOOLCHAIN: 0 continue-on-error: true @@ -29,11 +31,11 @@ jobs: - uses: threeal/cmake-action@v1.3.0 - name: Build Shared Library run: cmake --build build --config release + - name: Assemble artifacts + run: dart ./scripts/build_helpers/bin/assemble_artifacts.dart - name: 'Upload Artifact' uses: actions/upload-artifact@v3 with: - name: libs-${{ matrix.postfix }} - path: | - ./build/src/Release/ - ./build/src/*.so + name: lib-${{ matrix.postfix }} + path: ./artifacts \ No newline at end of file diff --git a/.gitignore b/.gitignore index 07c6d15..aebcdfc 100644 --- a/.gitignore +++ b/.gitignore @@ -1,2 +1,3 @@ dart-sdk/* -.build/* \ No newline at end of file +.build/* +artifacts/* \ No newline at end of file diff --git a/CMakeLists.txt b/CMakeLists.txt index efaa31b..8ed60a7 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -1,6 +1,6 @@ cmake_minimum_required(VERSION 3.21) -project(Tutorial VERSION 0.1) +project(DartSharedLibrary VERSION 0.1) set(CMAKE_CXX_STANDARD 11) set(CMAKE_CXX_STANDARD_REQUIRED True) diff --git a/scripts/build_helpers/bin/assemble_artifacts.dart b/scripts/build_helpers/bin/assemble_artifacts.dart new file mode 100644 index 0000000..8becb27 --- /dev/null +++ b/scripts/build_helpers/bin/assemble_artifacts.dart @@ -0,0 +1,65 @@ +// Script to assemble artifacts into a single place +import 'dart:io'; + +import 'package:build_helpers/build_helpers.dart'; +import 'package:glob/glob.dart'; +import 'package:glob/list_local_fs.dart'; +import 'package:logger/logger.dart'; +import 'package:path/path.dart' as path; + +void main() { + if (!checkRightDirectory()) { + // Not run from root. Exit. + exit(-1); + } + // Always verbose + BuildToolsLogger.initLogger(logLevel: Level.debug); + + final dest = Directory('artifacts'); + dest.createSync(); + _copyIncludeFiles(dest); + _copyLibs(dest); +} + +void _copyIncludeFiles(Directory dest) { + final logger = BuildToolsLogger.shared; + + final includePath = Directory('dart-sdk/sdk/runtime/include'); + if (!includePath.existsSync()) { + logger.f("Couldn't find Dart SDK include dir."); + exit(-1); + } + + const dartIncludeFiles = ['dart_api.h', 'dart_tools_api.h']; + Directory(path.join(dest.path, 'include')).createSync(recursive: true); + for (var dartIncludeFile in dartIncludeFiles) { + final file = File(path.join(includePath.path, dartIncludeFile)); + file.copySync(path.join(dest.path, 'include', dartIncludeFile)); + } + + final dartDllHeader = File('src/dart_dll.h'); + dartDllHeader.copySync(path.join(dest.path, 'include', 'dart_dll.h')); +} + +void _copyLibs(Directory dest) { + final logger = BuildToolsLogger.shared; + + final builtLibPath = Directory('build/src'); + if (!builtLibPath.existsSync()) { + logger.f('Could not find built artifact path'); + } + + final binDestPath = Directory(path.join(dest.path, 'bin')); + binDestPath.createSync(recursive: true); + + var copyGlob = Glob('*.so'); + if (Platform.isWindows) { + copyGlob = Glob(path.join('Release', '*.*')); + } else if (Platform.isMacOS) { + copyGlob = Glob('*.dylib'); + } + final files = copyGlob.listSync(root: builtLibPath.path); + for (var file in files) { + (file as File).copySync(path.join(binDestPath.path, file.basename)); + } +} \ 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 f3d7c9b..10ec6d4 100644 --- a/scripts/build_helpers/bin/build_dart.dart +++ b/scripts/build_helpers/bin/build_dart.dart @@ -15,6 +15,7 @@ void main(List args) async { if (argResults['verbose'] == true) { logLevel = Level.debug; } + BuildToolsLogger.initLogger(logLevel: logLevel); if (!checkRightDirectory()) { // Not run from root. Exit. @@ -30,7 +31,6 @@ void main(List args) async { } } - BuildToolsLogger.initLogger(logLevel: logLevel); if (!await checkForDepotTools()) { if (!await getDepotTools()) { // Fatal. Can't do this without depot_tools diff --git a/scripts/build_helpers/pubspec.lock b/scripts/build_helpers/pubspec.lock index ab1926b..6257b6b 100644 --- a/scripts/build_helpers/pubspec.lock +++ b/scripts/build_helpers/pubspec.lock @@ -90,7 +90,7 @@ packages: source: hosted version: "3.2.0" glob: - dependency: transitive + dependency: "direct main" description: name: glob sha256: "0e7014b3b7d4dac1ca4d6114f82bf1782ee86745b9b42a92c9289c23d8a0ab63" diff --git a/scripts/build_helpers/pubspec.yaml b/scripts/build_helpers/pubspec.yaml index e774fb6..dcde792 100644 --- a/scripts/build_helpers/pubspec.yaml +++ b/scripts/build_helpers/pubspec.yaml @@ -11,6 +11,7 @@ dependencies: args: ^2.4.2 path: ^1.8.0 logger: ^2.0.2 + glob: ^2.1.2 dev_dependencies: lints: ^2.0.0 diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index bc3cc7f..393cc7e 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -24,12 +24,12 @@ endif() find_library(LIB_DART_DEBUG NAMES "${LIB_PREFIX}dart" - HINTS "${DART_DIR}/out/DebugX64/obj/runtime/bin" + HINTS "${DART_DIR}/out/DebugX64/obj/runtime/bin" "${DART_DIR}/xcodebuild/ReleaseX64/obj/runtime/bin" ) find_library(LIB_DART_RELEASE NAMES "${LIB_PREFIX}dart" - HINTS "${DART_DIR}/out/ReleaseX64/obj/runtime/bin" + HINTS "${DART_DIR}/out/ReleaseX64/obj/runtime/bin" "${DART_DIR}/xcodebuild/ReleaseX64/obj/runtime/bin" ) target_compile_definitions(dart_dll PRIVATE @@ -77,6 +77,10 @@ elseif(LINUX) Threads::Threads ${CMAKE_DL_LIBS} ) +elseif(APPLE) + set(CMAKE_C_COMPILER "${DART_DIR}/buildtools/mac-x64/clang/bin/clang") + set(CMAKE_CXX_COMPILER "${DART_DIR}/buildtools/mac-x64/clang/bin/clang++") + set(CMAKE_SHARED_LINKER_FLAGS "${CMAKE_SHARED_LINKER_FLAGS} -nostdlib++ ${DART_DIR}/buildtools/mac-x64/clang/lib/libc++.a -framework Cocoa -framework QuartzCore -framework Security") endif() if(LIB_DART_DEBUG)