From 4e33517cb0a104db9d6269675207120434533858 Mon Sep 17 00:00:00 2001 From: Alexis Montoison Date: Thu, 30 May 2024 17:20:44 -0400 Subject: [PATCH] Add scripts to provide precompiled archives of SIFDecode --- .github/julia/build_tarballs.jl | 60 ++++++++++++++++ .github/julia/generate_binaries.jl | 92 ++++++++++++++++++++++++ .github/workflows/release.yml | 108 +++++++++++++++++++++++------ meson.build | 2 +- 4 files changed, 241 insertions(+), 21 deletions(-) create mode 100644 .github/julia/build_tarballs.jl create mode 100644 .github/julia/generate_binaries.jl diff --git a/.github/julia/build_tarballs.jl b/.github/julia/build_tarballs.jl new file mode 100644 index 0000000..cf6961b --- /dev/null +++ b/.github/julia/build_tarballs.jl @@ -0,0 +1,60 @@ +using BinaryBuilder, Pkg + +haskey(ENV, "SIFDECODE_RELEASE") || error("The environment variable SIFDECODE_RELEASE is not defined.") +haskey(ENV, "SIFDECODE_COMMIT") || error("The environment variable SIFDECODE_COMMIT is not defined.") + +name = "SIFDECODE" +version = VersionNumber(ENV["SIFDECODE_RELEASE"]) + +# Collection of sources required to complete build +sources = [ + GitSource("https://github.com/ralna/SIFDecode.git", ENV["SIFDECODE_COMMIT"]) +] + +# Bash recipe for building across all platforms +script = raw""" +# Export dependencies +mkdir ${prefix}/deps +cd ${libdir} +for file in $(ls .); do + if [[ -f $file ]]; then + if [[ -z $(ls -la $file | grep 'artifacts') ]]; then + cp -P ${file} ${prefix}/deps/${file} + else + cp -L ${file} ${prefix}/deps/${file} + fi + fi +done +cd ${prefix} +cp -rL share/licenses deps/licenses +chmod -R u=rwx deps +tar -czvf deps.tar.gz deps +rm -r deps + +# Update Ninja +cp ${host_prefix}/bin/ninja /usr/bin/ninja + +cd ${WORKSPACE}/srcdir/SIFDecode +meson setup builddir --cross-file=${MESON_TARGET_TOOLCHAIN%.*}_gcc.meson --prefix=$prefix +meson compile -C builddir +meson install -C builddir +""" + +# These are the platforms we will build for by default, unless further +# platforms are passed in on the command line +platforms = supported_platforms() +platforms = expand_gfortran_versions(platforms) + +# The products that we will ensure are always built +products = [ + LibraryProduct("libsifdecode", :libsifdecode) +] + +# Dependencies that must be installed before this package can be built +dependencies = [ + HostBuildDependency(PackageSpec(name="Ninja_jll", uuid="76642167-d241-5cee-8c94-7a494e8cb7b7")), + Dependency(PackageSpec(name="CompilerSupportLibraries_jll", uuid="e66e0078-7015-5450-92f7-15fbd957f2ae")), +] + +# Build the tarballs, and possibly a `build.jl` as well. +build_tarballs(ARGS, name, version, sources, script, platforms, products, dependencies; preferred_gcc_version=v"9.1", julia_compat="1.6") diff --git a/.github/julia/generate_binaries.jl b/.github/julia/generate_binaries.jl new file mode 100644 index 0000000..242441b --- /dev/null +++ b/.github/julia/generate_binaries.jl @@ -0,0 +1,92 @@ +# Version +haskey(ENV, "SIFDECODE_RELEASE") || error("The environment variable SIFDECODE_RELEASE is not defined.") +version = VersionNumber(ENV["SIFDECODE_RELEASE"]) +version2 = ENV["SIFDECODE_RELEASE"] +package = "SIFDECODE" + +platforms = [ + ("aarch64-apple-darwin-libgfortran5" , "lib", "dylib"), +# ("aarch64-linux-gnu-libgfortran3" , "lib", "so" ), +# ("aarch64-linux-gnu-libgfortran4" , "lib", "so" ), +# ("aarch64-linux-gnu-libgfortran5" , "lib", "so" ), +# ("aarch64-linux-musl-libgfortran3" , "lib", "so" ), +# ("aarch64-linux-musl-libgfortran4" , "lib", "so" ), +# ("aarch64-linux-musl-libgfortran5" , "lib", "so" ), +# ("powerpc64le-linux-gnu-libgfortran3" , "lib", "so" ), +# ("powerpc64le-linux-gnu-libgfortran4" , "lib", "so" ), +# ("powerpc64le-linux-gnu-libgfortran5" , "lib", "so" ), +# ("x86_64-apple-darwin-libgfortran3" , "lib", "dylib"), +# ("x86_64-apple-darwin-libgfortran4" , "lib", "dylib"), + ("x86_64-apple-darwin-libgfortran5" , "lib", "dylib"), +# ("x86_64-linux-gnu-libgfortran3" , "lib", "so" ), +# ("x86_64-linux-gnu-libgfortran4" , "lib", "so" ), + ("x86_64-linux-gnu-libgfortran5" , "lib", "so" ), +# ("x86_64-linux-musl-libgfortran3" , "lib", "so" ), +# ("x86_64-linux-musl-libgfortran4" , "lib", "so" ), +# ("x86_64-linux-musl-libgfortran5" , "lib", "so" ), +# ("x86_64-unknown-freebsd-libgfortran3", "lib", "so" ), +# ("x86_64-unknown-freebsd-libgfortran4", "lib", "so" ), +# ("x86_64-unknown-freebsd-libgfortran5", "lib", "so" ), +# ("x86_64-w64-mingw32-libgfortran3" , "bin", "dll" ), +# ("x86_64-w64-mingw32-libgfortran4" , "bin", "dll" ), + ("x86_64-w64-mingw32-libgfortran5" , "bin", "dll" ), +] + + +for (platform, libdir, ext) in platforms + + tarball_name = "$package.v$version.$platform.tar.gz" + + if isfile("products/$(tarball_name)") + # Unzip the tarball generated by BinaryBuilder.jl + isdir("products/$platform") && rm("products/$platform", recursive=true) + mkdir("products/$platform") + run(`tar -xzf products/$(tarball_name) -C products/$platform`) + + if isfile("products/$platform/deps.tar.gz") + # Unzip the tarball of the dependencies + run(`tar -xzf products/$platform/deps.tar.gz -C products/$platform`) + + # Copy the license of each dependency + for folder in readdir("products/$platform/deps/licenses") + cp("products/$platform/deps/licenses/$folder", "products/$platform/share/licenses/$folder") + end + rm("products/$platform/deps/licenses", recursive=true) + + # Copy the shared library of each dependency + for file in readdir("products/$platform/deps") + cp("products/$platform/deps/$file", "products/$platform/$libdir/$file") + end + + # Remove the folder used to unzip the tarball of the dependencies + rm("products/$platform/deps", recursive=true) + rm("products/$platform/deps.tar.gz", recursive=true) + + # Create the archives *_binaries + isfile("$(package)_binaries.$version2.$platform.tar.gz") && rm("$(package)_binaries.$version2.$platform.tar.gz") + isfile("$(package)_binaries.$version2.$platform.zip") && rm("$(package)_binaries.$version2.$platform.zip") + cd("products/$platform") + + # Create a folder with the version number of the package + mkdir("$(package)_binaries.$version2") + for folder in ("share", "modules", "lib", "bin") + cp(folder, "$(package)_binaries.$version2/$folder") + end + + cd("$(package)_binaries.$version2") + if ext == "dll" + run(`zip -r --symlinks ../../../$(package)_binaries.$version2.$platform.zip include modules lib bin`) + else + run(`tar -czf ../../../$(package)_binaries.$version2.$platform.tar.gz share modules lib bin`) + end + cd("../../..") + + # Remove the folder used to unzip the tarball generated by BinaryBuilder.jl + rm("products/$platform", recursive=true) + else + @warn("The tarball deps.tar.gz is missing in $(tarball_name)!") + end + else + @warn("The tarball for the platform $platform was not generated!") + end +end diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml index 4db17f3..1471a7b 100644 --- a/.github/workflows/release.yml +++ b/.github/workflows/release.yml @@ -1,25 +1,93 @@ -on: +name: Release +on: push: - branches: - - master - - main - + # Sequence of patterns matched against refs/tags + tags: + - 'v*' # Push events to matching v*, i.e. v1.0, v2023.11.15 jobs: - release-on-push: + build: + name: SIFDECODE -- Release ${{ github.ref_name }} runs-on: ubuntu-latest - env: - GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} steps: - - uses: rymndhng/release-on-push-action@master - id: release + - name: Checkout SIFDECODE + uses: actions/checkout@v4 + - name: Install Julia + uses: julia-actions/setup-julia@v2 with: - # add a label to your pull request to change the default behavior: - # release:major - # release:minor - # release:patch - # norelease - bump_version_scheme: patch - tag_prefix: v - release_body: "" - use_github_release_notes: true - + version: 1 + arch: x64 + - name: Set the environment variables BINARYBUILDER_AUTOMATIC_APPLE, SIFDECODE_RELEASE, SIFDECODE_COMMIT + shell: bash + run: | + echo "BINARYBUILDER_AUTOMATIC_APPLE=true" >> $GITHUB_ENV + echo "SIFDECODE_RELEASE=${{ github.ref_name }}" >> $GITHUB_ENV + echo "SIFDECODE_COMMIT=${{ github.sha }}" >> $GITHUB_ENV + - name: Cross-compilation of SIFDECODE -- x86_64-linux-gnu-libgfortran5 + run: | + julia --color=yes -e 'using Pkg; Pkg.add("BinaryBuilder")' + julia --color=yes .github/julia/build_tarballs.jl x86_64-linux-gnu-libgfortran5 --verbose + rm -r ~/.julia + - name: Cross-compilation of SIFDECODE -- x86_64-w64-mingw32-libgfortran5 + run: | + julia --color=yes -e 'using Pkg; Pkg.add("BinaryBuilder")' + julia --color=yes .github/julia/build_tarballs.jl x86_64-w64-mingw32-libgfortran5 --verbose + rm -r ~/.julia + - name: Cross-compilation of SIFDECODE -- x86_64-apple-darwin-libgfortran5 + run: | + julia --color=yes -e 'using Pkg; Pkg.add("BinaryBuilder")' + julia --color=yes .github/julia/build_tarballs.jl x86_64-apple-darwin-libgfortran5 --verbose + rm -r ~/.julia + - name: Cross-compilation of SIFDECODE -- aarch64-apple-darwin-libgfortran5 + run: | + julia --color=yes -e 'using Pkg; Pkg.add("BinaryBuilder")' + julia --color=yes .github/julia/build_tarballs.jl aarch64-apple-darwin-libgfortran5 --verbose + rm -r ~/.julia + - name: Generate the binaries + run: julia --color=yes .github/julia/generate_binaries.jl + - name: Create a new release + uses: actions/create-release@v1 + id: create_release + with: + draft: false + prerelease: false + release_name: ${{ github.ref_name }} + tag_name: ${{ github.ref_name }} + body: + env: + GITHUB_TOKEN: ${{ github.token }} + - name: upload Linux artifact + uses: actions/upload-release-asset@v1 + env: + GITHUB_TOKEN: ${{ github.token }} + with: + upload_url: ${{ steps.create_release.outputs.upload_url }} + asset_path: ./SIFDECODE_binaries.${{ github.ref_name }}.x86_64-linux-gnu-libgfortran5.tar.gz + asset_name: SIFDECODE.${{ github.ref_name }}.linux.tar.gz + asset_content_type: application/gzip + - name: upload Mac (Intel) artifact + uses: actions/upload-release-asset@v1 + env: + GITHUB_TOKEN: ${{ github.token }} + with: + upload_url: ${{ steps.create_release.outputs.upload_url }} + asset_path: ./SIFDECODE_binaries.${{ github.ref_name }}.x86_64-apple-darwin-libgfortran5.tar.gz + asset_name: SIFDECODE.${{ github.ref_name }}.mac-intel.tar.gz + asset_content_type: application/gzip + - name: upload Mac (ARM) artifact + uses: actions/upload-release-asset@v1 + env: + GITHUB_TOKEN: ${{ github.token }} + with: + upload_url: ${{ steps.create_release.outputs.upload_url }} + asset_path: ./SIFDECODE_binaries.${{ github.ref_name }}.aarch64-apple-darwin-libgfortran5.tar.gz + asset_name: SIFDECODE.${{ github.ref_name }}.mac-arm.tar.gz + asset_content_type: application/gzip + - name: upload Windows artifact + uses: actions/upload-release-asset@v1 + env: + GITHUB_TOKEN: ${{ github.token }} + with: + upload_url: ${{ steps.create_release.outputs.upload_url }} + asset_path: ./SIFDECODE_binaries.${{ github.ref_name }}.x86_64-w64-mingw32-libgfortran5.zip + asset_name: SIFDECODE.${{ github.ref_name }}.windows.zip + asset_content_type: application/zip diff --git a/meson.build b/meson.build index ed4a9bc..588b27e 100644 --- a/meson.build +++ b/meson.build @@ -1,7 +1,7 @@ project( 'SIFDecode', 'fortran', - version: '2024.2.11', + version: '2.4.1', meson_version: '>= 0.61.0', default_options: [ 'buildtype=release',