diff --git a/.devcontainer b/.devcontainer new file mode 160000 index 0000000..98c1aef --- /dev/null +++ b/.devcontainer @@ -0,0 +1 @@ +Subproject commit 98c1aef96d4d4e16c7028b46d99721a6e013c078 diff --git a/.github/workflows/xpbuild.yml b/.github/workflows/xpbuild.yml new file mode 100644 index 0000000..151d481 --- /dev/null +++ b/.github/workflows/xpbuild.yml @@ -0,0 +1,30 @@ +name: Build +on: + push: + branches: [ "dev" ] + pull_request: + branches: [ "dev" ] + workflow_dispatch: +jobs: + linux: + uses: externpro/externpro/.github/workflows/build-linux.yml@25.05.1 + with: + cmake-workflow-preset: Linux + runon: ubuntu-latest + secrets: inherit + linux-arm64: + uses: externpro/externpro/.github/workflows/build-linux.yml@25.05.1 + with: + cmake-workflow-preset: Linux + runon: ubuntu-24.04-arm + secrets: inherit + macos: + uses: externpro/externpro/.github/workflows/build-macos.yml@25.05.1 + with: + cmake-workflow-preset: Darwin + secrets: inherit + windows: + uses: externpro/externpro/.github/workflows/build-windows.yml@25.05.1 + with: + cmake-workflow-preset: Windows + secrets: inherit diff --git a/.github/workflows/xprelease.yml b/.github/workflows/xprelease.yml new file mode 100644 index 0000000..f868a82 --- /dev/null +++ b/.github/workflows/xprelease.yml @@ -0,0 +1,20 @@ +name: Release +on: + workflow_dispatch: + inputs: + workflow_run_url: + description: 'URL of the workflow run containing artifacts to upload (e.g., https://github.com/owner/repo/actions/runs/123456789)' + required: true + type: string +jobs: + # Upload build artifacts as release assets + release-from-build: + uses: externpro/externpro/.github/workflows/release-from-build.yml@25.05.1 + with: + workflow_run_url: ${{ github.event.inputs.workflow_run_url }} + artifact_pattern: "*.tar.xz" + permissions: + contents: write + id-token: write + attestations: write + secrets: inherit diff --git a/.gitignore b/.gitignore index da23814..67d1352 100644 --- a/.gitignore +++ b/.gitignore @@ -7,3 +7,8 @@ *.exe bzip2 bzip2recover + +# externpro +.env +_bld*/ +docker-compose.override.yml diff --git a/.gitmodules b/.gitmodules new file mode 100644 index 0000000..18932ab --- /dev/null +++ b/.gitmodules @@ -0,0 +1,3 @@ +[submodule ".devcontainer"] + path = .devcontainer + url = https://github.com/externpro/externpro diff --git a/CMakeLists.txt b/CMakeLists.txt new file mode 100644 index 0000000..c4dcb47 --- /dev/null +++ b/CMakeLists.txt @@ -0,0 +1,73 @@ +cmake_minimum_required(VERSION 3.31) +set(CMAKE_MODULE_PATH ${CMAKE_CURRENT_LIST_DIR}/.devcontainer/cmake) +set(CMAKE_PROJECT_TOP_LEVEL_INCLUDES xproinc) +project(bzip2 VERSION 1.0.8 LANGUAGES C) +include(flags) +include(GNUInstallDirs) +set(lib_name bz2) +######################################## +add_definitions(-D_FILE_OFFEST_BITS=64) +######################################## +set(${lib_name}_libsrcs + blocksort.c + huffman.c + crctable.c + randtable.c + compress.c + decompress.c + bzlib.c + bzlib.h + bzlib_private.h + ) +######################################## +add_library(${lib_name} STATIC ${${lib_name}_libsrcs}) +target_include_directories(${lib_name} PUBLIC $ + PRIVATE ${CMAKE_CURRENT_SOURCE_DIR} + ) +######################################## +add_executable(bzip2 bzip2.c) +target_link_libraries(bzip2 ${lib_name}) +set_target_properties(bzip2 PROPERTIES DEBUG_POSTFIX "${CMAKE_DEBUG_POSTFIX}") +######################################## +add_executable(bzip2recover bzip2recover.c) +set_target_properties(bzip2recover PROPERTIES DEBUG_POSTFIX "${CMAKE_DEBUG_POSTFIX}") +######################################## +include(CTest) +add_test(NAME bzip2_check + COMMAND ${CMAKE_COMMAND} + -DCMD=$ + -DSRC_DIR=${CMAKE_CURRENT_SOURCE_DIR} + -DBIN_DIR=${CMAKE_CURRENT_BINARY_DIR} + -P ${CMAKE_CURRENT_SOURCE_DIR}/run_bzip2_test.cmake + WORKING_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR} + ) +######################################## +set(targetsFile ${PROJECT_NAME}-targets) +set(exe bzip2) +set(lib ${lib_name}) +if(DEFINED XP_NAMESPACE) + string(PREPEND exe "${XP_NAMESPACE}::") + string(PREPEND lib "${XP_NAMESPACE}::") +endif() +xpPackageDevel(TARGETS_FILE ${targetsFile} LIBRARIES ${lib} EXE ${exe}) +install(TARGETS ${lib_name} EXPORT ${targetsFile} + ARCHIVE DESTINATION ${CMAKE_INSTALL_LIBDIR} + LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR} + RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR} + ) +install(TARGETS bzip2 bzip2recover EXPORT ${targetsFile} + ARCHIVE DESTINATION ${CMAKE_INSTALL_LIBDIR} + LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR} + RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR} + CONFIGURATIONS Release + ) +install(PROGRAMS $ DESTINATION ${CMAKE_INSTALL_BINDIR} CONFIGURATIONS Release RENAME bunzip2${CMAKE_EXECUTABLE_SUFFIX}) +install(PROGRAMS $ DESTINATION ${CMAKE_INSTALL_BINDIR} CONFIGURATIONS Release RENAME bzcat${CMAKE_EXECUTABLE_SUFFIX}) +install(FILES bzlib.h DESTINATION ${CMAKE_INSTALL_INCLUDEDIR}/${PROJECT_NAME}) +if(DEFINED XP_NAMESPACE) + set(nameSpace NAMESPACE ${XP_NAMESPACE}::) +endif() +if(NOT DEFINED XP_INSTALL_CMAKEDIR) + set(XP_INSTALL_CMAKEDIR ${CMAKE_INSTALL_DATADIR}/cmake) +endif() +install(EXPORT ${targetsFile} DESTINATION ${XP_INSTALL_CMAKEDIR} ${nameSpace}) diff --git a/CMakePresets.json b/CMakePresets.json new file mode 100644 index 0000000..f82cfdd --- /dev/null +++ b/CMakePresets.json @@ -0,0 +1,8 @@ +{ + "version": 8, + "include": [ + ".devcontainer/cmake/presets/xpLinuxNinja.json", + ".devcontainer/cmake/presets/xpDarwinNinja.json", + ".devcontainer/cmake/presets/xpWindowsVs2022.json" + ] +} diff --git a/CMakePresetsBase.json b/CMakePresetsBase.json new file mode 100644 index 0000000..5aa0fca --- /dev/null +++ b/CMakePresetsBase.json @@ -0,0 +1,14 @@ +{ + "version": 8, + "configurePresets": [ + { + "name": "config-base", + "hidden": true, + "binaryDir": "${sourceDir}/_bld-${presetName}", + "cacheVariables": { + "XP_INSTALL_CMAKEDIR": "share/cmake", + "XP_NAMESPACE": "xpro" + } + } + ] +} diff --git a/bzip2recover.c b/bzip2recover.c index a8131e0..136c72a 100644 --- a/bzip2recover.c +++ b/bzip2recover.c @@ -37,7 +37,7 @@ */ #ifdef __GNUC__ typedef unsigned long long int MaybeUInt64; -# define MaybeUInt64_FMT "%Lu" +# define MaybeUInt64_FMT "%llu" #else #ifdef _MSC_VER typedef unsigned __int64 MaybeUInt64; diff --git a/docker-compose.sh b/docker-compose.sh new file mode 120000 index 0000000..85f182f --- /dev/null +++ b/docker-compose.sh @@ -0,0 +1 @@ +.devcontainer/compose.pro.sh \ No newline at end of file diff --git a/docker-compose.yml b/docker-compose.yml new file mode 120000 index 0000000..46c1f89 --- /dev/null +++ b/docker-compose.yml @@ -0,0 +1 @@ +.devcontainer/compose.bld.yml \ No newline at end of file diff --git a/run_bzip2_test.cmake b/run_bzip2_test.cmake new file mode 100644 index 0000000..0ffb6b9 --- /dev/null +++ b/run_bzip2_test.cmake @@ -0,0 +1,27 @@ +set(commands + # Compress sample files + "'${CMD}' -1 < '${SRC_DIR}/sample1.ref' > '${BIN_DIR}/sample1.rb2'" + "'${CMD}' -2 < '${SRC_DIR}/sample2.ref' > '${BIN_DIR}/sample2.rb2'" + "'${CMD}' -3 < '${SRC_DIR}/sample3.ref' > '${BIN_DIR}/sample3.rb2'" + # Decompress sample files + "'${CMD}' -d < '${SRC_DIR}/sample1.bz2' > '${BIN_DIR}/sample1.tst'" + "'${CMD}' -d < '${SRC_DIR}/sample2.bz2' > '${BIN_DIR}/sample2.tst'" + "'${CMD}' -ds < '${SRC_DIR}/sample3.bz2' > '${BIN_DIR}/sample3.tst'" + # Verify compressed files + "'${CMAKE_COMMAND}' -E compare_files '${SRC_DIR}/sample1.bz2' '${BIN_DIR}/sample1.rb2'" + "'${CMAKE_COMMAND}' -E compare_files '${SRC_DIR}/sample2.bz2' '${BIN_DIR}/sample2.rb2'" + "'${CMAKE_COMMAND}' -E compare_files '${SRC_DIR}/sample3.bz2' '${BIN_DIR}/sample3.rb2'" + # Verify decompressed files + "'${CMAKE_COMMAND}' -E compare_files '${BIN_DIR}/sample1.tst' '${SRC_DIR}/sample1.ref'" + "'${CMAKE_COMMAND}' -E compare_files '${BIN_DIR}/sample2.tst' '${SRC_DIR}/sample2.ref'" + "'${CMAKE_COMMAND}' -E compare_files '${BIN_DIR}/sample3.tst' '${SRC_DIR}/sample3.ref'" + ) +foreach(cmd IN LISTS commands) + execute_process( + COMMAND ${CMAKE_COMMAND} -E echo "Running: ${cmd}" + COMMAND bash -c "${cmd}" RESULT_VARIABLE result + ) + if(NOT result EQUAL 0) + message(FATAL_ERROR "Command failed: ${cmd}\nExit code: ${result}") + endif() +endforeach()