Skip to content

Commit 95c6284

Browse files
committed
cmake: move NaCl host code out of Yokai
1 parent f2d90de commit 95c6284

4 files changed

Lines changed: 85 additions & 59 deletions

File tree

CMakeLists.txt

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -75,8 +75,8 @@ if (Daemon_OUT)
7575
set(CMAKE_RUNTIME_OUTPUT_DIRECTORY ${Daemon_OUT})
7676
endif()
7777

78-
set(YOKAI_NACL_HOST ON)
7978
include(Yokai/All)
79+
include(DaemonNaclHost)
8080

8181
################################################################################
8282
# Configuration options
@@ -979,8 +979,8 @@ if (DEPS_DIR AND HAS_NACL AND (BUILD_CLIENT OR BUILD_TTY_CLIENT OR BUILD_SERVER
979979

980980
add_custom_command(TARGET runtime_deps PRE_BUILD
981981
COMMAND ${CMAKE_COMMAND} -E copy_if_different
982-
${DEPS_DIR}/irt_core-${YOKAI_NACL_ARCH_NAME}.nexe
983-
${FULL_OUTPUT_DIR}/irt_core-${YOKAI_NACL_ARCH_NAME}.nexe
982+
${DEPS_DIR}/irt_core-${DAEMON_NACL_ARCH_NAME}.nexe
983+
${FULL_OUTPUT_DIR}/irt_core-${DAEMON_NACL_ARCH_NAME}.nexe
984984
)
985985

986986
# Linux uses a bootstrap program to reserve address space

cmake/DaemonNaclHost.cmake

Lines changed: 78 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,78 @@
1+
# Daemon BSD Source Code
2+
# Copyright (c) 2022-2026, Daemon Developers
3+
# All rights reserved.
4+
#
5+
# Redistribution and use in source and binary forms, with or without
6+
# modification, are permitted provided that the following conditions are met:
7+
# * Redistributions of source code must retain the above copyright
8+
# notice, this list of conditions and the following disclaimer.
9+
# * Redistributions in binary form must reproduce the above copyright
10+
# notice, this list of conditions and the following disclaimer in the
11+
# documentation and/or other materials provided with the distribution.
12+
# * Neither the name of the Daemon developers nor the
13+
# names of its contributors may be used to endorse or promote products
14+
# derived from this software without specific prior written permission.
15+
#
16+
# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
17+
# ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
18+
# WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
19+
# DISCLAIMED. IN NO EVENT SHALL DAEMON DEVELOPERS BE LIABLE FOR ANY
20+
# DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
21+
# (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
22+
# LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
23+
# ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
24+
# (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
25+
# SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
26+
27+
function(daemon_detect_nacl_arch)
28+
set(arch_name "${YOKAI_TARGET_ARCH_NAME}")
29+
set(nacl_arch "${arch_name}")
30+
31+
if (YOKAI_TARGET_SYSTEM_LINUX_COMPATIBILITY OR YOKAI_TARGET_SYSTEM_XDG_COMPATIBILITY)
32+
set(armhf_usage "arm64;armel")
33+
if ("${arch_name}" IN_LIST armhf_usage)
34+
# Load 32-bit armhf nexe on 64-bit arm64 engine on Linux with multiarch.
35+
# The nexe is system agnostic so there should be no difference with armel.
36+
set(nacl_arch "armhf")
37+
38+
set(box64_usage ppc64el riscv64)
39+
if ("${arch_name}" IN_LIST box64_usage)
40+
option(YOKAI_NACL_BOX64_EMULATION "Use Box64 to emulate x86_64 NaCl loader on unsupported platforms" ON)
41+
if (YOKAI_NACL_BOX64_EMULATION)
42+
# Use Box64 to run x86_64 NaCl loader and amd64 nexe.
43+
# Box64 must be installed and available in PATH at runtime.
44+
set(nacl_arch "amd64")
45+
add_definitions(-DDAEMON_NACL_BOX64_EMULATION)
46+
endif()
47+
endif()
48+
endif()
49+
50+
elseif (DAEMON_TARGET_SYSTEM_MACOS)
51+
if ("${arch_name}" STREQUAL "arm64")
52+
# You can get emulated NaCl going like this:
53+
# cp external_deps/macos-amd64-default_10/{nacl_loader,irt_core-amd64.nexe} build/
54+
set(nacl_arch "amd64")
55+
endif()
56+
endif()
57+
58+
string(TOUPPER "${nacl_arch_name}" nacl_arch_name_upper)
59+
60+
# The DAEMON_NACL_ARCH_NAME variable contributes to the nexe file name.
61+
set(DAEMON_NACL_ARCH_NAME "${nacl_arch}" PARENT_SCOPE)
62+
set(DAEMON_NACL_ARCH_NAME_UPPER "${nacl_arch_upper}" PARENT_SCOPE)
63+
64+
# NaCl runtime is only available on architectures that have a NaCl loader.
65+
set(nacl_runtime_arch amd64 i686 armhf)
66+
if ("${nacl_arch}" IN_LIST nacl_runtime_arch)
67+
add_definitions(-DDAEMON_NACL_RUNTIME_ENABLED)
68+
endif()
69+
endfunction()
70+
71+
daemon_detect_nacl_arch()
72+
73+
# Makes possible to do that in CMake code:
74+
# > if (DAEMON_NACL_ARCH_ARMHF)
75+
set("DAEMON_NACL_ARCH_${DAEMON_NACL_ARCH_NAME_UPPER}" ON)
76+
77+
# Add printable strings to the executable.
78+
yokai_add_buildinfo("char*" "DAEMON_NACL_ARCH_STRING" "\"${DAEMON_NACL_ARCH_NAME}\"")

cmake/Yokai/Architecture.cmake

Lines changed: 0 additions & 52 deletions
Original file line numberDiff line numberDiff line change
@@ -42,49 +42,6 @@ function(yokai_detect_arch)
4242
message(STATUS "Detected target architecture: ${arch_name}")
4343

4444
add_definitions(-DYOKAI_ARCH_${arch_name_upper})
45-
46-
if (YOKAI_NACL_HOST)
47-
set(nacl_arch "${arch_name}")
48-
49-
if (YOKAI_TARGET_SYSTEM_LINUX_COMPATIBILITY OR YOKAI_TARGET_SYSTEM_XDG_COMPATIBILITY)
50-
set(armhf_usage "arm64;armel")
51-
if ("${arch_name}" IN_LIST armhf_usage)
52-
# Load 32-bit armhf nexe on 64-bit arm64 engine on Linux with multiarch.
53-
# The nexe is system agnostic so there should be no difference with armel.
54-
set(nacl_arch "armhf")
55-
56-
set(box64_usage ppc64el riscv64)
57-
if ("${arch_name}" IN_LIST box64_usage)
58-
option(YOKAI_NACL_BOX64_EMULATION "Use Box64 to emulate x86_64 NaCl loader on unsupported platforms" ON)
59-
if (YOKAI_NACL_BOX64_EMULATION)
60-
# Use Box64 to run x86_64 NaCl loader and amd64 nexe.
61-
# Box64 must be installed and available in PATH at runtime.
62-
set(nacl_arch "amd64")
63-
add_definitions(-DYOKAI_NACL_BOX64_EMULATION)
64-
endif()
65-
endif()
66-
endif()
67-
68-
elseif (YOKAI_TARGET_SYSTEM_MACOS)
69-
if ("${arch_name}" STREQUAL "arm64")
70-
# You can get emulated NaCl going like this:
71-
# cp external_deps/macos-amd64-default_10/{nacl_loader,irt_core-amd64.nexe} build/
72-
set(nacl_arch "amd64")
73-
endif()
74-
endif()
75-
76-
string(TOUPPER "${nacl_arch_name}" nacl_arch_name_upper)
77-
78-
# The YOKAI_NACL_ARCH_NAME variable contributes to the nexe file name.
79-
set(YOKAI_NACL_ARCH_NAME "${nacl_arch}" PARENT_SCOPE)
80-
set(YOKAI_NACL_ARCH_NAME_UPPER "${nacl_arch_upper}" PARENT_SCOPE)
81-
82-
# NaCl runtime is only available on architectures that have a NaCl loader.
83-
set(nacl_runtime_arch amd64 i686 armhf)
84-
if ("${nacl_arch}" IN_LIST nacl_runtime_arch)
85-
add_definitions(-DYOKAI_NACL_RUNTIME_ENABLED)
86-
endif()
87-
endif()
8845
endfunction()
8946

9047
function(yokai_set_arch_intrinsics name)
@@ -124,18 +81,9 @@ yokai_set_intrinsics()
12481

12582
# Makes possible to do that in CMake code:
12683
# > if (YOKAI_TARGET_ARCH_ARM64)
127-
# > if (YOKAI_NACL_ARCH_ARMHF)
12884
set("YOKAI_TARGET_ARCH_${YOKAI_TARGET_ARCH_NAME_UPPER}" ON)
12985

130-
if (YOKAI_NACL_HOST)
131-
set("YOKAI_NACL_ARCH_${YOKAI_NACL_ARCH_NAME_UPPER}" ON)
132-
endif()
133-
13486
if (YOKAI_SOURCE_GENERATOR)
13587
# Add printable strings to the executable.
13688
yokai_add_buildinfo("char*" "YOKAI_ARCH_STRING" "\"${YOKAI_TARGET_ARCH_NAME}\"")
137-
138-
if (YOKAI_NACL_HOST)
139-
yokai_add_buildinfo("char*" "YOKAI_NACL_ARCH_STRING" "\"${YOKAI_NACL_ARCH_NAME}\"")
140-
endif()
14189
endif()

src/engine/framework/VirtualMachine.cpp

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -138,7 +138,7 @@ static Cvar::Cvar<int> vm_timeout(
138138
"Receive timeout in seconds",
139139
Cvar::NONE, 2);
140140

141-
#if defined(YOKAI_NACL_RUNTIME_ENABLED)
141+
#if defined(DAEMON_NACL_RUNTIME_ENABLED)
142142
static Cvar::Cvar<bool> vm_nacl_available(
143143
"vm.nacl.available",
144144
"Whether NaCl runtime is available on this platform",
@@ -329,7 +329,7 @@ static std::pair<Sys::OSHandle, IPC::Socket> CreateNaClVM(std::pair<IPC::Socket,
329329
// Extract the nexe from the pak so that nacl_loader can load it
330330
module = win32Force64Bit
331331
? name + "-amd64.nexe"
332-
: Str::Format("%s-%s.nexe", name, YOKAI_NACL_ARCH_STRING);
332+
: Str::Format("%s-%s.nexe", name, DAEMON_NACL_ARCH_STRING);
333333
if (extract) {
334334
try {
335335
FS::File out = FS::HomePath::OpenWrite(module);
@@ -349,7 +349,7 @@ static std::pair<Sys::OSHandle, IPC::Socket> CreateNaClVM(std::pair<IPC::Socket,
349349
Q_snprintf(rootSocketRedir, sizeof(rootSocketRedir), "%d:%d", ROOT_SOCKET_FD, (int)(intptr_t)pair.second.GetHandle());
350350
irt = FS::Path::Build(naclPath, win32Force64Bit
351351
? "irt_core-amd64.nexe"
352-
: Str::Format("irt_core-%s.nexe", YOKAI_NACL_ARCH_STRING));
352+
: Str::Format("irt_core-%s.nexe", DAEMON_NACL_ARCH_STRING));
353353
nacl_loader = FS::Path::Build(naclPath, win32Force64Bit ? "nacl_loader-amd64" EXE_EXT : "nacl_loader" EXE_EXT);
354354

355355
if (!FS::RawPath::FileExists(modulePath)) {
@@ -614,7 +614,7 @@ void VMBase::Create()
614614
std::pair<IPC::Socket, IPC::Socket> pair = IPC::Socket::CreatePair();
615615

616616
IPC::Socket rootSocket;
617-
#if !defined(YOKAI_NACL_RUNTIME_ENABLED)
617+
#if !defined(DAEMON_NACL_RUNTIME_ENABLED)
618618
if (type == TYPE_NACL || type == TYPE_NACL_LIBPATH) {
619619
Sys::Error("NaCl VM is not supported on this platform. "
620620
"Set vm.cgame.type and vm.sgame.type to 3 (native DLL) "

0 commit comments

Comments
 (0)