From 71f0b19476adb170c24d6a8de4ab3133701b1aeb Mon Sep 17 00:00:00 2001 From: Berke Güzel Date: Mon, 12 Oct 2026 20:39:36 +0300 Subject: Fix macOS builds on Apple Silicon and Intel --- tests/header_test.sh | 9 +++++++++ tests/meson.build | 2 ++ tests/symbols_test.sh | 11 +++++++++-- 3 files changed, 20 insertions(+), 2 deletions(-) (limited to 'tests') diff --git a/tests/header_test.sh b/tests/header_test.sh index 6636418..4ba091b 100644 --- a/tests/header_test.sh +++ b/tests/header_test.sh @@ -13,4 +13,13 @@ if command -v "$cxx" >/dev/null; then echo '#include "term.h"' | "$cxx" -std=c++17 -Wall -Wextra -Wpedantic -Werror \ -Iinclude/term -x c++ -fsyntax-only - || { echo "term.h: not valid C++" >&2; status=1; } fi + +# Apple headers define wide before a host includes the Unicode API. +unicode_header=$'typedef struct wide { int value; } wide;\n#include "unicode/width.h"' +echo "$unicode_header" | "$cc" -std=c11 -Wall -Wextra -Wpedantic -Werror \ + -Iinclude/term -x c -fsyntax-only - || { echo "unicode/width.h: conflicts with host types" >&2; status=1; } +if command -v "$cxx" >/dev/null; then + echo "$unicode_header" | "$cxx" -std=c++17 -Wall -Wextra -Wpedantic -Werror \ + -Iinclude/term -x c++ -fsyntax-only - || { echo "unicode/width.h: conflicts with C++ host types" >&2; status=1; } +fi exit $status diff --git a/tests/meson.build b/tests/meson.build index 8372574..0aa78e8 100644 --- a/tests/meson.build +++ b/tests/meson.build @@ -10,6 +10,7 @@ test_c_args = ['-UNDEBUG'] test_env = environment() test_env.set('LD_PRELOAD', '') test_env.set('DYLD_INSERT_LIBRARIES', '') +test_env.set('NM', find_program('nm', native: true).full_path()) # [name, sources, dependencies, suites] term_tests = [ @@ -97,6 +98,7 @@ test('term-symbols-test', bash, args: [files('symbols_test.sh'), term_headless_lib.get_static_lib(), meson.project_source_root() / 'include' / 'term', term_headless_lib.get_shared_lib()], + env: test_env, suite: 'unit', ) test('term-header-test', bash, diff --git a/tests/symbols_test.sh b/tests/symbols_test.sh index 4c7aee1..0343eb0 100644 --- a/tests/symbols_test.sh +++ b/tests/symbols_test.sh @@ -7,8 +7,15 @@ set -euo pipefail lib=$1 src=${2:-$(dirname "$0")/../include/term} +nm=${NM:-nm} -syms=$(nm -g --defined-only -P "$lib") +defined_args=(-g --defined-only -P) +exported_args=(-D --defined-only -P) +if [[ $(uname -s) == Darwin ]]; then + defined_args=(-g -U -P) + exported_args=(-g -U -P) +fi +syms=$("$nm" "${defined_args[@]}" "$lib") # ASan adds an __odr_asan. symbol for each global variable. defined=$(awk 'NF >= 2 && $2 ~ /^[A-Z]$/ && $2 != "U" { print $1 }' <<<"$syms" | grep -v '^_*odr_asan\.' | sed 's/^_//' | sort -u) @@ -49,7 +56,7 @@ fi # The shared library exports term.h and nothing else. shared=${3:-} if [[ -n $shared ]]; then - exported=$(nm -D --defined-only -P "$shared" | awk '$2 ~ /^[TDBRVW]$/ { print $1 }' | + exported=$("$nm" "${exported_args[@]}" "$shared" | awk '$2 ~ /^[TDBRVW]$/ { print $1 }' | sed 's/^_//' | sort -u) extra=$(comm -13 <(echo "$declared") <(echo "$exported")) absent=$(comm -23 <(echo "$declared") <(echo "$exported")) -- cgit v1.2.3