diff --git a/CMakeLists.txt b/CMakeLists.txt index 648d0c0..7c44d3f 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -14,7 +14,8 @@ set(EXEDESC "Transpiler for the yerbacon language.") string(TIMESTAMP SHORT_BUILD_TIMESTAMP "%Y%m") string(SUBSTRING ${SHORT_BUILD_TIMESTAMP} 2 4 SHORT_BUILD_TIMESTAMP) string(ASCII 169 CopyrightCharacter) -string(TIMESTAMP LEGAL-COPYRIGHT "Copyright ${CopyrightCharacter} 2020-%Y. Available under the MPL-2.0 license.") +set(CPACK_RPM_PACKAGE_LICENSE "MPL-2.0") +string(TIMESTAMP LEGAL-COPYRIGHT "Copyright ${CopyrightCharacter} 2020-%Y. Available under the ${CPACK_RPM_PACKAGE_LICENSE} license.") file(COPY "resources/${PROJECT_NAME}.ico" DESTINATION "processed") configure_file("resources/${PROJECT_NAME}.manifest" "processed/${PROJECT_NAME}.manifest" @ONLY) configure_file("resources/${PROJECT_NAME}.rc" "processed/${PROJECT_NAME}.rc" @ONLY) @@ -200,7 +201,26 @@ if (NOT (UPPERCASE_BUILD_TYPE STREQUAL "DEBUG" OR UPPERCASE_BUILD_TYPE STREQUAL endif() endif() -if (UNIX AND NOT (MINGW OR CMAKE_HOST_WIN32)) +if (EMSCRIPTEN) + find_program(NPM_PRESENT npm) + find_program(YARN_PRESENT yarn) + if (YARN_PRESENT) + set(NODE_PACKAGE_PROGRAM "${YARN_PRESENT}") + elseif(NPM_PRESENT) + set(NODE_PACKAGE_PROGRAM "${NPM_PRESENT}") + endif() + if (DEFINED NODE_PACKAGE_PROGRAM) + configure_file("resources/package.json" "processed/package.json" @ONLY) + file(COPY "${CMAKE_CURRENT_BINARY_DIR}/processed/package.json" DESTINATION ".") + file(COPY "resources/.npmrc" DESTINATION ".") + add_custom_target(vercel_pkg COMMAND ${NODE_PACKAGE_PROGRAM} install) + add_dependencies(vercel_pkg ${EXENAME}) + # Warning: https://github.com/sbingner/ldid has to be on the PATH, before packaging, for the arm64 macOS executable to work + add_custom_command(TARGET vercel_pkg POST_BUILD COMMAND node_modules/.bin/pkg --config processed/package.json -C Brotli $ --no-bytecode --public-packages "\"*\"" --public --output "${EXENAME}-mac" VERBATIM) + endif() +endif() + +if (UNIX AND NOT (MINGW OR CMAKE_HOST_WIN32 OR EMSCRIPTEN)) include(GNUInstallDirs) set(CMAKE_INSTALL_PREFIX "/usr") set(CPACK_PACKAGING_INSTALL_PREFIX "${CMAKE_INSTALL_PREFIX}") @@ -214,7 +234,6 @@ if (UNIX AND NOT (MINGW OR CMAKE_HOST_WIN32)) set(CPACK_RPM_COMPRESSION_TYPE ${CPACK_DEBIAN_COMPRESSION_TYPE}) set(CPACK_RPM_PACKAGE_AUTOREQ YES) set(CPACK_RPM_FILE_NAME "RPM-DEFAULT") - set(CPACK_RPM_PACKAGE_LICENSE "MPL-2.0") set(CPACK_RPM_CHANGELOG_FILE "${CMAKE_CURRENT_SOURCE_DIR}/changelog") if (CMAKE_VERSION STREQUAL "3.21.1") message(WARNING "CPack ${CMAKE_VERSION} has a bug which causes rpm scripts to be unusable; please update or downgrade") diff --git a/Jenkinsfile b/Jenkinsfile index 5a37926..8066c55 100644 --- a/Jenkinsfile +++ b/Jenkinsfile @@ -1,5 +1,6 @@ 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 @@ -13,6 +14,8 @@ def clean_workspace() { cleanWs(cleanWhenNotBuilt: false, deleteDirs: true, disa Optional Tools: - Ninja - UPX (d61edc9 or higher) + - Vercel PKG (https://github.com/vercel/pkg) + - LDID (https://github.com/sbingner/ldid) */ pipeline { @@ -67,7 +70,7 @@ pipeline { 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_SYSTEM_PROCESSOR=\"${path.substring(0, path.indexOf('-'))}\" -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 -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 ybcon", installation: 'Latest' + cmake arguments: "--build ./$build_directory --target ${!("${TARGET}".endsWith('Emscripten.cmake') && use_yarn_or_npm()) ? 'ybcon' : 'vercel_pkg'}", installation: 'Latest' } } } @@ -86,7 +89,7 @@ pipeline { 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, cmake-build-*/*.*.exe, cmake-build-*/*.zip', fingerprint: false + 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 } } } diff --git a/resources/.npmrc b/resources/.npmrc new file mode 100644 index 0000000..9cf9495 --- /dev/null +++ b/resources/.npmrc @@ -0,0 +1 @@ +package-lock=false \ No newline at end of file diff --git a/resources/package.json b/resources/package.json new file mode 100644 index 0000000..c475403 --- /dev/null +++ b/resources/package.json @@ -0,0 +1,13 @@ +{ + "name": "@EXENAME@", + "bin": "@EXENAME@.js", + "license": "@CPACK_RPM_PACKAGE_LICENSE@", + "devDependencies": { "pkg": "^5.8.0" }, + "pkg": { + "assets": "../@EXENAME@.worker.js", + "targets": [ + "latest-macos-x64", + "latest-macos-arm64" + ] + } +} \ No newline at end of file