Skip to content

Commit

Permalink
πŸ‘©β€πŸ’» Add Mac build to workflow
Browse files Browse the repository at this point in the history
Package up libs and header files for better distribution.
  • Loading branch information
Jeff Ward authored and Jeff Ward committed Sep 25, 2023
1 parent 4e454e3 commit 4770d1f
Show file tree
Hide file tree
Showing 8 changed files with 84 additions and 11 deletions.
12 changes: 7 additions & 5 deletions .github/workflows/build.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -29,11 +31,11 @@ jobs:
- uses: threeal/[email protected]
- 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

3 changes: 2 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
@@ -1,2 +1,3 @@
dart-sdk/*
.build/*
.build/*
artifacts/*
2 changes: 1 addition & 1 deletion CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -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)
Expand Down
65 changes: 65 additions & 0 deletions scripts/build_helpers/bin/assemble_artifacts.dart
Original file line number Diff line number Diff line change
@@ -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));
}
}
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 @@ -15,6 +15,7 @@ void main(List<String> args) async {
if (argResults['verbose'] == true) {
logLevel = Level.debug;
}
BuildToolsLogger.initLogger(logLevel: logLevel);

if (!checkRightDirectory()) {
// Not run from root. Exit.
Expand All @@ -30,7 +31,6 @@ void main(List<String> args) async {
}
}

BuildToolsLogger.initLogger(logLevel: logLevel);
if (!await checkForDepotTools()) {
if (!await getDepotTools()) {
// Fatal. Can't do this without depot_tools
Expand Down
2 changes: 1 addition & 1 deletion scripts/build_helpers/pubspec.lock
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,7 @@ packages:
source: hosted
version: "3.2.0"
glob:
dependency: transitive
dependency: "direct main"
description:
name: glob
sha256: "0e7014b3b7d4dac1ca4d6114f82bf1782ee86745b9b42a92c9289c23d8a0ab63"
Expand Down
1 change: 1 addition & 0 deletions scripts/build_helpers/pubspec.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
8 changes: 6 additions & 2 deletions src/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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)
Expand Down

0 comments on commit 4770d1f

Please sign in to comment.