String cmake_generator() { return fileExists('/usr/bin/ninja') ? 'Ninja' : 'Unix Makefiles' } String no_compilation_cache_flags() { return '-DNO_CCACHE=ON -DCMAKE_DISABLE_PRECOMPILE_HEADERS=ON' } def buildTarget(String path, String rpmArch = 'noarch', String debArch = 'noarch', boolean isPackageArchDeb = true, String suffix = '') { final String packageArch = isPackageArchDeb ? debArch : rpmArch; final String system_name = !path.contains('mingw') ? sh(returnStdout: true, script: 'uname -s').trim() : 'Windows' final String linker = "/usr/bin/${path}-ld" final String build_directory = "cmake-build-${packageArch}${suffix}" final boolean upx_exists = fileExists('/usr/bin/upx') final boolean is_riscv = path.contains('riscv') // Note: CMake 3.20 or higher is needed cmakeBuild buildDir: build_directory, buildType: 'release', cleanBuild: true, installation: 'Latest', cmakeArgs: "--no-warn-unused-cli -DCMAKE_SYSTEM_NAME=\"${system_name}\" -DCMAKE_C_COMPILER=/usr/bin/${path}-gcc -DCMAKE_CXX_COMPILER=/usr/bin/${path}-g++ -DCMAKE_LINKER=${fileExists("${linker}.gold") ? "${linker}.gold" : linker} -DCMAKE_AR=/usr/bin/${path}-ar -DCMAKE_RC_COMPILER=/usr/bin/${path}-windres -DCPACK_RPM_PACKAGE_ARCHITECTURE=${rpmArch} -DCPACK_DEBIAN_PACKAGE_ARCHITECTURE=${debArch} -DCXX_TARGET=${packageArch} -DCMAKE_EXE_LINKER_FLAGS=-static -DNO_SELF_PACKER=${!upx_exists || is_riscv ? 'ON' : 'OFF'} -DIGNORE_MINIMAL_COMPILER_VERSION=ON -DCPACK_STRIP_FILES=FALSE ${no_compilation_cache_flags()}", generator: cmake_generator() cmake arguments: "--build ./$build_directory --target ybcon", installation: 'Latest' if (!upx_exists || is_riscv) { sh "/usr/bin/${path}-strip -s ./$build_directory/ybcon*" } cpack installation: 'Latest', workingDir: build_directory } final String windowsSuffix = '-windows' /* Required Plugins: - CMake - Sidebar Link - Workspace Cleanup Required Compilers: - G++ cross-compiler for riscv64 - Musl cross-compiling toolchains (archives ending in "-cross" from https://musl.cc/#binaries) for x86_64, i686, armel, armhf and aarch64, unzipped into /usr/, along with soft links from /usr/bin/ to the binaries - Emscripten Clang (https://github.com/emscripten-core/emsdk) in /usr/share/ - MinGW32 G++/Clang (https://github.com/mstorsjo/llvm-mingw) for x86_64, i686, armhf and aarch64, (unzip the content of the folder in the tar.xz file) in /usr/, along with soft links from /usr/bin/ to the binaries Optional Tools: - Ninja - UPX (the devel branch is required because of a bug which is not fixed in the 3.96 version) */ pipeline { agent any options { buildDiscarder(logRotator(numToKeepStr: '48', artifactNumToKeepStr: '96')) timeout(time: 25, unit: 'MINUTES') sidebarLinks([ [displayName: 'Gitea Repository', iconFileName: '/userContent/Yerbacon.png', urlName: 'https://gits.username404.fr/Username404-59/Yerbacon/src/branch/' + env.BRANCH_NAME] ]) } triggers { pollSCM('*/10 * * * *') } stages { stage('Build') { steps { echo "Building the ${env.BRANCH_NAME} branch.." buildTarget('x86_64-linux-musl', 'x86_64', 'amd64') buildTarget('i686-linux-musl', 'i386', 'i386') cmakeBuild buildDir: "cmake-build-release-emscripten", buildType: 'release', cleanBuild: true, installation: 'Latest', cmakeArgs: "-DCMAKE_TOOLCHAIN_FILE=\"/usr/share/emsdk/upstream/emscripten/cmake/Modules/Platform/Emscripten.cmake\" ${no_compilation_cache_flags()}", generator: cmake_generator() cmake arguments: "--build ./cmake-build-release-emscripten", installation: 'Latest' } } stage('Build for other architectures') { steps { catchError(buildResult: 'SUCCESS', stageResult: 'FAILURE') { buildTarget('armel-linux-musleabi', 'armv4l', 'armel') buildTarget('armv7l-linux-musleabihf', 'armv7hl', 'armhf') buildTarget('aarch64-linux-musl', 'aarch64', 'arm64', false) buildTarget('riscv64-linux-gnu', 'riscv64', 'riscv64') } } } stage('Build for other platforms') { steps { catchError(buildResult: 'SUCCESS', stageResult: 'UNSTABLE') { buildTarget('armv7-w64-mingw32', 'armv7hl', 'armhf', true, windowsSuffix) buildTarget('aarch64-w64-mingw32', 'aarch64', 'arm64', false, windowsSuffix) } catchError(buildResult: 'SUCCESS', stageResult: 'FAILURE') { buildTarget('x86_64-w64-mingw32', 'x86_64', 'amd64', true, windowsSuffix) buildTarget('i686-w64-mingw32', 'i386', 'i386', true, windowsSuffix) } } } stage('Deploy') { steps { echo 'Deploying....' archiveArtifacts artifacts: 'cmake-build-*/*.deb, cmake-build-*/*.rpm, cmake-build-*/*.tar.gz, cmake-build-*/*.sh, cmake-build-release-emscripten/*.js', fingerprint: false catchError(buildResult: 'SUCCESS', stageResult: 'SUCCESS') { archiveArtifacts artifacts: 'cmake-build-*/*wpkg.*.exe, cmake-build-*/*.zip' } } } } post { always { cleanWs(cleanWhenNotBuilt: false, deleteDirs: true, disableDeferredWipeout: false, notFailBuild: true, skipWhenFailed: false) } } }