String cmake_generator() { return fileExists('/usr/bin/ninja') ? 'Ninja' : 'Unix Makefiles' } def clean_workspace() { cleanWs(cleanWhenNotBuilt: false, deleteDirs: true, disableDeferredWipeout: false, notFailBuild: true, skipWhenFailed: false) } boolean use_yarn_or_npm() { return fileExists('/usr/bin/yarn') || fileExists('/usr/bin/npm') } /* Required Plugins: - CMake 3.21 or higher - Sidebar Link - Workspace Cleanup Required Compilers: - Musl cross-compiling toolchains (archives ending in "-cross" from https://musl.cc/#binaries) for x86_64, i686, armel, armhf, aarch64 and riscv64, unzipped into /usr/, along with soft links from /usr/bin/ to the binaries - Emscripten Clang (https://github.com/emscripten-core/emsdk; the 3.1.30 version is known to work) 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 - Android NDK Clang (https://ci.android.com/builds/submitted/10493228/linux/latest/android-ndk-10493228-linux-x86_64.zip) unzipped as /usr/android-ndk Optional Tools: - Ninja - UPX (d61edc9 or higher) - NPM/Yarn to enable Yao PKG (https://github.com/yao-pkg/pkg) - LDID (https://github.com/ProcursusTeam/ldid or https://github.com/sbingner/ldid) */ 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') { matrix { agent any axes { axis { name 'TARGET' values( 'x86_64-linux-musl (RPM=x86_64, DEB=amd64)', 'i686-linux-musl (RPM=i686, DEB=i386)', 'armel-linux-musleabi (RPM=armv4l, DEB=armel)', 'armv7l-linux-musleabihf (RPM=armv7hl, DEB=armhf)', 'aarch64-linux-musl (RPM=aarch64, DEB=arm64)', 'riscv64-linux-musl (RPM=riscv64, DEB=riscv64)', 'x86_64-w64-mingw32 (RPM=x86_64, DEB=amd64)', 'i686-w64-mingw32 (RPM=i386, DEB=i386)', 'armv7-w64-mingw32 (RPM=armv7hl, DEB=armhf)', 'aarch64-w64-mingw32 (RPM=aarch64, DEB=arm64)', 'x86_64-linux-android21 (RPM=x86_64, DEB=amd64) -> x86_64', 'i686-linux-android21 (RPM=i686, DEB=i386) -> x86', 'armv7a-linux-android21 (RPM=armv7, DEB=armhf) -> armeabi-v7a', 'aarch64-linux-android21 (RPM=aarch64, DEB=arm64) -> arm64-v8a', '/usr/share/emsdk/upstream/emscripten/cmake/Modules/Platform/Emscripten.cmake' ) } } stages { stage('Compile') { steps { script { final boolean use_toolchain = "${TARGET}".endsWith('.cmake') final String path = use_toolchain ? "${TARGET}" : "${TARGET}".substring(0, "${TARGET}".indexOf(' (')) final String rpmArch = use_toolchain ? 'noarch' : "${TARGET}".substring("${TARGET}".indexOf('(RPM=') + 5, "${TARGET}".indexOf(',')) final String debArch = use_toolchain ? 'noarch' : "${TARGET}".substring("${TARGET}".indexOf('DEB=') + 4, "${TARGET}".indexOf(')')) final String system_name = path.contains('mingw') ? 'Windows' : (path.contains('android') ? 'Android' : sh(returnStdout: true, script: 'uname -s').trim()) final String linker = "/usr/bin/${path}-ld" final boolean not_packer_compatible = path.contains('riscv') || ((path.contains('aarch64') || path.contains('arm')) && path.contains('mingw')) final String build_directory = "cmake-build-${use_toolchain ? path.substring(path.lastIndexOf('/') + 1, path.length() - 6) : path}".toLowerCase() catchError(buildResult: 'UNSTABLE', stageResult: 'FAILURE') { cmakeBuild buildDir: build_directory, buildType: 'release', cleanBuild: true, installation: 'Latest', cmakeArgs: "--no-warn-unused-cli ${use_toolchain ? "-DCMAKE_TOOLCHAIN_FILE=${path}" : "-DCMAKE_SYSTEM_NAME=\"${system_name}\" -DCXX_TARGET=\"${use_toolchain ? 'noarch' : debArch}\" -DCPACK_RPM_PACKAGE_ARCHITECTURE=${rpmArch} -DCPACK_DEBIAN_PACKAGE_ARCHITECTURE=${debArch} -DCMAKE_C_COMPILER=/usr/bin/${path}-gcc -DCMAKE_CXX_COMPILER=/usr/bin/${path}-g++ ${system_name == 'Android' ? "-DCMAKE_SYSTEM_VERSION=21 -DCMAKE_ANDROID_STL_TYPE=c++_static -DCMAKE_CXX_FLAGS=-static-openmp -DCMAKE_ANDROID_NDK=/usr/android-ndk -DCMAKE_ANDROID_ARCH_ABI=${"${TARGET}".substring("${TARGET}".indexOf(' -> ') + 4)}" : "-DCMAKE_SYSTEM_PROCESSOR=${path.substring(0, path.indexOf('-'))}"} -DCMAKE_LINKER=${fileExists("${linker}.gold") ? "${linker}.gold" : linker} -DCMAKE_AR=/usr/bin/${path}-ar -DCMAKE_RC_COMPILER=/usr/bin/${path}-windres -DCMAKE_EXE_LINKER_FLAGS=-static"} -DNO_SELF_PACKER=${!(not_packer_compatible || use_toolchain) ? "OFF" : "ON"} -DIGNORE_MINIMAL_COMPILER_VERSION=ON -DNO_CCACHE=ON -DCMAKE_DISABLE_PRECOMPILE_HEADERS=ON${path.endsWith('armv7-w64-mingw32') ? ' -DCMAKE_INTERPROCEDURAL_OPTIMIZATION_RELEASE=NO' : ''}", generator: cmake_generator() cmake arguments: "--build ./$build_directory --target ${!("${TARGET}".endsWith('Emscripten.cmake') && use_yarn_or_npm()) ? 'ybcon' : 'yao_pkg'}", installation: 'Latest' } } } } stage('Package') { when { equals expected: true, actual: !"${TARGET}".endsWith('.cmake') } steps { catchError(buildResult: 'UNSTABLE', stageResult: 'FAILURE') { script { cpack installation: 'Latest', workingDir: "cmake-build-${"${TARGET}".substring(0, "${TARGET}".indexOf(' ('))}" } } } } stage('Deploy') { steps { echo 'Deploying....' catchError(buildResult: "${TARGET}".endsWith('.cmake') ? 'FAILURE' : 'UNSTABLE', stageResult: 'FAILURE') { archiveArtifacts artifacts: "cmake-build-*/*.deb, cmake-build-*/*.rpm, cmake-build-*/*.tar.gz, cmake-build-*/*.sh, cmake-build-*/*.js,${use_yarn_or_npm() ? 'cmake-build-*/*-mac-*,' : ''} cmake-build-*/*.*.exe, cmake-build-*/*.zip", fingerprint: false } } } } post { always { clean_workspace() } } } } } post { always { clean_workspace() } } }