Fixes for running on MacOS (#32)
* Fixed null completeness warning by clang by adding `-Wno-nullability-completeness` to compiler-opts in examples and wrapper build.
* Fixed relative path not allowed in hardened programs error by using absolute path for loading dynamic library if available.
diff --git a/example/libclang-example/pubspec.yaml b/example/libclang-example/pubspec.yaml
index 22acef7..f6acbeb 100644
--- a/example/libclang-example/pubspec.yaml
+++ b/example/libclang-example/pubspec.yaml
@@ -27,7 +27,7 @@
- 'CXString.h'
- 'Index.h'
- compiler-opts: '-I/usr/lib/llvm-9/include/ -I/usr/lib/llvm-10/include/ -IC:\Progra~1\LLVM\include -I/usr/local/opt/llvm/include/ -I/Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX.sdk/usr/include/'
+ compiler-opts: '-I/usr/lib/llvm-9/include/ -I/usr/lib/llvm-10/include/ -IC:\Progra~1\LLVM\include -I/usr/local/opt/llvm/include/ -I/Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX.sdk/usr/include/ -Wno-nullability-completeness'
functions:
include:
matches:
diff --git a/lib/src/header_parser/clang_bindings/clang_bindings.dart b/lib/src/header_parser/clang_bindings/clang_bindings.dart
index 2e6469c..809109f 100644
--- a/lib/src/header_parser/clang_bindings/clang_bindings.dart
+++ b/lib/src/header_parser/clang_bindings/clang_bindings.dart
@@ -8,7 +8,7 @@
/// Holds the Dynamic library.
final ffi.DynamicLibrary _dylib;
- /// The symbols are looked up in [dynamicLIbrary].
+ /// The symbols are looked up in [dynamicLibrary].
Clang(ffi.DynamicLibrary dynamicLibrary) : _dylib = dynamicLibrary;
/// Provides a shared context for creating translation units.
diff --git a/lib/src/header_parser/parser.dart b/lib/src/header_parser/parser.dart
index c35dd3c..48944df 100644
--- a/lib/src/header_parser/parser.dart
+++ b/lib/src/header_parser/parser.dart
@@ -3,6 +3,7 @@
// BSD-style license that can be found in the LICENSE file.
import 'dart:ffi';
+import 'dart:io';
import 'package:ffi/ffi.dart';
import 'package:ffigen/src/code_generator.dart';
@@ -43,7 +44,9 @@
void initParser(Config c) {
config = c;
- clang = clang_types.Clang(DynamicLibrary.open(config.libclang_dylib_path));
+ clang = clang_types.Clang(DynamicLibrary.open(
+ File(config.libclang_dylib_path).absolute?.path ??
+ config.libclang_dylib_path));
}
/// Parses source files and adds generated bindings to [bindings].
diff --git a/test/native_test/build_test_dylib.dart b/test/native_test/build_test_dylib.dart
index 2fd2c49..a41f874 100644
--- a/test/native_test/build_test_dylib.dart
+++ b/test/native_test/build_test_dylib.dart
@@ -30,24 +30,24 @@
import 'package:meta/meta.dart';
-const MACOS = 'macos';
-const WINDOWS = 'windows';
-const LINUX = 'linux';
+const macOS = 'macos';
+const windows = 'windows';
+const linux = 'linux';
Map<String, Options> platformOptions = {
- LINUX: Options(
+ linux: Options(
outputfilename: 'native_test.so',
sharedFlag: '-shared',
inputHeader: 'native_test.c',
fPIC: '-fpic',
),
- WINDOWS: Options(
+ windows: Options(
outputfilename: 'native_test.dll',
sharedFlag: '-shared',
inputHeader: 'native_test.c',
moduleDefPath: '-Wl,/DEF:native_test.def',
),
- MACOS: Options(
+ macOS: Options(
outputfilename: 'native_test.dylib',
sharedFlag: '-shared',
inputHeader: 'native_test.c',
@@ -75,6 +75,7 @@
'-o',
options.outputfilename,
options.moduleDefPath,
+ '-Wno-nullability-completeness',
],
);
return result;
@@ -93,11 +94,11 @@
/// Get options based on current platform.
Options getPlatformOptions() {
if (Platform.isMacOS) {
- return platformOptions[MACOS];
+ return platformOptions[macOS];
} else if (Platform.isWindows) {
- return platformOptions[WINDOWS];
+ return platformOptions[windows];
} else if (Platform.isLinux) {
- return platformOptions[LINUX];
+ return platformOptions[linux];
} else {
throw Exception('Unknown Platform.');
}
diff --git a/test/native_test/native_test.dart b/test/native_test/native_test.dart
index cc4fa22..11e18a8 100644
--- a/test/native_test/native_test.dart
+++ b/test/native_test/native_test.dart
@@ -18,7 +18,8 @@
} else if (Platform.isWindows) {
dylibName = r'test\native_test\native_test.dll';
}
- bindings.init(DynamicLibrary.open(dylibName));
+ bindings.init(
+ DynamicLibrary.open(File(dylibName).absolute?.path ?? dylibName));
});
test('uint8_t', () {
expect(bindings.Function1Uint8(pow(2, 8).toInt()), 42);
diff --git a/tool/libclang_config.yaml b/tool/libclang_config.yaml
index c9f5876..fe10d98 100644
--- a/tool/libclang_config.yaml
+++ b/tool/libclang_config.yaml
@@ -14,7 +14,7 @@
output: '../lib/src/header_parser/clang_bindings/clang_bindings.dart'
libclang-dylib-folder: 'wrapped_libclang'
sort: true
-compiler-opts: '-I/usr/lib/llvm-9/include/ -I/usr/lib/llvm-10/include/ -I/usr/local/opt/llvm/include/ -I/Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX.sdk/usr/include/'
+compiler-opts: '-I/usr/lib/llvm-9/include/ -I/usr/lib/llvm-10/include/ -I/usr/local/opt/llvm/include/ -I/Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX.sdk/usr/include/ -Wno-nullability-completeness'
headers:
- 'wrapped_libclang/wrapper.c'
header-filter:
diff --git a/tool/wrapped_libclang/build.dart b/tool/wrapped_libclang/build.dart
index 20971b1..3e1eff4 100644
--- a/tool/wrapped_libclang/build.dart
+++ b/tool/wrapped_libclang/build.dart
@@ -30,13 +30,13 @@
import 'package:args/args.dart';
import 'package:meta/meta.dart';
-const MACOS = 'macos';
-const WINDOWS = 'windows';
-const LINUX = 'linux';
+const macOS = 'macos';
+const windows = 'windows';
+const linux = 'linux';
/// Default platform options.
Map<String, Options> platformOptions = {
- LINUX: Options(
+ linux: Options(
outputfilename: 'libwrapped_clang.so',
sharedFlag: '-shared',
inputHeader: 'wrapper.c',
@@ -47,7 +47,7 @@
'-I/usr/lib/llvm-10/include/',
],
),
- WINDOWS: Options(
+ windows: Options(
outputfilename: 'wrapped_clang.dll',
sharedFlag: '-shared',
inputHeader: 'wrapper.c',
@@ -60,7 +60,7 @@
r'-LC:\Progra~1\LLVM\lib',
],
),
- MACOS: Options(
+ macOS: Options(
outputfilename: 'libwrapped_clang.dylib',
sharedFlag: '-shared',
inputHeader: 'wrapper.c',
@@ -102,6 +102,7 @@
'-o',
options.outputfilename,
options.moduleDefPath,
+ '-Wno-nullability-completeness',
],
);
return result;
@@ -167,11 +168,11 @@
/// Get options based on current platform.
Options getPlatformOptions() {
if (Platform.isMacOS) {
- return platformOptions[MACOS];
+ return platformOptions[macOS];
} else if (Platform.isWindows) {
- return platformOptions[WINDOWS];
+ return platformOptions[windows];
} else if (Platform.isLinux) {
- return platformOptions[LINUX];
+ return platformOptions[linux];
} else {
throw Exception('Unknown Platform.');
}