Attempt 16k Page-Size Support

This commit is contained in:
TheBrokenRail 2025-03-21 01:06:01 -04:00
parent 14331ce871
commit de378826bf
12 changed files with 120 additions and 110 deletions

View File

@ -165,7 +165,6 @@ endif()
# Superbuild # Superbuild
if(BUILD_NATIVE_COMPONENTS) if(BUILD_NATIVE_COMPONENTS)
include(ExternalProject)
# Arguments # Arguments
set(ARM_OPTIONS "${MCPI_OPTIONS}") set(ARM_OPTIONS "${MCPI_OPTIONS}")
list(APPEND ARM_OPTIONS "-DMCPI_BUILD_MODE:STRING=arm") list(APPEND ARM_OPTIONS "-DMCPI_BUILD_MODE:STRING=arm")
@ -181,8 +180,17 @@ if(BUILD_NATIVE_COMPONENTS)
if(DEFINED ARM_TOOLCHAIN) if(DEFINED ARM_TOOLCHAIN)
list(APPEND ARM_OPTIONS "-DCMAKE_TOOLCHAIN_FILE:FILEPATH=${ARM_TOOLCHAIN}") list(APPEND ARM_OPTIONS "-DCMAKE_TOOLCHAIN_FILE:FILEPATH=${ARM_TOOLCHAIN}")
endif() endif()
# Force Rebuild If Needed
set(ARM_PREFIX "${CMAKE_CURRENT_BINARY_DIR}/arm-components")
if(DEFINED MCPI_FORCE_ARM_REBUILD)
file(REMOVE_RECURSE "${ARM_PREFIX}")
endif()
# Build # Build
include(ExternalProject)
ExternalProject_Add(arm-components ExternalProject_Add(arm-components
PREFIX "${ARM_PREFIX}"
# Source Directory # Source Directory
DOWNLOAD_COMMAND "" DOWNLOAD_COMMAND ""
SOURCE_DIR "${CMAKE_CURRENT_SOURCE_DIR}" SOURCE_DIR "${CMAKE_CURRENT_SOURCE_DIR}"
@ -198,7 +206,7 @@ if(BUILD_NATIVE_COMPONENTS)
"${CMAKE_COMMAND}" "-E" "${CMAKE_COMMAND}" "-E"
"rm" "-rf" "<INSTALL_DIR>/${MCPI_INSTALL_DIR}" "rm" "-rf" "<INSTALL_DIR>/${MCPI_INSTALL_DIR}"
COMMAND COMMAND
"${CMAKE_COMMAND}" "-E" "env" "DESTDIR=" "${CMAKE_COMMAND}" "-E" "env" "DESTDIR="
"${CMAKE_COMMAND}" "--install" "<BINARY_DIR>" "--config" "$<CONFIG>" "${CMAKE_COMMAND}" "--install" "<BINARY_DIR>" "--config" "$<CONFIG>"
# Use Terminal # Use Terminal
USES_TERMINAL_CONFIGURE TRUE USES_TERMINAL_CONFIGURE TRUE
@ -207,6 +215,7 @@ if(BUILD_NATIVE_COMPONENTS)
# Always Build # Always Build
BUILD_ALWAYS TRUE BUILD_ALWAYS TRUE
) )
# Install # Install
ExternalProject_Get_Property(arm-components INSTALL_DIR) ExternalProject_Get_Property(arm-components INSTALL_DIR)
install(DIRECTORY "${INSTALL_DIR}/${MCPI_INSTALL_DIR}/" DESTINATION "${MCPI_INSTALL_DIR}") install(DIRECTORY "${INSTALL_DIR}/${MCPI_INSTALL_DIR}/" DESTINATION "${MCPI_INSTALL_DIR}")

@ -1 +1 @@
Subproject commit 5baa6b1948aeebb5e13af31ff62dc97f00a3b71e Subproject commit 58b318e01b94529105dfe351779a9a6038aa0159

View File

@ -13,7 +13,7 @@ if(BUILD_NATIVE_COMPONENTS)
set(MCPI_USE_PREBUILT_ARMHF_TOOLCHAIN TRUE) set(MCPI_USE_PREBUILT_ARMHF_TOOLCHAIN TRUE)
endif() endif()
if(MCPI_USE_PREBUILT_ARMHF_TOOLCHAIN) if(MCPI_USE_PREBUILT_ARMHF_TOOLCHAIN)
include("${CMAKE_CURRENT_LIST_DIR}/prebuilt-armhf-toolchain.cmake") include("${CMAKE_CURRENT_LIST_DIR}/../toolchain/prebuilt/armhf-toolchain.cmake")
endif() endif()
endif() endif()

View File

@ -1,88 +0,0 @@
# Target
set(target "arm-none-linux-gnueabihf")
# Pick Archive
set(toolchain_version "13.3.rel1")
execute_process(COMMAND uname -m OUTPUT_VARIABLE arch OUTPUT_STRIP_TRAILING_WHITESPACE)
if(arch STREQUAL "x86_64")
set(toolchain_file "arm-gnu-toolchain-${toolchain_version}-x86_64-${target}.tar.xz")
elseif(arch STREQUAL "aarch64" OR arch STREQUAL "armv8b" OR arch STREQUAL "armv8l")
set(toolchain_file "arm-gnu-toolchain-${toolchain_version}-aarch64-${target}.tar.xz")
else()
message(FATAL_ERROR "Unable To Download Prebuilt ARMHF Toolchain")
endif()
# Download If Needed
include(FetchContent)
FetchContent_Declare(prebuilt-armhf-toolchain
URL "${CMAKE_CURRENT_LIST_DIR}/../../archives/${toolchain_file}"
)
FetchContent_MakeAvailable(prebuilt-armhf-toolchain)
set(toolchain_dir "${prebuilt-armhf-toolchain_SOURCE_DIR}")
# Force Toolchain
file(WRITE "${toolchain_dir}/toolchain.cmake"
"set(CMAKE_C_COMPILER \"\${CMAKE_CURRENT_LIST_DIR}/bin/${target}-gcc\")\n"
"set(CMAKE_CXX_COMPILER \"\${CMAKE_CURRENT_LIST_DIR}/bin/${target}-g++\")\n"
"set(CMAKE_SYSTEM_NAME \"Linux\")\n"
"set(CMAKE_SYSTEM_PROCESSOR \"arm\")\n"
"set(CMAKE_FIND_ROOT_PATH_MODE_PROGRAM NEVER)\n"
)
force_set(MCPI_CMAKE_TOOLCHAIN_FILE "${toolchain_dir}/toolchain.cmake" FILEPATH)
# Build Sysroot
set(sysroot_dir "${CMAKE_CURRENT_BINARY_DIR}/bundled-armhf-sysroot")
set(sysroot_dir_debug "${sysroot_dir}/debug")
set(sysroot_dir_release "${sysroot_dir}/release")
if("${toolchain_dir}/bin/${target}-gcc" IS_NEWER_THAN "${sysroot_dir}")
# Create Directory
file(REMOVE_RECURSE "${sysroot_dir}")
file(MAKE_DIRECTORY "${sysroot_dir_debug}")
file(MAKE_DIRECTORY "${sysroot_dir_release}")
# Copy Files From Toolchain
file(
COPY "${toolchain_dir}/${target}/libc/"
DESTINATION "${sysroot_dir_debug}"
USE_SOURCE_PERMISSIONS
FILES_MATCHING
PATTERN "*.so*"
)
# Delete Unneeded Files
file(REMOVE_RECURSE "${sysroot_dir_debug}/usr/lib/audit")
file(REMOVE_RECURSE "${sysroot_dir_debug}/usr/lib/gconv")
# Strip Files
file(COPY "${sysroot_dir_debug}/." DESTINATION "${sysroot_dir_release}")
file(GLOB_RECURSE files LIST_DIRECTORIES FALSE "${sysroot_dir_release}/*")
foreach(file IN LISTS files)
execute_process(
COMMAND "${toolchain_dir}/bin/${target}-strip" "${file}"
RESULT_VARIABLE ret
ERROR_QUIET
)
# Delete Invalid Files
if(NOT ret EQUAL 0)
file(REMOVE "${file}")
endif()
endforeach()
endif()
# Install Sysroot (Skipping Empty Directories)
function(install_arm_sysroot_config config)
set(dir "${sysroot_dir_${config}}")
file(GLOB_RECURSE files LIST_DIRECTORIES FALSE RELATIVE "${dir}" "${dir}/*")
foreach(file IN LISTS files)
cmake_path(GET file PARENT_PATH parent)
install(
PROGRAMS "${dir}/${file}"
DESTINATION "${MCPI_INSTALL_DIR}/sysroot/${parent}"
CONFIGURATIONS "${config}"
)
endforeach()
endfunction()
function(install_arm_sysroot)
install_arm_sysroot_config(debug)
install_arm_sysroot_config(release)
endfunction()

View File

@ -0,0 +1,34 @@
# Target
set(target "arm-linux-gnueabihf")
# Pick Archive
get_arch(arch)
set(toolchain_name "arm-toolchain-${arch}")
set(toolchain_dir "${CMAKE_CURRENT_BINARY_DIR}/${toolchain_name}")
set(toolchain_file "${CMAKE_CURRENT_LIST_DIR}/../../../archives/${toolchain_name}.tar.xz")
# Sysroot
include("${CMAKE_CURRENT_LIST_DIR}/sysroot.cmake")
# Extract If Needed
file(SHA256 "${toolchain_file}" toolchain_hash)
if(NOT (DEFINED CACHE{MCPI_TOOLCHAIN_HASH} AND toolchain_hash STREQUAL MCPI_TOOLCHAIN_HASH))
force_set(MCPI_TOOLCHAIN_HASH "${toolchain_hash}" INTERNAL)
message(STATUS "Extracting Toolchain...")
file(REMOVE_RECURSE "${toolchain_dir}")
file(ARCHIVE_EXTRACT INPUT "${toolchain_file}" DESTINATION "${CMAKE_CURRENT_BINARY_DIR}" TOUCH)
# Force Toolchain
file(WRITE "${toolchain_dir}/toolchain.cmake"
"set(CMAKE_C_COMPILER \"\${CMAKE_CURRENT_LIST_DIR}/bin/${target}-gcc\")\n"
"set(CMAKE_CXX_COMPILER \"\${CMAKE_CURRENT_LIST_DIR}/bin/${target}-g++\")\n"
"set(CMAKE_SYSTEM_NAME \"Linux\")\n"
"set(CMAKE_SYSTEM_PROCESSOR \"arm\")\n"
"set(CMAKE_FIND_ROOT_PATH_MODE_PROGRAM NEVER)\n"
)
force_set(MCPI_CMAKE_TOOLCHAIN_FILE "${toolchain_dir}/toolchain.cmake" FILEPATH)
set(MCPI_FORCE_ARM_REBUILD TRUE)
# Sysroot
build_sysroot()
endif()

View File

@ -0,0 +1,60 @@
# Directories
set(sysroot_dir "${CMAKE_CURRENT_BINARY_DIR}/bundled-armhf-sysroot")
set(sysroot_dir_debug "${sysroot_dir}/debug")
set(sysroot_dir_release "${sysroot_dir}/release")
# Build Sysroot
function(_strip file)
execute_process(
COMMAND "${toolchain_dir}/bin/${target}-strip" "${file}"
RESULT_VARIABLE ret
ERROR_QUIET
)
# Delete Invalid Files
if(NOT ret EQUAL 0)
file(REMOVE "${file}")
endif()
endfunction()
function(build_sysroot)
# Create Directory
file(REMOVE_RECURSE "${sysroot_dir}")
# Copy Files From Toolchain
file(MAKE_DIRECTORY "${sysroot_dir_debug}")
file(COPY "${toolchain_dir}/${target}/sysroot/"
DESTINATION "${sysroot_dir_debug}"
USE_SOURCE_PERMISSIONS
FILES_MATCHING
PATTERN "*.so*"
)
# Delete Unneeded Files
file(REMOVE_RECURSE "${sysroot_dir_debug}/usr/lib/audit")
file(REMOVE_RECURSE "${sysroot_dir_debug}/usr/lib/gconv")
# Strip Files
file(MAKE_DIRECTORY "${sysroot_dir_release}")
file(COPY "${sysroot_dir_debug}/." DESTINATION "${sysroot_dir_release}")
file(GLOB_RECURSE files LIST_DIRECTORIES FALSE "${sysroot_dir_release}/*")
foreach(file IN LISTS files)
_strip("${file}")
endforeach()
endfunction()
# Install Sysroot (Skipping Empty Directories)
function(_install_arm_sysroot_config config)
set(dir "${sysroot_dir_${config}}")
file(GLOB_RECURSE files LIST_DIRECTORIES FALSE RELATIVE "${dir}" "${dir}/*")
foreach(file IN LISTS files)
cmake_path(GET file PARENT_PATH parent)
install(
PROGRAMS "${dir}/${file}"
DESTINATION "${MCPI_INSTALL_DIR}/sysroot/${parent}"
CONFIGURATIONS "${config}"
)
endforeach()
endfunction()
function(install_arm_sysroot)
_install_arm_sysroot_config(debug)
_install_arm_sysroot_config(release)
endfunction()

View File

@ -104,4 +104,13 @@ function(safe_download name url out)
else() else()
message(STATUS "Downloaded ${name}: ${out}") message(STATUS "Downloaded ${name}: ${out}")
endif() endif()
endfunction()
# Get Architecture
function(get_arch var)
execute_process(COMMAND uname -m OUTPUT_VARIABLE arch OUTPUT_STRIP_TRAILING_WHITESPACE)
if(arch STREQUAL "armv8b" OR arch STREQUAL "armv8l")
set(arch "aarch64")
endif()
set("${var}" "${arch}" PARENT_SCOPE)
endfunction() endfunction()

View File

@ -11,19 +11,11 @@
#define MCPI_BINARY "minecraft-pi" #define MCPI_BINARY "minecraft-pi"
#define REQUIRED_PAGE_SIZE 4096
// Bootstrap // Bootstrap
void bootstrap(const options_t &options) { void bootstrap() {
// Debug Information // Debug Information
print_debug_information(); print_debug_information();
// Check Page Size
const long page_size = sysconf(_SC_PAGESIZE);
if (page_size != REQUIRED_PAGE_SIZE) {
CONDITIONAL_ERR(!options.skip_pagesize_check, "Invalid page size! A page size of %ld bytes is required, but the system size is %ld bytes.", (long) REQUIRED_PAGE_SIZE, page_size);
}
// Get Binary Directory // Get Binary Directory
const std::string binary_directory = get_binary_directory(); const std::string binary_directory = get_binary_directory();
DEBUG("Binary Directory: %s", binary_directory.c_str()); DEBUG("Binary Directory: %s", binary_directory.c_str());

View File

@ -3,11 +3,9 @@
#include <string> #include <string>
#include <vector> #include <vector>
#include "../options/parser.h"
#define MCPI_PATCHED_DIR "/tmp/.minecraft-pi-patched" #define MCPI_PATCHED_DIR "/tmp/.minecraft-pi-patched"
void bootstrap(const options_t &options); void bootstrap();
// Debugging // Debugging
void print_debug_information(); void print_debug_information();
// Mods // Mods

View File

@ -83,7 +83,7 @@ static void start_game(const options_t &options) {
} }
// Bootstrap // Bootstrap
bootstrap(options); bootstrap();
} }
// Main // Main

View File

@ -10,5 +10,4 @@ OPTION(only_generate, "only-generate", -8, "Generate World And Exit (Server-Mode
OPTION(force_headless, "force-headless", -9, "Force Disable Game Rendering") OPTION(force_headless, "force-headless", -9, "Force Disable Game Rendering")
OPTION(force_non_headless, "force-non-headless", -10, "Force Enable Game Rendering") OPTION(force_non_headless, "force-non-headless", -10, "Force Enable Game Rendering")
OPTION(server_mode, "server", -11, "Run In Server-Mode") OPTION(server_mode, "server", -11, "Run In Server-Mode")
OPTION(skip_pagesize_check, "skip-pagesize-check", -12, "Skip Page-Size Check (Not Recommended)")
OPTION(run_update, "update", -13, "Run Updater (If Available)") OPTION(run_update, "update", -13, "Run Updater (If Available)")

View File

@ -29,12 +29,9 @@ FetchContent_MakeAvailable(ninja)
install(PROGRAMS "${ninja_SOURCE_DIR}/misc/jobserver_pool.py" TYPE BIN) install(PROGRAMS "${ninja_SOURCE_DIR}/misc/jobserver_pool.py" TYPE BIN)
# Download AppImageTool # Download AppImageTool
execute_process(COMMAND uname -m OUTPUT_VARIABLE ARCH OUTPUT_STRIP_TRAILING_WHITESPACE)
if(ARCH STREQUAL "armv8b" OR ARCH STREQUAL "armv8l")
set(ARCH "aarch64")
endif()
set(APPIMAGETOOL_NAME "appimagetool") set(APPIMAGETOOL_NAME "appimagetool")
set(APPIMAGETOOL_BIN "${CMAKE_CURRENT_BINARY_DIR}/${APPIMAGETOOL_NAME}.AppImage") set(APPIMAGETOOL_BIN "${CMAKE_CURRENT_BINARY_DIR}/${APPIMAGETOOL_NAME}.AppImage")
get_arch(ARCH)
safe_download( safe_download(
"AppImageTool" "AppImageTool"
"https://github.com/AppImage/appimagetool/releases/download/${APPIMAGETOOL_VERSION}/appimagetool-${ARCH}.AppImage" "https://github.com/AppImage/appimagetool/releases/download/${APPIMAGETOOL_VERSION}/appimagetool-${ARCH}.AppImage"