From 695c0656dc649e6858ec0a6e09c6102c4b005b7e Mon Sep 17 00:00:00 2001 From: Daco Harkes Date: Wed, 10 Apr 2024 08:42:44 +0200 Subject: [PATCH] [ffigen] Add compiler option `-Wno-nullability-completeness` by default (#1074) --- pkgs/ffigen/CHANGELOG.md | 1 + pkgs/ffigen/example/libclang-example/config.yaml | 1 - pkgs/ffigen/lib/src/config_provider/config_types.dart | 10 +++++----- pkgs/ffigen/test/config_tests/compiler_opts_test.dart | 9 ++++++++- pkgs/ffigen/test/native_test/config.yaml | 1 - pkgs/ffigen/tool/libclang_config.yaml | 1 - 6 files changed, 14 insertions(+), 9 deletions(-) diff --git a/pkgs/ffigen/CHANGELOG.md b/pkgs/ffigen/CHANGELOG.md index 2058fce29..400332646 100644 --- a/pkgs/ffigen/CHANGELOG.md +++ b/pkgs/ffigen/CHANGELOG.md @@ -5,6 +5,7 @@ `ffi-native` option. - Add `retainAndReturnPointer` method to ObjC objects and blocks, and add `castFromPointer` method to blocks. +- Add `-Wno-nullability-completeness` as default compiler option for MacOS. ## 11.0.0 diff --git a/pkgs/ffigen/example/libclang-example/config.yaml b/pkgs/ffigen/example/libclang-example/config.yaml index 6b3db356d..7e56f14c5 100644 --- a/pkgs/ffigen/example/libclang-example/config.yaml +++ b/pkgs/ffigen/example/libclang-example/config.yaml @@ -22,7 +22,6 @@ headers: compiler-opts: - '-I../../third_party/libclang/include' - '-I/Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX.sdk/usr/include/' - - '-Wno-nullability-completeness' functions: include: - 'clang_.*' # Can be a regexp, '.' matches any character. diff --git a/pkgs/ffigen/lib/src/config_provider/config_types.dart b/pkgs/ffigen/lib/src/config_provider/config_types.dart index ce6805122..7bec4928e 100644 --- a/pkgs/ffigen/lib/src/config_provider/config_types.dart +++ b/pkgs/ffigen/lib/src/config_provider/config_types.dart @@ -347,11 +347,11 @@ class CompilerOptsAuto { /// Extracts compiler options based on OS and config. List extractCompilerOpts() { - if (Platform.isMacOS && macIncludeStdLib) { - return getCStandardLibraryHeadersForMac(); - } - - return []; + return [ + if (Platform.isMacOS && macIncludeStdLib) + ...getCStandardLibraryHeadersForMac(), + if (Platform.isMacOS) '-Wno-nullability-completeness', + ]; } } diff --git a/pkgs/ffigen/test/config_tests/compiler_opts_test.dart b/pkgs/ffigen/test/config_tests/compiler_opts_test.dart index 0b711acd6..422232d84 100644 --- a/pkgs/ffigen/test/config_tests/compiler_opts_test.dart +++ b/pkgs/ffigen/test/config_tests/compiler_opts_test.dart @@ -2,6 +2,8 @@ // for details. All rights reserved. Use of this source code is governed by a // BSD-style license that can be found in the LICENSE file. +import 'dart:io'; + import 'package:ffigen/ffigen.dart'; import 'package:ffigen/src/config_provider/spec_utils.dart'; import 'package:ffigen/src/strings.dart' as strings; @@ -40,7 +42,12 @@ ${strings.compilerOptsAuto}: ${strings.macos}: ${strings.includeCStdLib}: false '''); - expect(config.compilerOpts.isEmpty, true); + expect( + config.compilerOpts, + equals([ + if (Platform.isMacOS) '-Wno-nullability-completeness', + ]), + ); }); }); } diff --git a/pkgs/ffigen/test/native_test/config.yaml b/pkgs/ffigen/test/native_test/config.yaml index 3942f6f26..5066f4094 100644 --- a/pkgs/ffigen/test/native_test/config.yaml +++ b/pkgs/ffigen/test/native_test/config.yaml @@ -15,7 +15,6 @@ headers: include-directives: - '**native_test.c' -compiler-opts: '-Wno-nullability-completeness' preamble: | // ignore_for_file: camel_case_types, non_constant_identifier_names diff --git a/pkgs/ffigen/tool/libclang_config.yaml b/pkgs/ffigen/tool/libclang_config.yaml index 7343442a5..46e373334 100644 --- a/pkgs/ffigen/tool/libclang_config.yaml +++ b/pkgs/ffigen/tool/libclang_config.yaml @@ -16,7 +16,6 @@ description: Holds bindings to LibClang. output: '../lib/src/header_parser/clang_bindings/clang_bindings.dart' compiler-opts: - '-Ithird_party/libclang/include' - - '-Wno-nullability-completeness' headers: entry-points: - '../third_party/libclang/include/clang-c/Index.h'