No More APT

This commit is contained in:
TheBrokenRail 2022-07-07 18:54:11 -04:00
parent 3937f88084
commit 126c3d618d
8 changed files with 95 additions and 125 deletions

1
.gitignore vendored
View File

@ -12,3 +12,4 @@ AppDir
*.AppImage
core*
qemu_*
.prebuilt-armhf-toolchain

View File

@ -11,9 +11,8 @@ option(MCPI_IS_APPIMAGE_BUILD "AppImage Build" FALSE)
option(MCPI_SERVER_MODE "Server Mode" FALSE)
option(MCPI_HEADLESS_MODE "Headless Mode" ${MCPI_SERVER_MODE})
# ARMHF Sysroot
option(MCPI_BUNDLE_ARMHF_SYSROOT "Whether To Include An ARMHF Sysroot" ${MCPI_IS_MIXED_BUILD})
set(MCPI_CUSTOM_BUNDLED_ARMHF_SYSROOT "" CACHE PATH "Custom Bundled ARMHF Sysroot")
# Prebuilt ARMHF Toolchain
option(MCPI_USE_PREBUILT_ARMHF_TOOLCHAIN "Whether To Use A Prebuilt ARMHF Toolchain For Building ARM Components" ${MCPI_IS_MIXED_BUILD})
# Media Layer
if(NOT MCPI_HEADLESS_MODE)
@ -92,6 +91,11 @@ if(NOT CMAKE_BUILD_TYPE)
set(CMAKE_BUILD_TYPE "Release")
endif()
# Setup Prebuilt ARMHF Toolchain
if(BUILD_ARM_COMPONENTS AND MCPI_USE_PREBUILT_ARMHF_TOOLCHAIN)
include(cmake/prebuilt-armhf-toolchain.cmake)
endif()
# Start Project
project(minecraft-pi-reborn)

View File

@ -0,0 +1,76 @@
# Locations
set(toolchain_dir "${CMAKE_CURRENT_SOURCE_DIR}/.prebuilt-armhf-toolchain")
set(sysroot_dir "${CMAKE_CURRENT_BINARY_DIR}/bundled-armhf-sysroot")
# Force Toolchain
set(CMAKE_C_COMPILER "${toolchain_dir}/bin/arm-none-linux-gnueabihf-gcc")
set(CMAKE_CXX_COMPILER "${toolchain_dir}/bin/arm-none-linux-gnueabihf-g++")
set(CMAKE_SYSTEM_NAME "Linux")
set(CMAKE_SYSTEM_PROCESSOR "arm")
unset(CMAKE_TOOLCHAIN_FILE CACHE)
# Download If Needed
if(NOT EXISTS "${CMAKE_C_COMPILER}")
# Pick URL
execute_process(COMMAND uname -m OUTPUT_VARIABLE arch OUTPUT_STRIP_TRAILING_WHITESPACE)
if(arch STREQUAL "x86_64")
set(toolchain_url "https://developer.arm.com/-/media/Files/downloads/gnu/11.2-2022.02/binrel/gcc-arm-11.2-2022.02-x86_64-arm-none-linux-gnueabihf.tar.xz")
set(toolchain_sha256 "c254f7199261fe76c32ef42187502839bda7efad0a66646cf739d074eff45fad")
elseif(arch STREQUAL "aarch64_be" OR arch STREQUAL "aarch64" OR arch STREQUAL "armv8b" OR arch STREQUAL "armv8l")
set(toolchain_url "https://developer.arm.com/-/media/Files/downloads/gnu/11.2-2022.02/binrel/gcc-arm-11.2-2022.02-aarch64-arm-none-linux-gnueabihf.tar.xz")
set(toolchain_sha256 "c5603772af016008ddacb7e475dc226d0cccdf069925dfded43e452a59774fc3")
else()
message(FATAL_ERROR "Unable To Download Prebuilt ARMHF Toolchain")
endif()
# Download
message(STATUS "Downloading Prebuilt ARMHF Toolchain...")
file(REMOVE_RECURSE "${toolchain_dir}")
include(FetchContent)
set(FETCHCONTENT_QUIET FALSE)
FetchContent_Declare(
prebuilt-armhf-toolchain
URL "${toolchain_url}"
URL_HASH "SHA256=${toolchain_sha256}"
SOURCE_DIR "${toolchain_dir}"
)
FetchContent_Populate(prebuilt-armhf-toolchain)
# Force Sysroot Rebuild
file(REMOVE_RECURSE "${sysroot_dir}")
endif()
# Build Sysroot
if(NOT EXISTS "${sysroot_dir}")
# Create Directory
file(MAKE_DIRECTORY "${sysroot_dir}")
# Copy Files From Toolchain
file(
COPY "${toolchain_dir}/arm-none-linux-gnueabihf/libc/"
DESTINATION "${sysroot_dir}"
USE_SOURCE_PERMISSIONS
FILES_MATCHING
PATTERN "*.so*"
PATTERN "*.py*" EXCLUDE
REGEX "gconv" EXCLUDE
REGEX "audit" EXCLUDE
)
# Strip Files
file(GLOB_RECURSE files LIST_DIRECTORIES FALSE "${sysroot_dir}/*")
foreach(file IN LISTS files)
execute_process(COMMAND "${toolchain_dir}/bin/arm-none-linux-gnueabihf-strip" "${file}" RESULT_VARIABLE ret)
# Check Result
if(NOT ret EQUAL 0)
# Delete Invalid Files
file(REMOVE "${file}")
endif()
endforeach()
endif()
# Install Sysroot (Skipping Empty Directories)
file(GLOB_RECURSE files LIST_DIRECTORIES FALSE RELATIVE "${sysroot_dir}" "${sysroot_dir}/*")
foreach(file IN LISTS files)
get_filename_component(parent "${file}" DIRECTORY)
install(PROGRAMS "${sysroot_dir}/${file}" DESTINATION "${MCPI_INSTALL_DIR}/sysroot/${parent}")
endforeach()

View File

@ -10,7 +10,3 @@ endif()
if(BUILD_NATIVE_COMPONENTS AND NOT MCPI_HEADLESS_MODE)
add_subdirectory(zenity)
endif()
# Sysroot
if(BUILD_ARM_COMPONENTS AND MCPI_BUNDLE_ARMHF_SYSROOT)
add_subdirectory(armhf-sysroot)
endif()

View File

@ -1,114 +0,0 @@
project(armhf-sysroot)
# Check If Using Custom Sysroot
if(MCPI_CUSTOM_BUNDLED_ARMHF_SYSROOT)
# Custom Sysroot
set(SYSROOT_DIR "${MCPI_CUSTOM_BUNDLED_ARMHF_SYSROOT}")
else()
# Download From APT
set(APT_PACKAGES "libc6" "libstdc++6")
# Copy To Binary Directory
set(APT_DIR "${CMAKE_CURRENT_BINARY_DIR}/apt")
file(MAKE_DIRECTORY "${APT_DIR}")
# Make Directories
file(MAKE_DIRECTORY "${APT_DIR}/apt.conf.d")
file(MAKE_DIRECTORY "${APT_DIR}/preferences.d")
file(MAKE_DIRECTORY "${APT_DIR}/keys")
file(MAKE_DIRECTORY "${APT_DIR}/dpkg")
file(MAKE_DIRECTORY "${APT_DIR}/archives")
file(TOUCH "${APT_DIR}/dpkg/status")
# Create APT Sources
execute_process(
COMMAND "${CMAKE_SOURCE_DIR}/scripts/tools/get-apt-sources.sh"
OUTPUT_STRIP_TRAILING_WHITESPACE
OUTPUT_VARIABLE APT_SOURCES
RESULT_VARIABLE APT_SOURCES_RESULT
)
if(NOT APT_SOURCES_RESULT EQUAL 0)
message(FATAL_ERROR "Unable To Get APT Sources For ARMHF Sysroot")
endif()
file(WRITE "${APT_DIR}/sources.list" "${APT_SOURCES}")
# Create APT Config
string(CONCAT APT_CONFIG
"Dir \"${APT_DIR}\";\n"
"Dir::State \"${APT_DIR}\";\n"
"Dir::Cache \"${APT_DIR}\";\n"
"Dir::Etc::Main \"${APT_DIR}/apt.conf\";\n"
"Dir::Etc::Parts \"${APT_DIR}/apt.conf.d\";\n"
"Dir::Etc::SourceList \"${APT_DIR}/sources.list\";\n"
"Dir::Etc::SourceListParts \"${APT_DIR}/sources.list.d\";\n"
"Dir::Etc::PreferencesParts \"${APT_DIR}/preferences.d\";\n"
"Dir::Etc::TrustedParts \"${APT_DIR}/keys\";\n"
"Dir::State::status \"${APT_DIR}/dpkg/status\";\n"
"Dir::Ignore-Files-Silently \"False\";\n"
"APT::Install-Recommends \"False\";\n"
"APT::Install-Suggests \"False\";\n"
"APT::Immediate-Configure \"False\";\n"
"APT::Architecture \"armhf\";\n"
"APT::Architectures { \"armhf\"; }\n"
"Acquire::Languages \"none\";\n"
"APT::Get::AllowUnauthenticated \"True\";\n"
"Acquire::AllowInsecureRepositories \"True\";\n"
)
file(WRITE "${APT_DIR}/apt.conf" "${APT_CONFIG}")
# Environment
set(APT_ENV
"${CMAKE_COMMAND}"
-E env
"DEBIAN_FRONTEND=noninteractive"
"APT_CONFIG=${APT_DIR}/apt.conf"
)
# Create Sysroot Directory
set(SYSROOT_DIR "${CMAKE_CURRENT_BINARY_DIR}/sysroot")
file(MAKE_DIRECTORY "${SYSROOT_DIR}")
# Download
add_custom_command(
OUTPUT "${APT_DIR}/.update-stamp"
COMMAND ${APT_ENV} apt-get update
COMMAND "${CMAKE_COMMAND}" -E touch "${APT_DIR}/.update-stamp"
VERBATIM
)
add_custom_command(
OUTPUT "${APT_DIR}/.download-stamp"
DEPENDS "${APT_DIR}/.update-stamp"
COMMAND find "${APT_DIR}/archives" -maxdepth 1 -type f -name "*.deb" -delete
COMMAND ${APT_ENV} apt-get install -y --no-install-recommends --download-only ${APT_PACKAGES}
COMMAND "${CMAKE_COMMAND}" -E touch "${APT_DIR}/.download-stamp"
VERBATIM
)
add_custom_command(
OUTPUT "${APT_DIR}/.extract-stamp"
DEPENDS "${APT_DIR}/.download-stamp"
COMMAND find "${SYSROOT_DIR}" -mindepth 1 -delete
COMMAND find "${APT_DIR}/archives" -maxdepth 1 -type f -name "*.deb" -exec dpkg -x {} "${SYSROOT_DIR}" ";"
COMMAND "${CMAKE_COMMAND}" -E touch "${APT_DIR}/.extract-stamp"
VERBATIM
)
add_custom_target(armhf-sysroot ALL DEPENDS "${APT_DIR}/.extract-stamp")
endif()
# Install
install(
DIRECTORY "${SYSROOT_DIR}/"
DESTINATION "${MCPI_INSTALL_DIR}/sysroot"
USE_SOURCE_PERMISSIONS
REGEX "usr/lib/arm-linux-gnueabihf/gconv" EXCLUDE
REGEX "usr/lib/arm-linux-gnueabihf/audit" EXCLUDE
REGEX "usr/share/man" EXCLUDE
REGEX "usr/share/doc/.*/README\..*" EXCLUDE
REGEX "usr/share/doc/.*/changelog\..*" EXCLUDE
REGEX "usr/share/doc/.*/NEWS\..*" EXCLUDE
REGEX "usr/share/doc/.*/TODO\..*" EXCLUDE
REGEX "usr/share/lintian" EXCLUDE
REGEX "usr/share/gcc" EXCLUDE
REGEX "usr/share/gdb" EXCLUDE
REGEX "usr/share/locale" EXCLUDE
REGEX "usr/share/help" EXCLUDE
REGEX "etc" EXCLUDE
)

View File

@ -292,7 +292,7 @@ void bootstrap(int argc, char *argv[]) {
// Find Linker
char *linker = NULL;
// Select Linker
#ifdef MCPI_BUNDLE_ARMHF_SYSROOT
#ifdef MCPI_USE_PREBUILT_ARMHF_TOOLCHAIN
// Use ARM Sysroot Linker
safe_asprintf(&linker, "%s/sysroot/lib/ld-linux-armhf.so.3", binary_directory);
#else
@ -358,7 +358,7 @@ void bootstrap(int argc, char *argv[]) {
safe_asprintf(&library_path, "%s/lib/arm", binary_directory);
// Add ARM Sysroot Libraries (Ensure Priority) (Ignore On Actual ARM System)
#ifdef MCPI_BUNDLE_ARMHF_SYSROOT
#ifdef MCPI_USE_PREBUILT_ARMHF_TOOLCHAIN
string_append(&library_path, ":%s/sysroot/lib:%s/sysroot/lib/arm-linux-gnueabihf:%s/sysroot/usr/lib:%s/sysroot/usr/lib/arm-linux-gnueabihf", binary_directory, binary_directory, binary_directory, binary_directory);
#endif

View File

@ -3,7 +3,7 @@
#cmakedefine MCPI_SERVER_MODE
#cmakedefine MCPI_HEADLESS_MODE
#cmakedefine MCPI_IS_APPIMAGE_BUILD
#cmakedefine MCPI_BUNDLE_ARMHF_SYSROOT
#cmakedefine MCPI_USE_PREBUILT_ARMHF_TOOLCHAIN
#cmakedefine MCPI_USE_GLES1_COMPATIBILITY_LAYER
#cmakedefine MCPI_APP_TITLE "@MCPI_APP_TITLE@"
#cmakedefine MCPI_VERSION "@MCPI_VERSION@"

View File

@ -1,4 +1,11 @@
FROM buildpack-deps:bullseye
FROM buildpack-deps:buster
# Install Updated CMakes
RUN \
echo 'deb http://deb.debian.org/debian buster-backports main' > /etc/apt/sources.list.d/backports.list && \
apt-get update && \
apt-get install --no-install-recommends -y -t buster-backports cmake && \
rm -rf /var/lib/apt/lists/*
# Install
ADD ./scripts/install-dependencies.sh /