Skip to content

Commit 4770d1f

Browse files
Jeff WardJeff Ward
authored andcommitted
πŸ‘©β€πŸ’» Add Mac build to workflow
Package up libs and header files for better distribution.
1 parent 4e454e3 commit 4770d1f

File tree

8 files changed

+84
-11
lines changed

8 files changed

+84
-11
lines changed

β€Ž.github/workflows/build.yaml

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -8,12 +8,14 @@ jobs:
88
build:
99
strategy:
1010
matrix:
11-
os: [windows-latest, ubuntu-latest]
11+
os: [windows-latest, ubuntu-latest, macos-latest]
1212
include:
1313
- os: windows-latest
1414
postfix: win
1515
- os: ubuntu-latest
1616
postfix: linux
17+
- os: macos-latest
18+
postfix: macos-x64
1719
env:
1820
DEPOT_TOOLS_WIN_TOOLCHAIN: 0
1921
continue-on-error: true
@@ -29,11 +31,11 @@ jobs:
2931
- uses: threeal/[email protected]
3032
- name: Build Shared Library
3133
run: cmake --build build --config release
34+
- name: Assemble artifacts
35+
run: dart ./scripts/build_helpers/bin/assemble_artifacts.dart
3236
- name: 'Upload Artifact'
3337
uses: actions/upload-artifact@v3
3438
with:
35-
name: libs-${{ matrix.postfix }}
36-
path: |
37-
./build/src/Release/
38-
./build/src/*.so
39+
name: lib-${{ matrix.postfix }}
40+
path: ./artifacts
3941

β€Ž.gitignore

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,3 @@
11
dart-sdk/*
2-
.build/*
2+
.build/*
3+
artifacts/*

β€ŽCMakeLists.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
cmake_minimum_required(VERSION 3.21)
22

3-
project(Tutorial VERSION 0.1)
3+
project(DartSharedLibrary VERSION 0.1)
44

55
set(CMAKE_CXX_STANDARD 11)
66
set(CMAKE_CXX_STANDARD_REQUIRED True)
Lines changed: 65 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,65 @@
1+
// Script to assemble artifacts into a single place
2+
import 'dart:io';
3+
4+
import 'package:build_helpers/build_helpers.dart';
5+
import 'package:glob/glob.dart';
6+
import 'package:glob/list_local_fs.dart';
7+
import 'package:logger/logger.dart';
8+
import 'package:path/path.dart' as path;
9+
10+
void main() {
11+
if (!checkRightDirectory()) {
12+
// Not run from root. Exit.
13+
exit(-1);
14+
}
15+
// Always verbose
16+
BuildToolsLogger.initLogger(logLevel: Level.debug);
17+
18+
final dest = Directory('artifacts');
19+
dest.createSync();
20+
_copyIncludeFiles(dest);
21+
_copyLibs(dest);
22+
}
23+
24+
void _copyIncludeFiles(Directory dest) {
25+
final logger = BuildToolsLogger.shared;
26+
27+
final includePath = Directory('dart-sdk/sdk/runtime/include');
28+
if (!includePath.existsSync()) {
29+
logger.f("Couldn't find Dart SDK include dir.");
30+
exit(-1);
31+
}
32+
33+
const dartIncludeFiles = ['dart_api.h', 'dart_tools_api.h'];
34+
Directory(path.join(dest.path, 'include')).createSync(recursive: true);
35+
for (var dartIncludeFile in dartIncludeFiles) {
36+
final file = File(path.join(includePath.path, dartIncludeFile));
37+
file.copySync(path.join(dest.path, 'include', dartIncludeFile));
38+
}
39+
40+
final dartDllHeader = File('src/dart_dll.h');
41+
dartDllHeader.copySync(path.join(dest.path, 'include', 'dart_dll.h'));
42+
}
43+
44+
void _copyLibs(Directory dest) {
45+
final logger = BuildToolsLogger.shared;
46+
47+
final builtLibPath = Directory('build/src');
48+
if (!builtLibPath.existsSync()) {
49+
logger.f('Could not find built artifact path');
50+
}
51+
52+
final binDestPath = Directory(path.join(dest.path, 'bin'));
53+
binDestPath.createSync(recursive: true);
54+
55+
var copyGlob = Glob('*.so');
56+
if (Platform.isWindows) {
57+
copyGlob = Glob(path.join('Release', '*.*'));
58+
} else if (Platform.isMacOS) {
59+
copyGlob = Glob('*.dylib');
60+
}
61+
final files = copyGlob.listSync(root: builtLibPath.path);
62+
for (var file in files) {
63+
(file as File).copySync(path.join(binDestPath.path, file.basename));
64+
}
65+
}

β€Žscripts/build_helpers/bin/build_dart.dart

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ void main(List<String> args) async {
1515
if (argResults['verbose'] == true) {
1616
logLevel = Level.debug;
1717
}
18+
BuildToolsLogger.initLogger(logLevel: logLevel);
1819

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

33-
BuildToolsLogger.initLogger(logLevel: logLevel);
3434
if (!await checkForDepotTools()) {
3535
if (!await getDepotTools()) {
3636
// Fatal. Can't do this without depot_tools

β€Žscripts/build_helpers/pubspec.lock

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -90,7 +90,7 @@ packages:
9090
source: hosted
9191
version: "3.2.0"
9292
glob:
93-
dependency: transitive
93+
dependency: "direct main"
9494
description:
9595
name: glob
9696
sha256: "0e7014b3b7d4dac1ca4d6114f82bf1782ee86745b9b42a92c9289c23d8a0ab63"

β€Žscripts/build_helpers/pubspec.yaml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ dependencies:
1111
args: ^2.4.2
1212
path: ^1.8.0
1313
logger: ^2.0.2
14+
glob: ^2.1.2
1415

1516
dev_dependencies:
1617
lints: ^2.0.0

β€Žsrc/CMakeLists.txt

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24,12 +24,12 @@ endif()
2424

2525
find_library(LIB_DART_DEBUG
2626
NAMES "${LIB_PREFIX}dart"
27-
HINTS "${DART_DIR}/out/DebugX64/obj/runtime/bin"
27+
HINTS "${DART_DIR}/out/DebugX64/obj/runtime/bin" "${DART_DIR}/xcodebuild/ReleaseX64/obj/runtime/bin"
2828
)
2929

3030
find_library(LIB_DART_RELEASE
3131
NAMES "${LIB_PREFIX}dart"
32-
HINTS "${DART_DIR}/out/ReleaseX64/obj/runtime/bin"
32+
HINTS "${DART_DIR}/out/ReleaseX64/obj/runtime/bin" "${DART_DIR}/xcodebuild/ReleaseX64/obj/runtime/bin"
3333
)
3434

3535
target_compile_definitions(dart_dll PRIVATE
@@ -77,6 +77,10 @@ elseif(LINUX)
7777
Threads::Threads
7878
${CMAKE_DL_LIBS}
7979
)
80+
elseif(APPLE)
81+
set(CMAKE_C_COMPILER "${DART_DIR}/buildtools/mac-x64/clang/bin/clang")
82+
set(CMAKE_CXX_COMPILER "${DART_DIR}/buildtools/mac-x64/clang/bin/clang++")
83+
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")
8084
endif()
8185

8286
if(LIB_DART_DEBUG)

0 commit comments

Comments
Β (0)