From 7b1051d6b064ac5633e544fb883f61ebbf8d802b Mon Sep 17 00:00:00 2001 From: agorangetek Date: Sat, 19 Sep 2026 12:04:42 +0300 Subject: [PATCH] tests/unix-tty: build on Darwin The suite that builds a library with -dylib and loads it back through fb_DylibLoad() could not be built on macOS at all, which is why nothing exercised that path on Apple silicon: - tester.cxx uses std::optional, which needs C++17. Apple clang does not default to it and the build stopped there; request it explicitly, which is a no-op for toolchains that already default to it. - check_tty_state_is_equal() and dump_tty_state() compare termios.c_line, a Linux extension; the BSDs, Darwin included, have no such field. Guard it. - the makefile hard-coded libexamplelib.so. Mach-O shared libraries are .dylib -- fbc names them that way on Darwin from freebasic/fbc#479 -- so pick the extension from the platform. With these, `make tests` builds on Darwin and the two dylibload testees pass on Apple silicon: testee-dylibload-only-examplelib 123 hello hello hello testee-dylibload-dylibfree-examplelib 123 hello hello hello The C++ tester itself still requires a real TTY to run, which is unchanged. --- tests/unix-tty/makefile | 16 +++++++++++++--- tests/unix-tty/tester.cxx | 5 +++++ 2 files changed, 18 insertions(+), 3 deletions(-) diff --git a/tests/unix-tty/makefile b/tests/unix-tty/makefile index eb3509840..70f45f130 100644 --- a/tests/unix-tty/makefile +++ b/tests/unix-tty/makefile @@ -2,7 +2,9 @@ FBC := fbc CXX := g++ FBFLAGS := -CXXFLAGS := -O2 -g +# tester.cxx uses std::optional, which needs C++17; Apple clang does not +# default to it, and this suite is where -dylib is exercised on Darwin. +CXXFLAGS := -O2 -g -std=c++17 LDFLAGS := ALLFBFLAGS := $(FBFLAGS) @@ -12,7 +14,15 @@ ALLLDFLAGS := $(LDFLAGS) TESTEE_SOURCES := $(sort $(wildcard testee-*.bas)) TESTEE_BINARIES := $(patsubst %.bas,%,$(TESTEE_SOURCES)) -ALL_BINARIES := tester $(TESTEE_BINARIES) libexamplelib.so examplebin +# Mach-O uses .dylib for shared libraries, ELF targets use .so +ifeq ($(shell uname -s),Darwin) +LIBEXT := .dylib +else +LIBEXT := .so +endif +LIBEXAMPLELIB := libexamplelib$(LIBEXT) + +ALL_BINARIES := tester $(TESTEE_BINARIES) $(LIBEXAMPLELIB) examplebin all: $(ALL_BINARIES) @@ -25,7 +35,7 @@ $(TESTEE_BINARIES): %: %.bas # #include dependency testee-dylibload-dylibfree-examplelib: testee-dylibload-only-examplelib.bas -libexamplelib.so: examplelib.bas +$(LIBEXAMPLELIB): examplelib.bas $(FBC) $(ALLFBFLAGS) $< -dylib examplebin: examplebin.bas diff --git a/tests/unix-tty/tester.cxx b/tests/unix-tty/tester.cxx index cde19040c..aac8056c8 100644 --- a/tests/unix-tty/tester.cxx +++ b/tests/unix-tty/tester.cxx @@ -57,7 +57,10 @@ std::string dump_tty_state(const struct termios &state) { s << " c_oflag=0x" << std::hex << state.c_oflag << '\n'; s << " c_cflag=0x" << std::hex << state.c_cflag << '\n'; s << " c_lflag=0x" << std::hex << state.c_lflag << '\n'; +#ifdef __linux__ + // c_line is a Linux extension; the BSDs, Darwin included, have no such field s << " c_line=0x" << std::hex << static_cast(state.c_line) << '\n'; +#endif for (size_t i = 0; i < NCCS; ++i) { s << " c_cc[" << std::dec << i << "]=0x" << std::hex << static_cast(state.c_cc[i]) << '\n'; } @@ -80,7 +83,9 @@ void check_tty_state_is_equal(const struct termios &a, const struct termios &b) CHECK(c_oflag); CHECK(c_cflag); CHECK(c_lflag); +#ifdef __linux__ CHECK(c_line); +#endif for (size_t i = 0; i < NCCS; ++i) { if (a.c_cc[i] != b.c_cc[i]) { std::ostringstream s;