Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
68 changes: 68 additions & 0 deletions .github/workflows/macos-appkit-provider.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,68 @@
name: macOS AppKit provider checks

"on":
workflow_dispatch:
inputs:
architecture:
description: Host architecture to check
type: choice
options: [both, x86_64, arm64]
default: both

permissions:
contents: read

concurrency:
group: macos-appkit-provider-${{ github.ref }}-${{ inputs.architecture }}
cancel-in-progress: false

# Build and exercise the AppKit desktop provider only. LLVM is off and no SDK
# is configured, qualified or published, so a cycle here costs minutes rather
# than a full source campaign.
jobs:
provider:
name: macOS ${{ matrix.host.arch }} AppKit provider
runs-on: ${{ matrix.host.runner }}
timeout-minutes: 30
strategy:
fail-fast: false
max-parallel: 2
matrix:
host: ${{ fromJSON(inputs.architecture == 'arm64' && '[{"runner":"macos-15","arch":"arm64"}]' || inputs.architecture == 'x86_64' && '[{"runner":"macos-15-intel","arch":"x86_64"}]' || '[{"runner":"macos-15-intel","arch":"x86_64"},{"runner":"macos-15","arch":"arm64"}]') }}
defaults:
run:
shell: bash
steps:
# Official v5 tag commit, matching the other workflows in this repository.
- uses: actions/checkout@fbc6f3992d24b796d5a048ff273f7fcc4a7b6c09 # v5
with:
persist-credentials: false
- name: Report the desktop session
timeout-minutes: 2
run: |
echo "runner arch: $(uname -m)"
# A provider that cannot reach a window server can still build, so
# record the session before anything is interpreted as a provider
# fault.
/usr/bin/python3 -c "
import ctypes, ctypes.util
core = ctypes.CDLL(ctypes.util.find_library('CoreGraphics'))
core.CGMainDisplayID.restype = ctypes.c_uint32
print('CGMainDisplayID:', core.CGMainDisplayID())
"
- name: Configure without LLVM
timeout-minutes: 8
run: |
cmake -S . -B build/ci \
-DCMAKE_BUILD_TYPE=Release \
-DBUILD_TESTING=ON \
-DNIL_ENABLE_LLVM=OFF
- name: Build the AppKit provider and its fixture
timeout-minutes: 20
run: cmake --build build/ci --target nil_ui_runtime_appkit_tests --parallel 3
- name: Availability without opening a display
timeout-minutes: 2
run: ./build/ci/bin/nil_ui_runtime_appkit_tests --provider-present
- name: Provider contract against a real session
timeout-minutes: 5
run: ./build/ci/bin/nil_ui_runtime_appkit_tests --display
39 changes: 29 additions & 10 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,11 @@ if(MSVC)
"/MANIFESTINPUT:${CMAKE_CURRENT_SOURCE_DIR}/cmake/utf8.manifest")
endif()

if(APPLE)
# The macOS desktop provider and its fixture are Objective-C++.
enable_language(OBJCXX)
endif()

add_subdirectory(nilcompiler)
add_subdirectory(nilinterpreter)
add_subdirectory(nillsp)
Expand Down Expand Up @@ -247,11 +252,29 @@ if(BUILD_TESTING)
add_test(NAME nil.etp-codec COMMAND $<TARGET_FILE:nil_etp_codec_tests>)
set_tests_properties(nil.etp-codec PROPERTIES LABELS "tools;ipc;etp" TIMEOUT 30)

add_executable(nil_ui_runtime_tests tests/ui_runtime_tests.cpp)
target_link_libraries(nil_ui_runtime_tests PRIVATE nilruntime Threads::Threads)
target_include_directories(nil_ui_runtime_tests PRIVATE "${CMAKE_CURRENT_SOURCE_DIR}/nilcompiler/src")
target_compile_features(nil_ui_runtime_tests PRIVATE cxx_std_17)
add_test(NAME nil.ui-runtime COMMAND $<TARGET_FILE:nil_ui_runtime_tests>)
# The provider fixture follows the provider: tests/ui_runtime_tests.cpp
# inspects loaded GTK modules and symbol origins, so it describes the GTK
# provider and cannot speak for Win32.
if(WIN32)
add_executable(nil_ui_runtime_win32_tests tests/ui_runtime_win32_tests.cpp)
target_link_libraries(nil_ui_runtime_win32_tests PRIVATE nilruntime Threads::Threads)
target_include_directories(nil_ui_runtime_win32_tests PRIVATE "${CMAKE_CURRENT_SOURCE_DIR}/nilcompiler/src")
target_compile_features(nil_ui_runtime_win32_tests PRIVATE cxx_std_17)
set(NIL_UI_PROVIDER_TEST nil_ui_runtime_win32_tests)
elseif(APPLE)
add_executable(nil_ui_runtime_appkit_tests tests/ui_runtime_appkit_tests.mm)
target_link_libraries(nil_ui_runtime_appkit_tests PRIVATE nilruntime Threads::Threads)
target_include_directories(nil_ui_runtime_appkit_tests PRIVATE "${CMAKE_CURRENT_SOURCE_DIR}/nilcompiler/src")
target_compile_features(nil_ui_runtime_appkit_tests PRIVATE cxx_std_17)
set(NIL_UI_PROVIDER_TEST nil_ui_runtime_appkit_tests)
else()
add_executable(nil_ui_runtime_tests tests/ui_runtime_tests.cpp)
target_link_libraries(nil_ui_runtime_tests PRIVATE nilruntime Threads::Threads)
target_include_directories(nil_ui_runtime_tests PRIVATE "${CMAKE_CURRENT_SOURCE_DIR}/nilcompiler/src")
target_compile_features(nil_ui_runtime_tests PRIVATE cxx_std_17)
set(NIL_UI_PROVIDER_TEST nil_ui_runtime_tests)
endif()
add_test(NAME nil.ui-runtime COMMAND $<TARGET_FILE:${NIL_UI_PROVIDER_TEST}>)
set_tests_properties(nil.ui-runtime PROPERTIES LABELS "ui;runtime" TIMEOUT 30)
add_executable(nil_ui_lifecycle_tests tests/ui_lifecycle_tests.cpp)
target_link_libraries(nil_ui_lifecycle_tests PRIVATE nilcompiler_core nilruntime ${CMAKE_DL_LIBS})
Expand Down Expand Up @@ -629,10 +652,6 @@ if(BUILD_TESTING)
if(WIN32)
set(NIL_UI_DISPLAY_CONTRACT "${CMAKE_CURRENT_SOURCE_DIR}/tests/tools/windows_ui_display_contract.py")
set(NIL_UI_DISPLAY_TIMEOUT 660)
add_test(NAME nil.ui-windows-loader
COMMAND "${Python3_EXECUTABLE}" "${CMAKE_CURRENT_SOURCE_DIR}/tests/tools/windows_ui_loader_contract.py"
--probe $<TARGET_FILE:nil_ui_runtime_tests>)
set_tests_properties(nil.ui-windows-loader PROPERTIES LABELS "ui;runtime;windows" TIMEOUT 180)
endif()
add_test(NAME nil.ui-display
COMMAND "${Python3_EXECUTABLE}" "${NIL_UI_DISPLAY_CONTRACT}"
Expand All @@ -642,7 +661,7 @@ if(BUILD_TESTING)
--sdk "${CMAKE_CURRENT_SOURCE_DIR}/nilstd/src"
--source "${CMAKE_CURRENT_SOURCE_DIR}/tests/ui/gtk_desktop.matrix"
--interaction-source "${CMAKE_CURRENT_SOURCE_DIR}/tests/ui/gtk_interaction.matrix"
--provider-test $<TARGET_FILE:nil_ui_runtime_tests>
--provider-test $<TARGET_FILE:${NIL_UI_PROVIDER_TEST}>
--lifecycle-test $<TARGET_FILE:nil_ui_lifecycle_tests>
--llvm "${NIL_ENABLE_LLVM}")
set_tests_properties(nil.ui-display PROPERTIES LABELS "ui;routes" SKIP_RETURN_CODE 77 TIMEOUT "${NIL_UI_DISPLAY_TIMEOUT}")
Expand Down
29 changes: 27 additions & 2 deletions docs/platform-support.md
Original file line number Diff line number Diff line change
Expand Up @@ -92,6 +92,26 @@ tests after the numeric-address correction, including IPv4/IPv6 timeout and
socket-close checks. The original checkout, installed SDK and provider DLLs
remain unchanged.

A private Windows build at `8aa60d2` records the first complete local suite since
the port closeout: 574 registered tests against 572 on the Linux reference. The
two inventories share 569 tests. Five are Windows-only: console UTF-8,
unmanifested UTF-8 file paths, the GTK loader, the native memory-limit self-test
and the SDK preflight. Three are Linux-only: toolchain inputs, POSIX process
semantics and a socket-backpressure check of the Python test client rather than
of a product surface. No language, frontend, type-checker, IR, interpreter, LLVM
or standard-library test fails. Four shared contracts fail only when the suite
runs as `SYSTEM`: that account reports `TEMP` cased `C:\WINDOWS\TEMP`, the
toolchain reports paths in their on-disk casing, and the affected assertions
compare the two strings exactly; the same four pass unchanged under an ordinary
user account. The Windows-only SDK preflight needs a machine execution
policy that permits local scripts, because it invokes `powershell.exe -File`
deliberately without a bypass; under the Windows client default of `Restricted`
every subtest observes a policy refusal instead of a preflight diagnostic, and
it passes once the policy is `RemoteSigned`. Two display tests skip for want of
an interactive desktop session and both PostgreSQL tests skip without a
server. This supplements the recorded Windows baseline; it neither
replaces the accepted SDK nor qualifies a new one.

## Native executable context

Thin Mach-O64 x86_64 and arm64 objects and executables support bounded inspection
Expand Down Expand Up @@ -150,8 +170,13 @@ the complete admission rules.
bound. Native diagnostics show that the fixed 96 MiB virtual-memory cap is
rejected at process setup; larger diagnostic profiles do not replace it.
Successful lifetime execution routes remain covered by the ordinary suite.
- The GTK provider currently supports Linux and Windows. macOS UI/provider
support and live desktop acceptance remain open. Both hosted Mac architectures
- Desktop UI now uses one provider per platform: GTK on Linux and Win32 on
Windows. The Windows provider passes the full desktop contract on a real
interactive session -- provider contract, lifecycle release observation, the
Matrix desktop suite and the interaction suite that drives real keyboard
input -- while a session without an interactive window station still skips.
macOS UI/provider support and live desktop acceptance remain open; AppKit
replaces the retired GTK-on-macOS work. Both hosted Mac architectures
now pass the prerequisite GLib, Cairo-Quartz and HarfBuzz/CoreText compile,
link and runtime checks, plus exact own-process AppKit key dispatch, view
delivery and window closure. Directed keyboard input to a verified child and
Expand Down
41 changes: 21 additions & 20 deletions docs/standard-library/ui.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,13 @@

`read nil.std.ui` provides a Matrix desktop library with typed windows, widgets,
events and explicit model bindings. Ny programs can import the same module.
The VM and native compiler use the same checked GTK4 provider on Linux and
The VM and native compiler use one desktop provider per platform, each behind
the same checked boundary: a GTK4 provider on Linux and a Win32 provider on
Windows. Windows remains a development target, not a qualified release platform.
The macOS provider is being integrated. Its private GTK stack and toolkit
window/event checks pass on Intel and Apple Silicon; product and language-level
desktop acceptance remain in progress. See [platform support](../platform-support.md).
The macOS provider is being integrated; AppKit replaces the earlier GTK-on-macOS
work, because a GTK process on macOS never runs the AppKit event loop and is
therefore invisible to the accessibility APIs that assistive technology and
directed input depend on. See [platform support](../platform-support.md).
Examples display the framework generation as **NIL²**, with **NIL^2** as the
plain-text spelling. This presentation does not change numeric release or
artifact identities in `VERSION`.
Expand Down Expand Up @@ -41,20 +43,19 @@ symbols can load; it does not connect to a display. Window creation returns
`Result.Error` if the graphical session cannot be initialized. There is no
headless widget simulation or automatic package installation.

On Windows, deploy a compatible x64 GTK4 runtime with its dependencies and
runtime data. Set `NIL_UI_GTK_DIRECTORY` to its absolute DLL directory, or place
the DLLs beside the executable. An explicitly empty, relative or invalid setting
fails closed rather than falling back. The loader accepts the `libgtk-4-1.dll`
or `gtk-4-1.dll` naming family and corresponding GLib/GObject names; ambiguous
duplicates are rejected. It uses wide paths and scoped DLL search flags, without
changing process-wide DLL policy or searching the current directory or `PATH`.
Already-loaded direct GTK/GLib/GObject modules must match the selected files.
This does not establish isolation from every transitive DLL already loaded by
an embedding host. GTK is an optional external dependency, not bundled in the SDK.

Windows window creation requires an interactive, visible window station.
Service-session requests return a display error before GTK initialization;
successful provider availability alone does not prove a desktop is usable.
Windows needs no external toolkit. The provider is Win32 itself, so
`available with nothing` is always true there and no runtime has to be deployed
or configured; GTK is neither used nor loaded on Windows. Because USER32 and
GDI32 are called directly rather than loaded on demand, every linked program
imports them, which is why `user32.lib` and `gdi32.lib` join `ws2_32.lib` in the
Windows link lines and in the incremental build's toolchain identity.

Windows window creation still requires an interactive, visible window station.
A service session, or an SSH session with no desktop, returns a display error
before any window is created; successful provider availability alone does not
prove a desktop is usable. Win32 supplies no box or grid container, so the
provider owns the layout pass for rows, columns and grids; sizes therefore come
from measuring text with the system message font rather than from the toolkit.

The macOS source provider requires `NIL_UI_GTK_DIRECTORY` to name an existing
absolute trusted directory containing `libgtk-4.1.dylib`,
Expand Down Expand Up @@ -97,7 +98,7 @@ second window or widget.
| `set-expansion(widget, horizontal, vertical)` | Set the two layout expansion flags. The writes are sequential, not transactional. |
| `attach-grid(grid, child, column, row, column-span, row-span)` | Reposition an existing child of that grid; it cannot reparent a widget. |
| `focus-widget(widget)` | Request keyboard focus, normally after showing the window. |
| `activate-widget(widget)` | Request GTK activation of an enabled button or checkbox. |
| `activate-widget(widget)` | Request the provider's real activation of an enabled button or checkbox. |
| `widget-width(widget)`, `widget-height(widget)` | `Result<number,text>`; current allocation in pixels, which can be zero before layout. |

Mutation operations return `Result<boolean,text>` with `yes` on success unless
Expand Down Expand Up @@ -139,7 +140,7 @@ when a field cannot be read. A retained event therefore describes the original
event even after another mutation or window close. Its copied target handle
can still become stale.

Polling is nonblocking and processes a bounded batch of GTK work. An ordinary
Polling is nonblocking and processes a bounded batch of provider work. An ordinary
event loop sleeps briefly when it receives `Option.None`; the example uses
16 milliseconds. Call UI operations from the context's creation thread and use
one UI thread in the process. Worker jobs should return application data for
Expand Down
3 changes: 2 additions & 1 deletion nilbuild/windows_toolchain_inputs.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -189,7 +189,8 @@ class collector {
}
}
if (error || !library(runtime, 0)) return {};
for (const auto *name : {"kernel32.lib", "ws2_32.lib", "msvcrt.lib", "ucrt.lib",
for (const auto *name : {"kernel32.lib", "ws2_32.lib", "user32.lib", "gdi32.lib",
"msvcrt.lib", "ucrt.lib",
"vcruntime.lib", "legacy_stdio_definitions.lib"}) {
const auto selected = resolve(name);
if (!selected || !library(*selected, 0)) return {};
Expand Down
27 changes: 25 additions & 2 deletions nilcompiler/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,22 @@ set(NILCOMPILER_CORE_SOURCES
src/executable_context.cpp
)

# One desktop provider per platform: GTK is the Linux (and macOS) provider,
# Win32 is the Windows provider. Both implement the same ui.v1 contract and
# share its toolkit-independent half through src/ui_runtime_shared.hpp, so
# exactly one of them is ever compiled into the runtime.
if(WIN32)
set(NIL_UI_PROVIDER_SOURCE src/ui_runtime_win32.cpp)
elseif(APPLE)
enable_language(OBJCXX)
set(NIL_UI_PROVIDER_SOURCE src/ui_runtime_appkit.mm)
# ARC owns the toolkit objects the provider stores in its node table.
set_source_files_properties(src/ui_runtime_appkit.mm PROPERTIES
COMPILE_OPTIONS "-fobjc-arc")
else()
set(NIL_UI_PROVIDER_SOURCE src/ui_runtime.cpp)
endif()

# Compile the runtime once as PIC so both the portable SDK shared library and
# the static companion use the same implementation and versioned C ABI.
add_library(nilruntime_objects OBJECT
Expand All @@ -53,7 +69,7 @@ add_library(nilruntime_objects OBJECT
src/owned_runtime.cpp
src/secure_file_io.cpp
src/database_runtime.cpp
src/ui_runtime.cpp
${NIL_UI_PROVIDER_SOURCE}
src/pattern_engine.cpp
src/nildata.cpp
)
Expand All @@ -73,7 +89,14 @@ foreach(nil_runtime_target IN ITEMS nilruntime nilruntime_shared)
if(WIN32)
# PostgreSQL's bounded socket wait and numeric-address validation use
# Winsock; propagate it to static build-tree consumers as well as DLLs.
target_link_libraries(${nil_runtime_target} PUBLIC ws2_32)
# The Win32 desktop provider calls USER32 and GDI32 directly, unlike
# the dynamically loaded GTK provider, so those travel the same way.
target_link_libraries(${nil_runtime_target} PUBLIC ws2_32 user32 gdi32)
endif()
if(APPLE)
# The AppKit desktop provider calls Cocoa and CoreGraphics directly,
# so both travel to every consumer of the runtime.
target_link_libraries(${nil_runtime_target} PUBLIC "-framework Cocoa" "-framework CoreGraphics")
endif()
set_target_properties(${nil_runtime_target} PROPERTIES
CXX_EXTENSIONS OFF
Expand Down
9 changes: 7 additions & 2 deletions nilcompiler/src/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2244,8 +2244,8 @@ static int compile_main(int argc, char *argv[], ny::analysis_session *analysis)
// otherwise only ever inline - without it a generated call to printf
// is an unresolved external.
const std::vector<std::string> windows_crt_libraries = {
"kernel32.lib", "ws2_32.lib", "msvcrt.lib", "ucrt.lib", "vcruntime.lib",
"legacy_stdio_definitions.lib"};
"kernel32.lib", "ws2_32.lib", "user32.lib", "gdi32.lib", "msvcrt.lib",
"ucrt.lib", "vcruntime.lib", "legacy_stdio_definitions.lib"};
const auto manifest_path = *private_output_workspace / "utf8.manifest";
const auto manifest_publish = ny::detail::write_file_atomic(
manifest_path,
Expand Down Expand Up @@ -2315,6 +2315,7 @@ static int compile_main(int argc, char *argv[], ny::analysis_session *analysis)
std::vector<std::string> arguments = {
driver->u8string(), "-o", link_output_path.u8string(),
obj_path.u8string(), native_runtime->u8string(), "ws2_32.lib",
"user32.lib", "gdi32.lib",
"-Xlinker", "/MANIFEST:EMBED", "-Xlinker", manifest_argument};
arguments.insert(arguments.end(), link_libraries.begin(),
link_libraries.end());
Expand Down Expand Up @@ -2360,6 +2361,10 @@ static int compile_main(int argc, char *argv[], ny::analysis_session *analysis)
quote_posix_shell_argument(native_runtime->string());
#if defined(__linux__)
cmd += " -ldl";
#endif
#if defined(__APPLE__)
// As above: nil.a carries the AppKit provider on Darwin.
cmd += " -framework Cocoa -framework CoreGraphics";
#endif
for (const auto &lib : link_libraries) {
cmd += " " + quote_posix_shell_argument(lib);
Expand Down
Loading
Loading