The library is built with the recompiler, in every configuration that has it. The smallest one leaves out both runtimes:
cmake -S . -B build/tools -DSNX_TOOLS_ONLY=ON -DSNX_BUILD_GNUABI=OFF
cmake --build build/tools --target scarletnx-recompiler
cmake --install build/tools --prefix /opt/scarletnx
ctest --test-dir build/tools -R recompiler_library --output-on-failure
The install puts lib/libscarletnx-recompiler.a, the headers under include/scarletnx/
and a CMake package under lib/cmake/ScarletNXRecompiler/ in the prefix. The library is
built in every configuration and installed in a tools-only one. A full build installs the
emulator alone unless -DSNX_RECOMPILER_INSTALL=ON is given. A consumer needs nothing
else from this tree:
find_package(ScarletNXRecompiler REQUIRED)
target_link_libraries(my_emulator PRIVATE ScarletNX::recompiler)
A project can also build the library in its own tree, fetched with
CPM.cmake (or added with add_subdirectory), with CMake 3.28 or newer,
which CPMUtil, the build's own package fetcher, needs.
With every driver off, the configure needs the compiler and nothing else: no third-party
package is downloaded and no font or other asset of the runtimes is fetched. ScarletNX's
tests are left out when another project includes it (SNX_BUILD_TESTING, on only at the
top level), without changing that project's BUILD_TESTING:
CPMAddPackage(NAME ScarletNX
GIT_REPOSITORY https://github.com/scarletnx/ScarletNX.git
GIT_TAG main # a commit, for a reproducible build
GIT_SHALLOW YES
EXCLUDE_FROM_ALL YES
OPTIONS "SNX_BUILD_NX OFF" "SNX_BUILD_GNUABI OFF" "SNX_BUILD_3DS OFF"
"SNX_BUILD_VITA OFF" "SNX_BUILD_AGB OFF" "SNX_DEPLOY OFF")
target_link_libraries(my_emulator PRIVATE ScarletNX::recompiler)
EXCLUDE_FROM_ALL builds only what the project links. The project builds with Clang, as ScarletNX does.
The archive holds the recompiler and nothing else of this tree: the native back ends,
the linkers, the code loader and the prebuilt runtime library every module gets
(snx_recompiler_core), the JIT, the AArch32 block compiler with its decoders and helpers, and what they take from
src/common (snx_recompiler_base): the A64 decoder, the function discovery, and the
host calls under them (allocation, the error line, files and folders, the clocks, the
address space). It takes no other library but the system's that the core needs: threads, dl and m
(advapi32 on Windows). The package records them. The test recompiler_symbols
links every object of the archive with those alone, so a call into another library of
this tree, or a new external library, fails it. The backend generates code for the machine it runs on, as
the scarletnx command does: build the library on the machine that will use it, or one
with the same instruction set extensions.
The archive holds machine code in every build. The rest of a build that links with ThinLTO
(SNX_LTO) compiles to LLVM bitcode, which a consumer's linker may not read. The archive,
the parts it is made of and the shared library build without it, so the programs of this tree that link those parts
get no inlining across them.
-DSNX_RECOMPILER_SHARED=ON also builds libscarletnx-recompiler.so (a DLL on
Windows), which exports only the header's functions and is linked with
ScarletNX::recompiler-shared. It compiles the backend as position-independent code.
Made from docs/dev/library.md at 69237645142c. GPL-3.0-or-later.