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 --- include/term/unicode/unicode_data.inc | 2 +- include/term/unicode/width.h | 2 +- tests/header_test.sh | 9 +++++++++ tests/meson.build | 2 ++ tests/symbols_test.sh | 11 +++++++++-- tools/generate_unicode.py | 2 +- 6 files changed, 23 insertions(+), 5 deletions(-) diff --git a/include/term/unicode/unicode_data.inc b/include/term/unicode/unicode_data.inc index 8c3d394..8053b01 100644 --- a/include/term/unicode/unicode_data.inc +++ b/include/term/unicode/unicode_data.inc @@ -105,7 +105,7 @@ static const struct unicode_range nonprintable[] = { {0x0,0x1F},{0x7F,0x9F},{0xD800,0xDFFF}, }; -static const struct unicode_range wide[] = { +static const struct unicode_range unicode_wide[] = { {0x1100,0x115F},{0x231A,0x231B},{0x2329,0x232A},{0x23E9,0x23EC}, {0x23F0,0x23F0},{0x23F3,0x23F3},{0x25FD,0x25FE},{0x2614,0x2615}, {0x2630,0x2637},{0x2648,0x2653},{0x267F,0x267F},{0x268A,0x268F}, diff --git a/include/term/unicode/width.h b/include/term/unicode/width.h index fc639c8..388ae6c 100644 --- a/include/term/unicode/width.h +++ b/include/term/unicode/width.h @@ -32,7 +32,7 @@ static inline int unicode_width(uint32_t cp) return -1; if (IN_TABLE(zero_width, cp)) return 0; - return IN_TABLE(wide, cp) ? 2 : 1; + return IN_TABLE(unicode_wide, cp) ? 2 : 1; } static inline bool unicode_extended_pictographic(uint32_t cp) 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")) diff --git a/tools/generate_unicode.py b/tools/generate_unicode.py index cf72b87..85c646d 100644 --- a/tools/generate_unicode.py +++ b/tools/generate_unicode.py @@ -107,7 +107,7 @@ def main(): f'#define UNICODE_DATA_VERSION "{version}"', ""] emit_table(out, "zero_width", zero) emit_table(out, "nonprintable", nonprint) - emit_table(out, "wide", wide) + emit_table(out, "unicode_wide", wide) emit_table(out, "spacing_mark", spacing) emit_table(out, "extended_pictographic", pictographic) emit_table(out, "emoji_presentation", emoji_presentation) -- cgit v1.2.3