diff --git a/.github/workflows/weekly-ci-bs-cmake-windows-make.yml b/.github/workflows/weekly-ci-bs-cmake-windows-make.yml index 41d35ff6..cb9ba6c2 100644 --- a/.github/workflows/weekly-ci-bs-cmake-windows-make.yml +++ b/.github/workflows/weekly-ci-bs-cmake-windows-make.yml @@ -29,10 +29,10 @@ jobs: # # clang-cl # - { os: windows-2022, cc: clang-cl, cxx: clang-cl, vsversion: 2022, arch: amd64 } # gcc (mingw-gcc) - - { os: windows-2022, cc: gcc, cxx: 'g++', arch: amd64 } + - { os: windows-2022, cc: gcc, cxx: 'g++', arch: amd64, xflags: '-static' } env: - CC: ${{ matrix.cc }} - CXX: ${{ matrix.cxx }} + CC: ${{ matrix.cc }} ${{ matrix.xflags }} + CXX: ${{ matrix.cxx }} ${{ matrix.xflags }} name: ${{ format('{0} {1} {2}', matrix.cc, matrix.vsversion, matrix.arch) }} runs-on: ${{ matrix.os }} steps: @@ -45,20 +45,23 @@ jobs: with: vsversion: ${{ matrix.vsversion }} arch: ${{ matrix.arch }} - - name: 'Build cmake Make Debug' + - name: 'Init environment' shell: bash run: | xtarget="windows-make-${{ matrix.cc }}-${{ matrix.vsversion }}-${{ matrix.arch}}" echo "xtarget=$xtarget" >> $GITHUB_ENV + - name: 'Build cmake Make Debug' + shell: bash + run: | make UPX_XTARGET=$xtarget xtarget/debug - ls -l build/xtarget/$xtarget/*/upx.exe - file build/xtarget/$xtarget/*/upx.exe || true + ls -l build/xtarget/$xtarget/debug/upx.exe + file build/xtarget/$xtarget/debug/upx.exe || true - name: 'Build cmake Make Release' shell: bash run: | make UPX_XTARGET=$xtarget xtarget/release - ls -l build/xtarget/$xtarget/*/upx.exe - file build/xtarget/$xtarget/*/upx.exe || true + ls -l build/xtarget/$xtarget/release/upx.exe + file build/xtarget/$xtarget/release/upx.exe || true - name: 'Make artifact' shell: bash run: | diff --git a/.github/workflows/weekly-ci-bs-cmake-windows-ninja.yml b/.github/workflows/weekly-ci-bs-cmake-windows-ninja.yml index 4f820ced..956a0a8e 100644 --- a/.github/workflows/weekly-ci-bs-cmake-windows-ninja.yml +++ b/.github/workflows/weekly-ci-bs-cmake-windows-ninja.yml @@ -28,10 +28,10 @@ jobs: # clang-cl - { os: windows-2022, cc: clang-cl, cxx: clang-cl, vsversion: 2022, arch: amd64 } # gcc (mingw-gcc) - - { os: windows-2022, cc: gcc, cxx: 'g++', arch: amd64 } + - { os: windows-2022, cc: gcc, cxx: 'g++', arch: amd64, xflags: '-static' } env: - CC: ${{ matrix.cc }} - CXX: ${{ matrix.cxx }} + CC: ${{ matrix.cc }} ${{ matrix.xflags }} + CXX: ${{ matrix.cxx }} ${{ matrix.xflags }} name: ${{ format('{0} {1} {2}', matrix.cc, matrix.vsversion, matrix.arch) }} runs-on: ${{ matrix.os }} steps: @@ -44,20 +44,24 @@ jobs: with: vsversion: ${{ matrix.vsversion }} arch: ${{ matrix.arch }} + - name: 'Init environment' + shell: bash + run: | + command -v ninja >/dev/null || choco install -y --no-progress ninja + xtarget="windows-make-${{ matrix.cc }}-${{ matrix.vsversion }}-${{ matrix.arch}}" + echo "xtarget=$xtarget" >> $GITHUB_ENV - name: 'Build cmake Ninja Debug' shell: bash run: | - xtarget="windows-ninja-${{ matrix.cc }}-${{ matrix.vsversion }}-${{ matrix.arch}}" - echo "xtarget=$xtarget" >> $GITHUB_ENV make UPX_XTARGET=$xtarget xtarget/debug - ls -l build/xtarget/$xtarget/*/upx.exe - file build/xtarget/$xtarget/*/upx.exe || true + ls -l build/xtarget/$xtarget/debug/upx.exe + file build/xtarget/$xtarget/debug/upx.exe || true - name: 'Build cmake Ninja Release' shell: bash run: | make UPX_XTARGET=$xtarget xtarget/release - ls -l build/xtarget/$xtarget/*/upx.exe - file build/xtarget/$xtarget/*/upx.exe || true + ls -l build/xtarget/$xtarget/release/upx.exe + file build/xtarget/$xtarget/release/upx.exe || true - name: 'Make artifact' shell: bash run: | diff --git a/.github/workflows/weekly-ci-cc-alpine-linux.yml b/.github/workflows/weekly-ci-cc-alpine-linux.yml index c3cb8eb5..eadaa85e 100644 --- a/.github/workflows/weekly-ci-cc-alpine-linux.yml +++ b/.github/workflows/weekly-ci-cc-alpine-linux.yml @@ -26,14 +26,14 @@ jobs: fail-fast: false matrix: include: - - { container: 'alpine:3.9' , use_cxx20: 0, use_cxx2b: 0, use_lto: 0 } # Jan 2019: C++17 + - { container: 'alpine:3.9' , use_cxx20: 0, use_cxx2b: 0, use_lto: 0 } # Jan 2019: C++17; clang-5 & gcc-8 - { container: 'alpine:3.10', use_cxx20: 0, use_cxx2b: 0, use_lto: 0 } - { container: 'alpine:3.11', use_cxx20: 0, use_cxx2b: 0, use_lto: 0 } - { container: 'alpine:3.12', use_cxx20: 0, use_cxx2b: 0, use_lto: 0 } - - { container: 'alpine:3.13', use_cxx20: 1, use_cxx2b: 0, use_lto: 0 } # Jan 2021: C++20 + - { container: 'alpine:3.13', use_cxx20: 1, use_cxx2b: 0, use_lto: 0 } # Jan 2021: C++20; clang-10 & gcc-10 - { container: 'alpine:3.14', use_cxx20: 1, use_cxx2b: 0, use_lto: 0 } - - { container: 'alpine:3.15', use_cxx20: 1, use_cxx2b: 0, use_lto: 1 } # Nov 2021: LTO - - { container: 'alpine:3.16', use_cxx20: 1, use_cxx2b: 1, use_lto: 1 } # May 2022: C++23 + - { container: 'alpine:3.15', use_cxx20: 1, use_cxx2b: 0, use_lto: 1 } # Nov 2021: LTO; clang-12 & gcc-10 & binutils-2.37 + - { container: 'alpine:3.16', use_cxx20: 1, use_cxx2b: 1, use_lto: 1 } # May 2022: C++2b; clang-13 & gcc-11 - { container: 'alpine:3.17', use_cxx20: 1, use_cxx2b: 1, use_lto: 1 } - { container: 'alpine:3.18', use_cxx20: 1, use_cxx2b: 1, use_lto: 1 } - { container: 'alpine:edge', use_cxx20: 1, use_cxx2b: 1, use_lto: 1 } @@ -47,11 +47,11 @@ jobs: run: | apk update && apk upgrade && apk add clang cmake g++ git make case ${{ matrix.container }} in - # clang-dev is needed on older Alpine versions for clang headers like + # clang-dev is needed on Alpine versions <= 3.11 for clang headers like *:3.[0-9] | *:3.1[0-1]) apk add clang-dev ;; esac case ${{ matrix.container }}-${{ matrix.use_lto }} in - # llvm-dev is needed on older Alpine versions for -flto (LTO also needs support in binutils) + # llvm-dev is needed on Alpine versions <= 3.18 for -flto *:3.[0-9]-1 | *:3.1[0-8]-1) apk add llvm-dev ;; esac # set environment vars @@ -100,25 +100,29 @@ jobs: # build with C23 and C++23 (using -std=gnu++2b) - name: ${{ format('Build clang C++23 Release with {0}', env.clang_package) }} - if: matrix.use_cxx2b + if: matrix.use_cxx23 || matrix.use_cxx2b run: | export UPX_CONFIG_DISABLE_C_STANDARD=ON UPX_CONFIG_DISABLE_CXX_STANDARD=ON - make -C "upx with space" UPX_XTARGET=clang-cxx23-static CC="clang -std=gnu2x -static" CXX="clang++ -std=gnu++2b -static" + a=gnu23; b=gnu++23; if test "X${{ matrix.use_cxx2b }}" = X1; then a=gnu2x; b=gnu++2b; fi + make -C "upx with space" UPX_XTARGET=clang-cxx23-static CC="clang -std=$a -static" CXX="clang++ -std=$b -static" - name: ${{ format('Build clang C++23 Debug with {0}', env.clang_package) }} - if: matrix.use_cxx2b + if: matrix.use_cxx23 || matrix.use_cxx2b run: | export UPX_CONFIG_DISABLE_C_STANDARD=ON UPX_CONFIG_DISABLE_CXX_STANDARD=ON - make -C "upx with space" UPX_XTARGET=clang-cxx23-static CC="clang -std=gnu2x -static" CXX="clang++ -std=gnu++2b -static" xtarget/debug + a=gnu23; b=gnu++23; if test "X${{ matrix.use_cxx2b }}" = X1; then a=gnu2x; b=gnu++2b; fi + make -C "upx with space" UPX_XTARGET=clang-cxx23-static CC="clang -std=$a -static" CXX="clang++ -std=$b -static" xtarget/debug - name: ${{ format('Build gcc C++23 Release with {0}', env.gcc_package) }} - if: matrix.use_cxx2b + if: matrix.use_cxx23 || matrix.use_cxx2b run: | export UPX_CONFIG_DISABLE_C_STANDARD=ON UPX_CONFIG_DISABLE_CXX_STANDARD=ON - make -C "upx with space" UPX_XTARGET=gcc-cxx23-static CC="gcc -std=gnu2x -static" CXX="g++ -std=gnu++2b -static" + a=gnu23; b=gnu++23; if test "X${{ matrix.use_cxx2b }}" = X1; then a=gnu2x; b=gnu++2b; fi + make -C "upx with space" UPX_XTARGET=gcc-cxx23-static CC="gcc -std=$a -static" CXX="g++ -std=$b -static" - name: ${{ format('Build gcc C++23 Debug with {0}', env.gcc_package) }} - if: matrix.use_cxx2b + if: matrix.use_cxx23 || matrix.use_cxx2b run: | export UPX_CONFIG_DISABLE_C_STANDARD=ON UPX_CONFIG_DISABLE_CXX_STANDARD=ON - make -C "upx with space" UPX_XTARGET=gcc-cxx23-static CC="gcc -std=gnu2x -static" CXX="g++ -std=gnu++2b -static" xtarget/debug + a=gnu23; b=gnu++23; if test "X${{ matrix.use_cxx2b }}" = X1; then a=gnu2x; b=gnu++2b; fi + make -C "upx with space" UPX_XTARGET=gcc-cxx23-static CC="gcc -std=$a -static" CXX="g++ -std=$b -static" xtarget/debug # build with -flto - name: ${{ format('Build clang LTO Release with {0}', env.clang_package) }} @@ -147,19 +151,6 @@ jobs: name: ${{ env.artifact_name }} path: 'upx with space*/build/*/*/*/upx' - - { name: 'Run basic tests clang Release', run: 'make -C "upx with space"/build/xtarget/clang-static/release test' } - - { name: 'Run basic tests clang Debug', run: 'make -C "upx with space"/build/xtarget/clang-static/debug test' } - - { name: 'Run basic tests gcc Release', run: 'make -C "upx with space"/build/xtarget/gcc-static/release test' } - - { name: 'Run basic tests gcc Debug', run: 'make -C "upx with space"/build/xtarget/gcc-static/debug test' } - - - name: 'Run basic tests C++20, C++23 and LTO' - if: matrix.use_cxx20 || matrix.use_cxx2b || matrix.use_cxx23 || matrix.use_lto - run: | - for dir in "upx with space"/build/xtarget/*-cxx*/*; do - echo "===== $dir" - make -C "$dir" test - done - - name: 'Run install tests' run: | (cd "upx with space"/build/xtarget/clang-static/debug && DESTDIR="$PWD/Install with cmake" cmake --install .) @@ -171,6 +162,19 @@ jobs: (cd "upx with space"/build/xtarget/gcc-static/release && DESTDIR="$PWD/Install with cmake" cmake --install .) (cd "upx with space"/build/xtarget/gcc-static/release && DESTDIR="$PWD/Install with make" make install) + - { name: 'Run basic tests clang Debug', run: 'make -C "upx with space"/build/xtarget/clang-static/debug test' } + - { name: 'Run basic tests clang Release', run: 'make -C "upx with space"/build/xtarget/clang-static/release test' } + - { name: 'Run basic tests gcc Debug', run: 'make -C "upx with space"/build/xtarget/gcc-static/debug test' } + - { name: 'Run basic tests gcc Release', run: 'make -C "upx with space"/build/xtarget/gcc-static/release test' } + + - name: 'Run basic tests C++20, C++23 and LTO' + if: matrix.use_cxx20 || matrix.use_cxx23 || matrix.use_cxx2b || matrix.use_lto + run: | + for dir in "upx with space"/build/xtarget/*-cxx*/*; do + echo "===== $dir" + make -C "$dir" test + done + - name: 'Run file system test suite (busybox)' run: | apk add bash sudo diff --git a/.github/workflows/weekly-ci-cc-llvm-mingw.yml b/.github/workflows/weekly-ci-cc-llvm-mingw.yml index 9263ee9e..e98bb005 100644 --- a/.github/workflows/weekly-ci-cc-llvm-mingw.yml +++ b/.github/workflows/weekly-ci-cc-llvm-mingw.yml @@ -24,12 +24,12 @@ jobs: - name: llvm-mingw-20230614-ucrt llvm_version: 16.0.6 url: 'https://github.com/mstorsjo/llvm-mingw/releases/download/20230614/llvm-mingw-20230614-ucrt-ubuntu-20.04-x86_64.tar.xz' - - name: llvm-mingw-20230905-msvcrt - llvm_version: 17.0.0rc4 - url: 'https://github.com/mstorsjo/llvm-mingw/releases/download/20230905/llvm-mingw-20230905-msvcrt-ubuntu-20.04-x86_64.tar.xz' - - name: llvm-mingw-20230905-ucrt - llvm_version: 17.0.0rc4 - url: 'https://github.com/mstorsjo/llvm-mingw/releases/download/20230905/llvm-mingw-20230905-ucrt-ubuntu-20.04-x86_64.tar.xz' + - name: llvm-mingw-20230919-msvcrt + llvm_version: 17.0.1 + url: 'https://github.com/mstorsjo/llvm-mingw/releases/download/20230919/llvm-mingw-20230919-msvcrt-ubuntu-20.04-x86_64.tar.xz' + - name: llvm-mingw-20230919-ucrt + llvm_version: 17.0.1 + url: 'https://github.com/mstorsjo/llvm-mingw/releases/download/20230919/llvm-mingw-20230919-ucrt-ubuntu-20.04-x86_64.tar.xz' name: ${{ format('{0} {1}', matrix.name, matrix.llvm_version) }} runs-on: ubuntu-latest steps: @@ -43,23 +43,23 @@ jobs: wget -q '${{ matrix.url }}' ls -l ./llvm-mingw*.tar.* tar -xoaf ./llvm-mingw*.tar.* - rm ./llvm-mingw*tar.* + rm ./llvm-mingw*.tar.* # update PATH cd ./llvm-mingw*/bin echo "PATH=$PWD:$PATH" >> $GITHUB_ENV - - name: 'Build aarch64' + - name: 'Build clang aarch64' run: | export CC="aarch64-w64-mingw32-clang -static" CXX="aarch64-w64-mingw32-clang++ -static" make UPX_XTARGET=aarch64-w64-mingw32-clang xtarget/debug xtarget/release - - name: 'Build armv7' + - name: 'Build clang armv7' run: | export CC="armv7-w64-mingw32-clang -static" CXX="armv7-w64-mingw32-clang++ -static" make UPX_XTARGET=armv7-w64-mingw32-clang xtarget/debug xtarget/release - - name: 'Build i686' + - name: 'Build clang i686' run: | export CC="i686-w64-mingw32-clang -static" CXX="i686-w64-mingw32-clang++ -static" make UPX_XTARGET=i686-w64-mingw32-clang xtarget/debug xtarget/release - - name: 'Build x86_64' + - name: 'Build clang x86_64' run: | export CC="x86_64-w64-mingw32-clang -static" CXX="x86_64-w64-mingw32-clang++ -static" make UPX_XTARGET=x86_64-w64-mingw32-clang xtarget/debug xtarget/release diff --git a/CMakeLists.txt b/CMakeLists.txt index c12b73b5..853e8ddc 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -16,7 +16,7 @@ endif() # compilation config options if(NOT IS_DIRECTORY "${CMAKE_CURRENT_SOURCE_DIR}/.git") - # permissive config defaults when building from source code tarball + # permissive config defaults when building from source code release tarball option(UPX_CONFIG_DISABLE_GITREV "Do not compile with default Git version info." ON) option(UPX_CONFIG_DISABLE_SANITIZE "Do not compile with default sanitize options." ON) option(UPX_CONFIG_DISABLE_WSTRICT "Do not compile with strict compiler warnings." ON) @@ -166,6 +166,7 @@ endif() #*********************************************************************** include(CheckCCompilerFlag) +include(CheckIncludeFile) if(UPX_CONFIG_DISABLE_WSTRICT) # enable all basic warnings @@ -372,10 +373,13 @@ set(t upx_vendor_zlib) upx_compile_target_debug_with_O2(${t}) upx_sanitize_target(${t}) target_compile_definitions(${t} PRIVATE HAVE_VSNPRINTF=1) +check_include_file("unistd.h" HAVE_UNISTD_H) +if(HAVE_UNISTD_H) + target_compile_definitions(${t} PRIVATE HAVE_UNISTD_H=1) +endif() if(MSVC_FRONTEND) target_compile_options(${t} PRIVATE -W3 ${warn_WX}) else() - target_compile_definitions(${t} PRIVATE HAVE_UNISTD_H=1) target_compile_options(${t} PRIVATE -Wall ${warn_Werror}) ##target_compile_options(${t} PRIVATE ${warn_Wall} -Wno-cast-align -Wno-cast-qual ${warn_Werror}) endif() diff --git a/Makefile b/Makefile index 05fcb497..f2679590 100644 --- a/Makefile +++ b/Makefile @@ -20,9 +20,10 @@ endif # enable this if you prefer Ninja for the actual builds: #UPX_CMAKE_CONFIG_FLAGS += -G Ninja -# by default CMake only honors CC and CXX; make it easy to use other -# variables like CMAKE_AR by manually passing them +# info: by default CMake only honors the CC and CXX environment variables; make +# it easy to set other variables like CMAKE_AR or CMAKE_RANLIB __add_cmake_config = $(and $($1),-D$1="$($1)") +# pass common CMake settings from environment/make to cmake build/%: UPX_CMAKE_CONFIG_FLAGS += $(call __add_cmake_config,CMAKE_AR) build/%: UPX_CMAKE_CONFIG_FLAGS += $(call __add_cmake_config,CMAKE_NM) build/%: UPX_CMAKE_CONFIG_FLAGS += $(call __add_cmake_config,CMAKE_RANLIB) @@ -109,6 +110,12 @@ build/extra/clang-static/release: PHONY; $(call run_config_and_build,$@,Release) build/extra/clang-static/%: export CC = clang -static build/extra/clang-static/%: export CXX = clang++ -static +# force building with clang/clang++ -static -flto +build/extra/clang-static-lto/debug: PHONY; $(call run_config_and_build,$@,Debug) +build/extra/clang-static-lto/release: PHONY; $(call run_config_and_build,$@,Release) +build/extra/clang-static-lto/%: export CC = clang -static -flto +build/extra/clang-static-lto/%: export CXX = clang++ -static -flto + # force building with clang/clang++ C17/C++20 build/extra/clang-std-cxx20/debug: PHONY; $(call run_config_and_build,$@,Debug) build/extra/clang-std-cxx20/release: PHONY; $(call run_config_and_build,$@,Release) @@ -155,6 +162,12 @@ build/extra/gcc-static/release: PHONY; $(call run_config_and_build,$@,Release) build/extra/gcc-static/%: export CC = gcc -static build/extra/gcc-static/%: export CXX = g++ -static +# force building with gcc/g++ -static -flto +build/extra/gcc-static-lto/debug: PHONY; $(call run_config_and_build,$@,Debug) +build/extra/gcc-static-lto/release: PHONY; $(call run_config_and_build,$@,Release) +build/extra/gcc-static-lto/%: export CC = gcc -static -flto +build/extra/gcc-static-lto/%: export CXX = g++ -static -flto + # force building with gcc/g++ C17/C++20 build/extra/gcc-std-cxx20/debug: PHONY; $(call run_config_and_build,$@,Debug) build/extra/gcc-std-cxx20/release: PHONY; $(call run_config_and_build,$@,Release)