Hmm
This commit is contained in:
parent
940e309e9c
commit
f5e2f48c64
150
packages/CMakeLists.txt.static
Normal file
150
packages/CMakeLists.txt.static
Normal file
@ -0,0 +1,150 @@
|
|||||||
|
cmake_minimum_required(VERSION 3.10)
|
||||||
|
project(dropshell VERSION 1.0.0 LANGUAGES CXX)
|
||||||
|
|
||||||
|
set(CMAKE_CXX_STANDARD 17)
|
||||||
|
set(CMAKE_CXX_STANDARD_REQUIRED ON)
|
||||||
|
|
||||||
|
# Force static linking
|
||||||
|
set(CMAKE_EXE_LINKER_FLAGS "-static")
|
||||||
|
set(CMAKE_FIND_LIBRARY_SUFFIXES ".a")
|
||||||
|
set(BUILD_SHARED_LIBS OFF)
|
||||||
|
|
||||||
|
# Set default build type to Release if not specified
|
||||||
|
if(NOT CMAKE_BUILD_TYPE)
|
||||||
|
set(CMAKE_BUILD_TYPE "Release" CACHE STRING "Choose the type of build (Debug or Release)" FORCE)
|
||||||
|
endif()
|
||||||
|
|
||||||
|
# Configure build-specific compiler flags
|
||||||
|
set(CMAKE_CXX_FLAGS_DEBUG "${CMAKE_CXX_FLAGS_DEBUG} -g")
|
||||||
|
set(CMAKE_CXX_FLAGS_RELEASE "${CMAKE_CXX_FLAGS_RELEASE} -O3 -DNDEBUG")
|
||||||
|
|
||||||
|
# Configure version information
|
||||||
|
string(TIMESTAMP CURRENT_YEAR "%Y")
|
||||||
|
string(TIMESTAMP CURRENT_MONTH "%m")
|
||||||
|
string(TIMESTAMP CURRENT_DAY "%d")
|
||||||
|
set(PROJECT_VERSION "${CURRENT_YEAR}.${CURRENT_MONTH}.${CURRENT_DAY}")
|
||||||
|
string(TIMESTAMP RELEASE_DATE "%Y-%m-%d")
|
||||||
|
|
||||||
|
# Configure version.hpp file
|
||||||
|
configure_file(
|
||||||
|
"${CMAKE_CURRENT_SOURCE_DIR}/src/version.hpp.in"
|
||||||
|
"${CMAKE_CURRENT_BINARY_DIR}/src/version.hpp"
|
||||||
|
@ONLY
|
||||||
|
)
|
||||||
|
|
||||||
|
# Set CMAKE_MODULE_PATH to include our custom find modules
|
||||||
|
set(CMAKE_MODULE_PATH ${CMAKE_MODULE_PATH} ${CMAKE_CURRENT_SOURCE_DIR}/cmake)
|
||||||
|
|
||||||
|
# Find required packages
|
||||||
|
find_package(Threads REQUIRED)
|
||||||
|
find_package(TBB REQUIRED)
|
||||||
|
find_package(xxHash REQUIRED)
|
||||||
|
|
||||||
|
# Auto-detect source files
|
||||||
|
file(GLOB_RECURSE SOURCES "src/*.cpp")
|
||||||
|
file(GLOB_RECURSE HEADERS "src/*.hpp")
|
||||||
|
|
||||||
|
# Add executable
|
||||||
|
add_executable(dropshell ${SOURCES})
|
||||||
|
|
||||||
|
# Set include directories
|
||||||
|
target_include_directories(dropshell PRIVATE
|
||||||
|
src
|
||||||
|
${CMAKE_CURRENT_BINARY_DIR}/src
|
||||||
|
${xxHash_INCLUDE_DIRS}
|
||||||
|
)
|
||||||
|
|
||||||
|
# Link libraries statically
|
||||||
|
target_link_libraries(dropshell PRIVATE
|
||||||
|
-Wl,--whole-archive
|
||||||
|
TBB::tbb
|
||||||
|
${xxHash_LIBRARIES}
|
||||||
|
Threads::Threads
|
||||||
|
-Wl,--no-whole-archive
|
||||||
|
-static-libgcc
|
||||||
|
-static-libstdc++
|
||||||
|
)
|
||||||
|
|
||||||
|
# Install targets
|
||||||
|
install(TARGETS dropshell
|
||||||
|
RUNTIME DESTINATION bin
|
||||||
|
)
|
||||||
|
|
||||||
|
# Create symbolic link 'ds' pointing to 'dropshell'
|
||||||
|
install(CODE "
|
||||||
|
message(STATUS \"Checking if 'ds' command already exists...\")
|
||||||
|
execute_process(
|
||||||
|
COMMAND which ds
|
||||||
|
RESULT_VARIABLE DS_NOT_EXISTS
|
||||||
|
OUTPUT_QUIET
|
||||||
|
ERROR_QUIET
|
||||||
|
)
|
||||||
|
if(DS_NOT_EXISTS)
|
||||||
|
message(STATUS \"Command 'ds' does not exist. Creating symlink.\")
|
||||||
|
execute_process(
|
||||||
|
COMMAND ${CMAKE_COMMAND} -E create_symlink
|
||||||
|
\${CMAKE_INSTALL_PREFIX}/bin/dropshell
|
||||||
|
\${CMAKE_INSTALL_PREFIX}/bin/ds
|
||||||
|
)
|
||||||
|
else()
|
||||||
|
message(STATUS \"Command 'ds' already exists. Skipping symlink creation.\")
|
||||||
|
endif()
|
||||||
|
")
|
||||||
|
|
||||||
|
# Install completion script
|
||||||
|
install(FILES src/dropshell-completion.bash
|
||||||
|
DESTINATION /etc/bash_completion.d
|
||||||
|
RENAME dropshell
|
||||||
|
)
|
||||||
|
|
||||||
|
# Create a symlink for the completion script to work with 'ds' command
|
||||||
|
install(CODE "
|
||||||
|
# First check if 'ds' command exists after our installation
|
||||||
|
execute_process(
|
||||||
|
COMMAND which ds
|
||||||
|
RESULT_VARIABLE DS_NOT_EXISTS
|
||||||
|
OUTPUT_VARIABLE DS_PATH
|
||||||
|
ERROR_QUIET
|
||||||
|
OUTPUT_STRIP_TRAILING_WHITESPACE
|
||||||
|
)
|
||||||
|
|
||||||
|
# Only proceed if 'ds' exists
|
||||||
|
if(NOT DS_NOT_EXISTS)
|
||||||
|
# Check if 'ds' is a symlink pointing to dropshell
|
||||||
|
execute_process(
|
||||||
|
COMMAND readlink -f \${DS_PATH}
|
||||||
|
RESULT_VARIABLE READLINK_FAILED
|
||||||
|
OUTPUT_VARIABLE REAL_PATH
|
||||||
|
ERROR_QUIET
|
||||||
|
OUTPUT_STRIP_TRAILING_WHITESPACE
|
||||||
|
)
|
||||||
|
|
||||||
|
# Get the path to our dropshell binary
|
||||||
|
set(DROPSHELL_PATH \${CMAKE_INSTALL_PREFIX}/bin/dropshell)
|
||||||
|
|
||||||
|
# Check if the real path is our dropshell binary
|
||||||
|
if(NOT READLINK_FAILED AND \"\${REAL_PATH}\" STREQUAL \"\${DROPSHELL_PATH}\")
|
||||||
|
message(STATUS \"Command 'ds' exists and points to dropshell. Creating completion script symlink.\")
|
||||||
|
execute_process(
|
||||||
|
COMMAND ${CMAKE_COMMAND} -E create_symlink
|
||||||
|
/etc/bash_completion.d/dropshell
|
||||||
|
/etc/bash_completion.d/ds
|
||||||
|
)
|
||||||
|
else()
|
||||||
|
message(STATUS \"Command 'ds' exists but doesn't point to dropshell. Skipping completion symlink.\")
|
||||||
|
endif()
|
||||||
|
else()
|
||||||
|
message(STATUS \"Command 'ds' not found. Skipping completion symlink.\")
|
||||||
|
endif()
|
||||||
|
")
|
||||||
|
|
||||||
|
# Create pre-install script to clean old templates
|
||||||
|
install(CODE "
|
||||||
|
message(STATUS \"Removing old template files...\")
|
||||||
|
execute_process(COMMAND rm -rf /opt/dropshell/templates)
|
||||||
|
")
|
||||||
|
|
||||||
|
# Install templates with pre-install script
|
||||||
|
install(DIRECTORY templates/
|
||||||
|
DESTINATION /opt/dropshell/templates
|
||||||
|
)
|
@ -14,13 +14,66 @@ RUN apt-get update && \
|
|||||||
cmake \
|
cmake \
|
||||||
make \
|
make \
|
||||||
g++ \
|
g++ \
|
||||||
musl-tools \
|
wget \
|
||||||
|
git \
|
||||||
g++-aarch64-linux-gnu \
|
g++-aarch64-linux-gnu \
|
||||||
crossbuild-essential-arm64 \
|
crossbuild-essential-arm64 \
|
||||||
libtbb-dev \
|
libtbb-dev \
|
||||||
libxxhash-dev \
|
libtbb2 \
|
||||||
libtbb-dev:arm64 \
|
libtbb-dev:arm64 \
|
||||||
libxxhash-dev:arm64 && \
|
libtbb2:arm64 \
|
||||||
|
libxxhash-dev \
|
||||||
|
libxxhash0 \
|
||||||
|
libxxhash-dev:arm64 \
|
||||||
|
libxxhash0:arm64 && \
|
||||||
rm -rf /var/lib/apt/lists/*
|
rm -rf /var/lib/apt/lists/*
|
||||||
|
|
||||||
|
# Build musl cross compilers with C++ support
|
||||||
|
RUN git clone https://github.com/richfelker/musl-cross-make.git && \
|
||||||
|
cd musl-cross-make && \
|
||||||
|
echo "TARGET = x86_64-linux-musl" > config.mak && \
|
||||||
|
echo "OUTPUT = /opt/cross" >> config.mak && \
|
||||||
|
echo "COMMON_CONFIG += CFLAGS=\"-g0 -O2\" CXXFLAGS=\"-g0 -O2\" LDFLAGS=\"-s\"" >> config.mak && \
|
||||||
|
echo "GCC_CONFIG += --enable-languages=c,c++" >> config.mak && \
|
||||||
|
make -j$(nproc) && \
|
||||||
|
make install && \
|
||||||
|
cd .. && \
|
||||||
|
rm -rf musl-cross-make
|
||||||
|
|
||||||
|
# Build arm64 musl cross compiler
|
||||||
|
RUN git clone https://github.com/richfelker/musl-cross-make.git && \
|
||||||
|
cd musl-cross-make && \
|
||||||
|
echo "TARGET = aarch64-linux-musl" > config.mak && \
|
||||||
|
echo "OUTPUT = /opt/cross" >> config.mak && \
|
||||||
|
echo "COMMON_CONFIG += CFLAGS=\"-g0 -O2\" CXXFLAGS=\"-g0 -O2\" LDFLAGS=\"-s\"" >> config.mak && \
|
||||||
|
echo "GCC_CONFIG += --enable-languages=c,c++" >> config.mak && \
|
||||||
|
make -j$(nproc) && \
|
||||||
|
make install && \
|
||||||
|
cd .. && \
|
||||||
|
rm -rf musl-cross-make
|
||||||
|
|
||||||
|
# Add cross compilers to PATH
|
||||||
|
ENV PATH="/opt/cross/bin:${PATH}"
|
||||||
|
|
||||||
|
# Install TBB from source for musl compatibility
|
||||||
|
RUN wget https://github.com/oneapi-src/oneTBB/archive/refs/tags/v2021.10.0.tar.gz && \
|
||||||
|
tar xf v2021.10.0.tar.gz && \
|
||||||
|
cd oneTBB-2021.10.0 && \
|
||||||
|
mkdir build && \
|
||||||
|
cd build && \
|
||||||
|
cmake -DCMAKE_BUILD_TYPE=Release -DBUILD_SHARED_LIBS=OFF .. && \
|
||||||
|
make -j$(nproc) && \
|
||||||
|
make install && \
|
||||||
|
cd ../.. && \
|
||||||
|
rm -rf oneTBB-2021.10.0 v2021.10.0.tar.gz
|
||||||
|
|
||||||
|
# Install xxHash from source for musl compatibility
|
||||||
|
RUN wget https://github.com/Cyan4973/xxHash/archive/refs/tags/v0.8.2.tar.gz && \
|
||||||
|
tar xf v0.8.2.tar.gz && \
|
||||||
|
cd xxHash-0.8.2 && \
|
||||||
|
make -j$(nproc) && \
|
||||||
|
make install && \
|
||||||
|
cd .. && \
|
||||||
|
rm -rf xxHash-0.8.2 v0.8.2.tar.gz
|
||||||
|
|
||||||
WORKDIR /src
|
WORKDIR /src
|
@ -14,33 +14,40 @@ GROUP_ID=$(id -g)
|
|||||||
# Create output directory if it doesn't exist
|
# Create output directory if it doesn't exist
|
||||||
mkdir -p output
|
mkdir -p output
|
||||||
|
|
||||||
# Build Docker image if it doesn't exist
|
# Build Docker image
|
||||||
if ! docker image inspect dropshell-builder:latest >/dev/null 2>&1; then
|
echo "Building builder image..."
|
||||||
echo "Building builder image..."
|
docker build -t dropshell-builder:latest .
|
||||||
docker build -t dropshell-builder:latest .
|
|
||||||
fi
|
|
||||||
|
|
||||||
|
echo "Building x86_64 executable..."
|
||||||
# Build x86_64 executable
|
# Build x86_64 executable
|
||||||
docker run --rm -v "$(pwd)/..:/src" -u root dropshell-builder:latest bash -c '
|
docker run --rm -v "$(pwd)/..:/src" -u root dropshell-builder:latest bash -c ' \
|
||||||
rm -rf build && \
|
rm -rf build && \
|
||||||
mkdir -p build && \
|
mkdir -p build && \
|
||||||
cd build && \
|
cd build && \
|
||||||
cmake -DCMAKE_BUILD_TYPE=Release .. && \
|
cp ../packages/CMakeLists.txt.static ../CMakeLists.txt && \
|
||||||
|
MUSL_GPP=$(which musl-g++) && \
|
||||||
|
cmake -DCMAKE_BUILD_TYPE=Release \
|
||||||
|
-DCMAKE_CXX_COMPILER=${MUSL_GPP} \
|
||||||
|
-DCMAKE_CXX_FLAGS="-static" .. && \
|
||||||
make && \
|
make && \
|
||||||
cp dropshell ../packages/output/dropshell-x86_64 && \
|
cp dropshell ../packages/output/dropshell-x86_64 && \
|
||||||
chown '"$USER_ID:$GROUP_ID"' ../packages/output/dropshell-x86_64 && \
|
chown '"$USER_ID:$GROUP_ID"' ../packages/output/dropshell-x86_64 && \
|
||||||
rm -rf build
|
rm -rf build \
|
||||||
'
|
'
|
||||||
|
|
||||||
|
echo "Building arm64 executable..."
|
||||||
# Build arm64 executable
|
# Build arm64 executable
|
||||||
docker run --rm -v "$(pwd)/..:/src" -u root dropshell-builder:latest bash -c '
|
docker run --rm -v "$(pwd)/..:/src" -u root dropshell-builder:latest bash -c ' \
|
||||||
rm -rf build && \
|
rm -rf build && \
|
||||||
mkdir -p build && \
|
mkdir -p build && \
|
||||||
cd build && \
|
cd build && \
|
||||||
cmake -DCMAKE_CXX_COMPILER=aarch64-linux-gnu-g++ \
|
cp ../packages/CMakeLists.txt.static ../CMakeLists.txt && \
|
||||||
-DCMAKE_BUILD_TYPE=Release .. && \
|
MUSL_GPP=$(which aarch64-linux-musl-g++) && \
|
||||||
|
cmake -DCMAKE_BUILD_TYPE=Release \
|
||||||
|
-DCMAKE_CXX_COMPILER=${MUSL_GPP} \
|
||||||
|
-DCMAKE_CXX_FLAGS="-static" .. && \
|
||||||
make && \
|
make && \
|
||||||
cp dropshell ../packages/output/dropshell-arm64 && \
|
cp dropshell ../packages/output/dropshell-arm64 && \
|
||||||
chown '"$USER_ID:$GROUP_ID"' ../packages/output/dropshell-arm64 && \
|
chown '"$USER_ID:$GROUP_ID"' ../packages/output/dropshell-arm64 && \
|
||||||
rm -rf build
|
rm -rf build \
|
||||||
'
|
'
|
Binary file not shown.
Binary file not shown.
Loading…
x
Reference in New Issue
Block a user