Skip to content

Rework external_deps for Saigo and CMake-based NaCL rebuild#1986

Open
illwieckz wants to merge 29 commits into
masterfrom
illwieckz/deps
Open

Rework external_deps for Saigo and CMake-based NaCL rebuild#1986
illwieckz wants to merge 29 commits into
masterfrom
illwieckz/deps

Conversation

@illwieckz

@illwieckz illwieckz commented Jun 26, 2026

Copy link
Copy Markdown
Member

This introduce a big change: the NaCl loader and bootstrap executables are now suffixed with their architecture, like the IRT: nacl_loader-amd64, nacl_helper_bootstrap-amd4.

To avoid name collision, the armhf loader wrapper for running armhf on arm64 is now named nacl_helper_bootstrap-ldarmhf, it chainloads what is now nacl_helper_bootstrap-armhf.

This change genericize what already existed for loading the amd64 loader on windows-amd64 when running the i686 engine, except now that's all the loaders that have a suffix, not just the non-native one.

This makes things very easy to manage, for example the external_deps script just loops over all the different nexe architecture an engine architecture can support and builds the nacl_loader for it. This already works for the windows-i686 deps build: it builds both the i686 and amd64 loaders using MinGW.

This same mechanism would be usable in the future to build for the linux-arm64 deps both the armhf loader and the amd64 loader (purposed to be running on box64 when armhf support isn't there in hardware).

With that loader suffix thing I deeply rewrote the NaCl startup code in VirtualMachine.cpp, which is then already shaped for the ability to chose between armhf or amd64 on box64 at run time. The integration of box64 (CMake code, etc.) isn't there, but the VirtualMachine.cpp code is ready. That rework is deep and deduplicate and refactor intensively the binary name construction and the command construction.

I started adding the macos-arm64-default deps configuration. For now not everything works, but it already successfully builds the amd64 loader.

The IRT was previously fetched as part of the naclsdk, which is not removed yet, so the IRT is still shipped the old way at this point.

For Saigo it uses the recent release I packaged:

For the NaCl loader it uses my illwieckz/staging branch that contains all my unmerged code:

@illwieckz

illwieckz commented Jun 26, 2026

Copy link
Copy Markdown
Member Author

The CI fails because I haven't uploaded preview external_deps archives yet (it's too early).

@illwieckz

illwieckz commented Jun 26, 2026

Copy link
Copy Markdown
Member Author

Building the NaCl loader with MinGW requires JWasm:

I wonder if we can extend the script to build specific host tools.

I actually suspect that some macOS tools are meant to be built for the host as well (nasm, pkg-config…), and that we were lucky to be able to reuse the ones built for the target because we weren't cross-compiling…

@illwieckz

illwieckz commented Jun 26, 2026

Copy link
Copy Markdown
Member Author

I'm very proud of this:

build_naclruntime() {
	local nacl_arch_list=()

	case "${PLATFORM}" in
	windows-amd64-*)
		nacl_arch_list+=('amd64')
		;;
	windows-i686-*)
		nacl_arch_list+=('i686')
		nacl_arch_list+=('amd64')
		;;
	linux-amd64-*)
		nacl_arch_list+=('amd64')
		;;
	linux-i686-*)
		nacl_arch_list+=('i686')
		;;
	linux-arm64-*)
		nacl_arch_list+=('armhf')
		;;
	linux-armhf-*)
		nacl_arch_list+=('armhf')
		;;
	macos-amd64-*)
		nacl_arch_list+=('amd64')
		;;
	macos-arm64-*)
		nacl_arch_list+=('amd64')
		;;
	*)
		log ERROR 'Unsupported platform for naclruntime'
		;;
	esac

	local dir_name="DaemonEngine-native_client-${NACLRUNTIME_REVISION:0:7}"
	local archive_name="native_client-${NACLRUNTIME_REVISION}.zip"

	download_extract naclruntime "${archive_name}" \
		"{$NACLRUNTIME_BASEURL}/${NACLRUNTIME_REVISION}"

	"${download_only}" && return

	cd "${dir_name}"

	for nacl_arch in "${nacl_arch_list[@]}"
	do
		(
			setup_platform "${PLATFORM_SYSTEM}-${nacl_arch}-${PLATFORM_COMPILER}"
			cmake_build
		)

		case "${PLATFORM}" in
		linux-*)
			mv "${PREFIX}/bin/nacl_helper_bootstrap" "${PREFIX}/nacl_helper_bootstrap-${nacl_arch}"
			;;
		esac

		mv "${PREFIX}/bin/sel_ldr${EXE_EXT}" "${PREFIX}/nacl_loader-${nacl_arch}${EXE_EXT}"
	done

@illwieckz

illwieckz commented Jun 26, 2026

Copy link
Copy Markdown
Member Author

I actually suspect that some macOS tools are meant to be built for the host as well (nasm, pkg-config…), and that we were lucky to be able to reuse the ones built for the target because we weren't cross-compiling…

Yes, pkg-config is a host tool required to build opusfile on macOS. There is already some specific code (but specific to pkg-config) to build it for the host, but we still install it in the packaged prefix.

So we better refactor this and reuse the mechanism for JWasm.

@illwieckz illwieckz force-pushed the illwieckz/deps branch 4 times, most recently from 65ccd0f to 96a1e9d Compare June 26, 2026 05:49
@illwieckz illwieckz force-pushed the illwieckz/deps branch 2 times, most recently from eb0893d to 6d2955a Compare June 26, 2026 06:46
@illwieckz illwieckz force-pushed the illwieckz/deps branch 2 times, most recently from bd56fb3 to 7179f26 Compare June 26, 2026 07:50
@illwieckz

illwieckz commented Jun 26, 2026

Copy link
Copy Markdown
Member Author

So we better refactor this and reuse the mechanism for JWasm.

Now done.

Those “packages“:

  • native-pkgconfig (macOS)
  • native-nasm (macOS)
  • native-jwasm (MinGW)

Are now guaranteed to be compiled the native way and stored in their own native prefix that is not packaged.
It also means that those tools are not executed from the prefix that is to be packaged.

The building of the NaCl client is now working out of the box with MinGW. Well, at least on Ubuntu 24.04 Noble. On Debian 13 Trixie I get some “-Wincompatible-pointer-types” errors, to be fixed in Native Client upstream. The build tooling is fine.

@illwieckz illwieckz force-pushed the illwieckz/deps branch 2 times, most recently from 8db6365 to c456a3f Compare June 26, 2026 08:00
@illwieckz

Copy link
Copy Markdown
Member Author

Something annoying is that both the NASM build we download (2.16.03) and the latest stable one (3.01 from October 2025) provide a macOS fat binary of i386 and amd64, no arm64… So we can compile macOS deps for both amd64 and arm64 from amd64, but we can only build arm64 deps from arm64.

That's not a big deal because I build on amd64, but that is annoying.

@illwieckz

Copy link
Copy Markdown
Member Author

The building of the NaCl client is now working out of the box with MinGW. Well, at least on Ubuntu 24.04 Noble. On Debian 13 Trixie I get some “-Wincompatible-pointer-types” errors, to be fixed in Native Client upstream. The build tooling is fine.

The fix can be found there:

@illwieckz

Copy link
Copy Markdown
Member Author

I started adding the macos-arm64-default deps configuration. For now not everything works, but it already successfully builds the amd64 loader.

Now everything builds.

@illwieckz

Copy link
Copy Markdown
Member Author

I'm investigating the upgrade of libs (I'm testing the new versions), since I do remember that at least macOS can benefit from a newer SDL3.

@illwieckz

Copy link
Copy Markdown
Member Author

Welp, SDL3 is triggering a bug in the system libs:

In file included from /usr/lib/x86_64-linux-gnu/glib-2.0/include/glibconfig.h:9,
                 from /usr/include/glib-2.0/glib/gtypes.h:32,
                 from /usr/include/glib-2.0/glib/galloca.h:32,
                 from /usr/include/glib-2.0/glib.h:30,
                 from /usr/include/ibus-1.0/ibusshare.h:40,
                 from /usr/include/ibus-1.0/ibus.h:30,
                 from build-linux-armhf-default_12/sdl3/SDL3-3.4.10/src/core/linux/SDL_ibus.h:29,
                 from build-linux-armhf-default_12/sdl3/SDL3-3.4.10/src/core/linux/SDL_ibus.c:24:
/usr/include/glib-2.0/glib/gtypes.h: In function '_GLIB_CHECKED_ADD_U64':
/usr/include/glib-2.0/glib/gtypes.h:463:3: error: static assertion failed: "Expression evaluates to false"
  463 |   G_STATIC_ASSERT(sizeof (unsigned long long) == sizeof (guint64));
      |   ^~~~~~~~~~~~~~~

@illwieckz

illwieckz commented Jun 26, 2026

Copy link
Copy Markdown
Member Author

It was just a poorly worded dependency mistake.

@illwieckz illwieckz force-pushed the illwieckz/deps branch 2 times, most recently from 7512bc0 to 094c453 Compare June 26, 2026 13:56
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