Skip to content
This repository has been archived by the owner on Aug 4, 2024. It is now read-only.

Commit

Permalink
UGLY HACK: use nightly Rust features on stable channel
Browse files Browse the repository at this point in the history
Signed-off-by: Ookiineko <[email protected]>
  • Loading branch information
Ookiineko committed Dec 11, 2023
1 parent 2e910b9 commit 228e319
Show file tree
Hide file tree
Showing 9 changed files with 111 additions and 121 deletions.
64 changes: 17 additions & 47 deletions .github/workflows/ci.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -75,27 +75,25 @@ jobs:
tag: "jammy"
note: "glibc-x86_64-static"
cmake_flag: "-DPREFER_STATIC_LINKING=ON"
rust_target: "x86_64-unknown-linux-gnu"
dpkg_arch: "amd64"
extra_patches: "patches-contrib/Magisk/0021-workaround-revert-extract_if-to-drain_filter-rename.patch"
upload: "yes"

- os: "ubuntu"
tag: "jammy"
note: "glibc-i368-static"
cmake_flag: "-DPREFER_STATIC_LINKING=ON"
rust_target: "i686-unknown-linux-gnu"
dpkg_arch: "i386"
extra_patches: "patches-contrib/Magisk/0021-workaround-revert-extract_if-to-drain_filter-rename.patch"
upload: "yes"

- os: "alpine"
tag: "edge"
note: "musl-x86_64"
rust_target: "x86_64-unknown-linux-musl"

- os: "archlinux"
tag: "latest"
note: "glibc-x86_64"
rust_target: "x86_64-unknown-linux-gnu"

container:
image: ${{ matrix.os }}:${{ matrix.tag }}
Expand All @@ -122,10 +120,11 @@ jobs:
_arch=${{ matrix.dpkg_arch }}
dpkg --add-architecture $_arch
apt update
DEBIAN_FRONTEND=noninteractive apt install -y curl tar patch file libc6-dev:$_arch \
binutils:$_arch liblzma-dev:$_arch liblz4-dev:$_arch libbz2-dev:$_arch \
zlib1g-dev:$_arch pkg-config:$_arch clang-15:$_arch libc++-15-dev:$_arch \
libc++abi-15-dev:$_arch cmake:$_arch ninja-build:$_arch libbsd-dev:$_arch
DEBIAN_FRONTEND=noninteractive apt install -y curl tar patch file python3 \
libc6-dev:$_arch binutils:$_arch liblzma-dev:$_arch liblz4-dev:$_arch \
libbz2-dev:$_arch zlib1g-dev:$_arch pkg-config:$_arch clang-15:$_arch \
libc++-15-dev:$_arch libc++abi-15-dev:$_arch cmake:$_arch \
ninja-build:$_arch libbsd-dev:$_arch rustc:$_arch cargo:$_arch
unset _arch
ln -s $(which clang-15) $(dirname $(which clang-15))/clang
ln -s $(which clang++-15) $(dirname $(which clang-15))/clang++
Expand All @@ -134,23 +133,15 @@ jobs:
if: matrix.os == 'alpine'
run: |
apk update
apk add build-base curl file xz-dev lz4-dev bzip2-dev zlib-dev \
pkgconf clang libc++-dev cmake samurai libbsd-dev
apk add build-base curl file xz-dev lz4-dev bzip2-dev zlib-dev python3 \
pkgconf clang libc++-dev cmake samurai libbsd-dev rust cargo
- name: Prepare (archlinux)
if: matrix.os == 'archlinux'
run: |
pacman -Syu --noconfirm
pacman -S --noconfirm --needed curl file base-devel xz lz4 bzip2 \
zlib pkgconf clang libc++ cmake ninja libbsd
- name: Prepare (Rust)
run: |
curl https://sh.rustup.rs -sSf | sh -s -- -y \
--default-toolchain nightly \
--default-host ${{ matrix.rust_target }}
. "$HOME/.cargo/env"
rustup component add rust-src
pacman -S --noconfirm --needed curl file base-devel xz lz4 bzip2 python \
zlib pkgconf clang libc++ cmake ninja libbsd rust
- name: Build
run: |
Expand All @@ -159,8 +150,10 @@ jobs:
cd magiskboot_*-src/
echo -e "\n### patch source ###\n"
./scripts/apply_patches.py ${{ matrix.extra_patches }}
echo -e "\n### configure ###\n"
. "$HOME/.cargo/env"
cmake -G Ninja -B build -DCMAKE_BUILD_TYPE=Release ${{ matrix.cmake_flag }}
echo -e "\n### make ###\n"
Expand Down Expand Up @@ -202,13 +195,7 @@ jobs:
- name: Prepare
run: |
brew install --overwrite coreutils file xz lz4 \
bzip2 zlib pkg-config cmake ninja rustup-init
- name: Prepare (Rust)
run: |
rustup-init -y --default-toolchain nightly
. "$HOME/.cargo/env"
rustup component add rust-src
bzip2 zlib pkg-config cmake ninja rust
- name: Fix up Rust
if: matrix.os_release == 13
Expand All @@ -223,7 +210,6 @@ jobs:
cd magiskboot_*-src/
echo -e "\n### configure ###\n"
. "$HOME/.cargo/env"
cmake -G Ninja -B build -DCMAKE_BUILD_TYPE=Release \
-DPREFER_STATIC_LINKING=ON
Expand Down Expand Up @@ -253,23 +239,18 @@ jobs:
include:
- msystem: CLANG32
note: "ucrt-i686-standalone"
host_rust_target: "i686-pc-windows-gnu"
upload: "yes"
- msystem: MINGW32
note: "msvcrt-i686-standalone"
host_rust_target: "i686-pc-windows-gnu"
upload: "yes"
- msystem: CLANG64
note: "ucrt-x86_64-standalone"
host_rust_target: "x86_64-pc-windows-gnu"
upload: "yes"
- msystem: MINGW64
note: "msvcrt-x86_64-standalone"
host_rust_target: "x86_64-pc-windows-gnu"
upload: "yes"
- msystem: UCRT64
note: "ucrt-x86_64-standalone"
host_rust_target: "x86_64-pc-windows-gnu"
env:
MSYS: "winsymlinks:native"
MAGISKBOOT_WINSUP_NOCASE: 1
Expand All @@ -290,18 +271,8 @@ jobs:
install: >-
base-devel file
pacboy: >-
xz:p lz4:p bzip2:p zlib:p pkgconf:p
clang:p lld:p cmake:p libc++:p ninja:p
- name: Prepare (Rust)
shell: msys2 {0}
run: |
curl https://sh.rustup.rs -sSf | sh -s -- -y \
--default-toolchain nightly \
--default-host ${{ matrix.host_rust_target }}
echo 'export PATH=$(cygpath ${USERPROFILE}\\.cargo\\bin):$PATH' > $(cygpath $USERPROFILE)/.cargo/env
. "$(cygpath $USERPROFILE)/.cargo/env"
rustup component add rust-src
xz:p lz4:p bzip2:p zlib:p pkgconf:p clang:p
lld:p cmake:p libc++:p ninja:p rust:p
- name: Build
shell: msys2 {0}
Expand All @@ -312,7 +283,6 @@ jobs:
cd magiskboot_*-src/
echo -e "\n### configure ###\n"
. "$(cygpath $USERPROFILE)/.cargo/env"
cmake -G Ninja -B build -DCMAKE_BUILD_TYPE=Release \
-DPREFER_STATIC_LINKING=ON
Expand Down
2 changes: 0 additions & 2 deletions CMakeLists.compat.txt
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,6 @@ if (NOT APPLE)
set(CMAKE_CXX_FLAGS_MINSIZEREL "${CMAKE_CXX_FLAGS_MINSIZEREL} -fdata-sections -ffunction-sections")
set(CMAKE_EXE_LINKER_FLAGS_RELEASE "${CMAKE_EXE_LINKER_FLAGS_RELEASE} -Wl,--gc-sections -s")
set(CMAKE_EXE_LINKER_FLAGS_MINSIZEREL "${CMAKE_EXE_LINKER_FLAGS_MINSIZEREL} -Wl,--gc-sections -s")

set(CARGO_FLAGS ${CARGO_FLAGS} -Z build-std=std,panic_abort -Z build-std-features=panic_immediate_abort)
endif()

if (NOT CYGWIN)
Expand Down
3 changes: 2 additions & 1 deletion CMakeLists.lib.txt
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,8 @@ if (EXISTS ${CMAKE_CURRENT_SOURCE_DIR}/vendor/Magisk/native/src/Cargo.toml)
${CMAKE_CURRENT_SOURCE_DIR}/vendor/Magisk/native/src/boot/boot-rs.hpp
${CMAKE_CURRENT_SOURCE_DIR}/vendor/Magisk/native/src/base/base-rs.cpp
${CMAKE_CURRENT_SOURCE_DIR}/vendor/Magisk/native/src/boot/boot-rs.cpp
COMMAND ${CMAKE_COMMAND} -E env CXXBRIDGE_GEN_TARGET_OS=${CXXBRIDGE_GEN_TARGET_OS} RUSTFLAGS=${RUSTFLAGS} CARGO_TARGET_DIR="${CMAKE_CURRENT_BINARY_DIR}/libmagiskboot_target" ${CARGO_EXECUTABLE} build --target ${RUSTC_TARGET} -p magiskboot ${CARGO_FLAGS}
COMMAND ${CMAKE_COMMAND} -E remove -f ${CMAKE_CURRENT_SOURCE_DIR}/vendor/Magisk/native/src/.cargo/config.toml
COMMAND ${CMAKE_COMMAND} -E env CXXBRIDGE_GEN_TARGET_OS=${CXXBRIDGE_GEN_TARGET_OS} RUSTFLAGS=${RUSTFLAGS} CARGO_TARGET_DIR="${CMAKE_CURRENT_BINARY_DIR}/libmagiskboot_target" RUSTC_BOOTSTRAP=winsup,base,magiskboot ${CARGO_EXECUTABLE} build --target ${RUSTC_TARGET} -p magiskboot ${CARGO_FLAGS}
COMMAND ${CMAKE_COMMAND} -E copy_if_different ${CMAKE_CURRENT_BINARY_DIR}/libmagiskboot_target/${RUSTC_TARGET}/${CARGO_OUT}/libmagiskboot.a ${CMAKE_CURRENT_BINARY_DIR}/libmagiskboot-rs.a
COMMENT "Building Rust static library libmagiskboot-rs.a"
WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}/vendor/Magisk/native/src
Expand Down
1 change: 0 additions & 1 deletion CMakeLists.magiskboot.txt
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ add_library(libbase STATIC
vendor/Magisk/native/src/base/misc.cpp
vendor/Magisk/native/src/base/logging.cpp
vendor/Magisk/native/src/base/stream.cpp
vendor/Magisk/native/src/base/new.cpp
vendor/Magisk/native/src/base/base-rs.cpp
vendor/Magisk/native/src/external/cxx-rs/src/cxx.cc)
target_compile_definitions(libbase PRIVATE -DRUST_CXX_NO_EXCEPTIONS)
Expand Down
23 changes: 4 additions & 19 deletions CMakeLists.rust.txt
Original file line number Diff line number Diff line change
Expand Up @@ -14,34 +14,19 @@ foreach(RUSTC_OUTPUT_LINE ${RUSTC_OUTPUT})
if (RUSTC_OUTPUT_LINE MATCHES "^rustc[ \t]+")
string(REGEX MATCH "[0-9]+\\.[0-9]+\\.[0-9]+" RUSTC_VERSION ${RUSTC_OUTPUT_LINE})
elseif (RUSTC_OUTPUT_LINE MATCHES "^host:[ \t]+")
string(REGEX REPLACE "^host:[ \t]+" "" HOST_RUSTC_TARGET ${RUSTC_OUTPUT_LINE})
string(REGEX REPLACE "^host:[ \t]+" "" RUSTC_TARGET ${RUSTC_OUTPUT_LINE})
endif()
endif()
endforeach()
if (NOT DEFINED RUSTC_VERSION)
set(RUSTC_VERSION "unknown")
endif()
message(STATUS "Found rustc: ${RUSTC_EXECUTABLE} (version ${RUSTC_VERSION})")
if (DEFINED HOST_RUSTC_TARGET)
message(STATUS "Found Rust host target: ${HOST_RUSTC_TARGET}")
if (DEFINED RUSTC_TARGET)
message(STATUS "Found Rust target: ${RUSTC_TARGET}")
else()
message(FATAL_ERROR "Cannot get host Rust target")
message(FATAL_ERROR "Cannot get Rust target")
endif()
if (WIN32)
if (CMAKE_SYSTEM_PROCESSOR STREQUAL "ARM64")
if (USE_UCRT)
set(RUSTC_TARGET "aarch64-pc-windows-gnullvm")
else()
message(WARNING "non-UCRT Windows on ARM target with GNU ABI is not yet supported by Rust")
endif()
elseif (USE_UCRT)
set(RUSTC_TARGET "${HOST_RUSTC_TARGET}llvm")
endif()
endif()
if (NOT DEFINED RUSTC_TARGET)
set(RUSTC_TARGET "${HOST_RUSTC_TARGET}")
endif()
message(STATUS "Using Rust target: ${RUSTC_TARGET}")
find_program(CARGO_EXECUTABLE cargo REQUIRED)
execute_process(
COMMAND ${CARGO_EXECUTABLE} -V
Expand Down
13 changes: 0 additions & 13 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -50,19 +50,6 @@ set(RUSTFLAGS -Clinker-plugin-lto)
endif() # USE_LTO_LINKER_PLUGIN
endif() # NO_TARGETS_OR_DEPS

include(ProcessorCount)
ProcessorCount(N)

if(N GREATER 8)
set(N 8)
endif()

if (NOT N EQUAL 0)
list(APPEND RUSTFLAGS -Zthreads=${N})
endif()

string(REPLACE ";" " " RUSTFLAGS "${RUSTFLAGS}")

add_compile_options(-U_FORTIFY_SOURCE)

if (NOT NO_TARGETS_OR_DEPS)
Expand Down
Loading

0 comments on commit 228e319

Please sign in to comment.