Skip to content

build: fix cross-platform build support and add macOS CI#225

Open
m-mcgowan wants to merge 5 commits intoblues:masterfrom
m-mcgowan:build/macos-test-support
Open

build: fix cross-platform build support and add macOS CI#225
m-mcgowan wants to merge 5 commits intoblues:masterfrom
m-mcgowan:build/macos-test-support

Conversation

@m-mcgowan
Copy link
Contributor

@m-mcgowan m-mcgowan commented Feb 23, 2026

Summary

  • Use check_symbol_exists to detect system-provided strlcpy/strlcat (macOS, FreeBSD, OpenBSD, glibc 2.38+) instead of bundling them unconditionally
  • Guard Linux x86 32-bit cross-compile flags (-m32, -mfpmath=sse, linker paths) by CMAKE_SYSTEM_PROCESSOR so builds work on any POSIX platform
  • Fix AppleClang warnings-as-errors at source (NoteUserAgent strict prototype, unused variables in n_helpers.c)
  • Add a macOS build verification job to the CI pipeline
  • Add strlcpy/strlcat to the libc dependency whitelist and make the lcov n_str.c exclude conditional

Changes

CMakeLists.txt:

  • check_symbol_exists for strlcpy/strlcat; define HAVE_STRLCPY/HAVE_STRLCAT and exclude n_str.c when the system provides them
  • Guard -m32, -mfpmath=sse, -msse2, 32-bit linker paths, and -Wl,-melf_i386 behind CMAKE_SYSTEM_NAME/CMAKE_SYSTEM_PROCESSOR checks (Linux x86 only)
  • Add -Wl,-flat_namespace on Apple for FFF symbol interposition

test/CMakeLists.txt:

  • Guard Catch2 -m32 flag by Linux x86 check
  • Add -Wl,-flat_namespace to test executables on Apple
  • Only exclude n_str.c from lcov coverage when the file is actually compiled

n_ua.c / n_helpers.c:

  • Fix -Wstrict-prototypes: NoteUserAgent()NoteUserAgent(void)
  • Remove unused variables (j, lastLengthCount) that triggered -Wunused-but-set-variable

scripts/check_libc_dependencies.sh:

  • Add strlcpy and strlcat to the permitted libc function whitelist

.github/workflows/ci.yml:

  • Add run_macos_unit_tests job (build-only; FFF interposition limitations prevent running ctest on macOS)

Test plan

  • All existing unit tests build and pass on macOS (Apple Silicon)
  • note-posix builds and passes 13/13 tests using this branch
  • macOS CI job passes via act locally
  • Linux CI passes (verify after push of libc whitelist/lcov fixes)

@m-mcgowan m-mcgowan force-pushed the build/macos-test-support branch from cd3c7a1 to 49afe4c Compare February 24, 2026 21:15
Add conditional CMake configuration for macOS (APPLE):
- Skip -m32 and Linux-specific linker flags
- Define HAVE_STRLCPY/HAVE_STRLCAT (macOS provides these natively)
- Exclude n_str.c (strlcpy/strlcat bundled implementations)
- Suppress AppleClang-specific warnings in upstream code
- Use -flat_namespace for dylib and test executables to enable
FFF test fake symbol interposition

All changes are guarded by if(APPLE)/if(NOT APPLE) so Linux CI behavior is completely unchanged.
Use check_symbol_exists() to detect system-provided strlcpy/strlcat (macOS, *BSD) and conditionally exclude n_str.c and define HAVE_STRLCPY/ HAVE_STRLCAT guards. This avoids collisions with the platform's fortified string macros that prevented compilation on macOS.

Guard the 32-bit x86 compile/link flags behind a Linux x86 check instead of if(NOT APPLE), making the build portable to any non-x86 platform.

Suppress two AppleClang warnings-as-errors in upstream code (-Wstrict-prototypes, -Wunused-but-set-variable).

Add -Wl,-flat_namespace on macOS for both the library and test executables so FFF test fakes can interpose dylib symbols.
- n_ua.c: add void to NoteUserAgent() prototype to fix
-Wstrict-prototypes (empty parens means unspecified args in C)
- n_helpers.c: remove unused variables j and lastLengthCount that
triggered -Wunused-but-set-variable

With these fixes the -Wno-* suppressions added in the previous commit are no longer needed and are removed from CMakeLists.txt.
@m-mcgowan m-mcgowan force-pushed the build/macos-test-support branch from 49afe4c to ca24782 Compare March 9, 2026 18:01
@m-mcgowan
Copy link
Contributor Author

Reworked to remove the unused variable warning (for what looks like debug code) and fixed the string functions to use CMake-level detection about the headers provided.

  1. 2d13c08: original approach (if(APPLE) guards)
  2. 1cdf7a1: rework to check_symbol_exists + Linux x86 guards (more portable), with -Wno-* suppressions for AppleClang
  3. ca24782: fix the actual warnings at source (NoteUserAgent(void), remove unused vars), drop suppressions entirely

Adds a `run_macos_unit_tests` job that configures and builds note-c with tests on macos-latest. Tests are not run via ctest because FFF symbol interposition does not fully work on macOS — even with -flat_namespace, intra-library calls are resolved at link time and cannot be faked.
- Add `strlcpy` and `strlcat` to the libc dependency whitelist so the `check_libc_dependencies` job passes when `n_str.c` is excluded on
  systems that provide these functions natively (glibc 2.38+).
- Only add `n_str.c` to the lcov coverage exclude list when the file is actually compiled, avoiding an lcov error on unused patterns.
@m-mcgowan m-mcgowan changed the title add macOS build support for unit tests build: fix cross-platform build support and add macOS CI Mar 10, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant