diff --git a/.github/workflows/linux-precompile.yml b/.github/workflows/linux-precompile.yml new file mode 100644 index 0000000..62b6b62 --- /dev/null +++ b/.github/workflows/linux-precompile.yml @@ -0,0 +1,76 @@ +name: linux-precompile + +on: + push: + tags: + - 'v*' + +permissions: + contents: write + +jobs: + precompile: + runs-on: ubuntu-20.04 + env: + MIX_ENV: prod + strategy: + matrix: + arch: + - x86_64 + - aarch64 + - riscv64 + job: + - {otp: "27", elixir: "1.17"} + - {otp: "25", elixir: "1.16"} + + name: Linux ${{ matrix.arch }} - OTP ${{ matrix.job.otp }} - Elixir ${{ matrix.job.elixir }} + steps: + - name: Checkout + uses: actions/checkout@v4 + + - uses: erlef/setup-beam@v1 + with: + otp-version: ${{ matrix.job.otp }} + elixir-version: ${{ matrix.job.elixir }} + + - name: Install system dependecies + run: | + sudo apt-get update + sudo apt-get install -y \ + build-essential automake autoconf pkg-config \ + bc m4 unzip zip gcc g++ + + - name: Install x86_64 specific deps + if: matrix.arch == 'x86_64' + run: | + sudo apt-get install -y gcc-i686-linux-gnu g++-i686-linux-gnu \ + gcc-arm-linux-gnueabihf g++-arm-linux-gnueabihf \ + gcc-powerpc64le-linux-gnu g++-powerpc64le-linux-gnu \ + gcc-s390x-linux-gnu g++-s390x-linux-gnu + + - name: Install aarch64 specific deps + if: matrix.arch == 'aarch64' + run: sudo apt-get install -y gcc-aarch64-linux-gnu g++-aarch64-linux-gnu + + - name: Install riscv64 specific deps + if: matrix.arch == 'riscv64' + run: sudo apt-get install -y gcc-riscv64-linux-gnu g++-riscv64-linux-gnu + + - name: Get musl ${{ matrix.arch }} cross-compilers + run: | + wget "https://musl.cc/${{matrix.arch}}-linux-musl-cross.tgz" -O "${{matrix.arch}}-linux-musl-cross.tgz" + tar -xf "${{matrix.arch}}-linux-musl-cross.tgz" + + - name: Create precompiled ${{ matrix.arch }} library + run: | + export PATH="$(pwd)/${{ matrix.arch }}-linux-musl-cross/bin:${PATH}" + export ELIXIR_MAKE_CACHE_DIR=$(pwd)/cache + mkdir -p "${ELIXIR_MAKE_CACHE_DIR}" + mix deps.get + mix elixir_make.precompile + + - uses: softprops/action-gh-release@v1 + if: startsWith(github.ref, 'refs/tags/') + with: + files: | + cache/*.tar.gz diff --git a/.github/workflows/macos-precompile.yml b/.github/workflows/macos-precompile.yml new file mode 100644 index 0000000..27323a9 --- /dev/null +++ b/.github/workflows/macos-precompile.yml @@ -0,0 +1,78 @@ +name: macos-precompile + +on: + push: + tags: + - 'v*' + +permissions: + contents: write + +jobs: + precompile: + runs-on: macos-14 + env: + MIX_ENV: prod + strategy: + matrix: + arch: + - x86_64-apple-darwin + - arm64-apple-darwin + job: + - {otp: "27.0.1", elixir: "1.17.2"} + - {otp: "25.3.2.13", elixir: "1.16.3"} + + name: Mac ${{ matrix.arch }} - OTP ${{ matrix.job.otp }} - Elixir ${{ matrix.job.elixir }} + steps: + - name: Checkout + uses: actions/checkout@v4 + + - name: Install asdf + uses: asdf-vm/actions/setup@v2 + + - name: Cache asdf + id: asdf-cache + uses: actions/cache@v3 + with: + path: ~/.asdf + key: asdf-${{ runner.os }}-build-${{ matrix.job.otp }}-${{ matrix.job.elixir }} + + - if: ${{ steps.asdf-cache.outputs.cache-hit != 'true' }} + name: Install Erlang & Elixir + env: + ELIXIR_VERSION: ${{ matrix.job.elixir }} + OTP_VERSION: ${{ matrix.job.otp }} + run: | + asdf plugin-add erlang + asdf install erlang ${OTP_VERSION} + + ELIXIR_OTP_VERSION=$(echo $OTP_VERSION | cut -d. -f1) + asdf plugin-add elixir + asdf install elixir ${ELIXIR_VERSION}-otp-${ELIXIR_OTP_VERSION} + + - name: Setup Erlang & Elixir + env: + ELIXIR_VERSION: ${{ matrix.job.elixir }} + OTP_VERSION: ${{ matrix.job.otp }} + run: | + asdf global erlang ${OTP_VERSION} + ELIXIR_OTP_VERSION=$(echo $OTP_VERSION | cut -d. -f1) + asdf global elixir ${ELIXIR_VERSION}-otp-${ELIXIR_OTP_VERSION} + + - name: Install hex & rebar + run: | + mix local.hex --force + mix local.rebar --force + + - name: Pre-compile NIF library + run: | + export ELIXIR_MAKE_CACHE_DIR=$(pwd)/cache + mkdir -p "${ELIXIR_MAKE_CACHE_DIR}" + mix deps.get + mix elixir_make.precompile + + - uses: softprops/action-gh-release@v1 + if: startsWith(github.ref, 'refs/tags/') + with: + files: | + cache/*.tar.gz diff --git a/.github/workflows/precompile.yml b/.github/workflows/precompile.yml deleted file mode 100644 index 4521432..0000000 --- a/.github/workflows/precompile.yml +++ /dev/null @@ -1,105 +0,0 @@ -name: precompile - -on: - push: - tags: - - 'v*' - -permissions: - contents: write - -jobs: - precompile: - runs-on: ${{ matrix.job.os }} - env: - MIX_ENV: "prod" - - name: Precompile for Elixir ${{ matrix.job.elixir }}, OTP ${{ matrix.job.otp }}, OS ${{ matrix.job.os }} - strategy: - fail-fast: false - matrix: - job: - - { os: "ubuntu-20.04", otp: "23", elixir: "1.14" } - - { os: "macos-11", otp: "24.3.4.16", elixir: "1.14.3"} - - { os: "windows-2019", otp: "25", elixir: "1.14"} - steps: - - uses: actions/checkout@v3 - - uses: erlef/setup-beam@v1 - if: matrix.job.os != 'macos-11' - with: - otp-version: ${{ matrix.job.otp }} - elixir-version: ${{ matrix.job.elixir }} - - name: Install erlang and elixir - if: matrix.job.os == 'macos-11' - run: | - export ROOT_DIR=$(pwd) - - mkdir -p ./cache/otp - curl -fSL https://github.com/cocoa-xu/otp-build/releases/download/v${{ matrix.job.otp }}/otp-x86_64-apple-darwin.tar.gz -o ./cache/otp/otp-v${{ matrix.job.otp }}-x86_64-apple-darwin.tar.gz - cd ./cache/otp - tar -xzf otp-v${{ matrix.job.otp }}-x86_64-apple-darwin.tar.gz - cd ${ROOT_DIR} - - export PATH=$(pwd)/cache/otp/usr/local/bin:$(pwd)/./cache/elixir/elixir-${{ matrix.job.elixir }}/bin:${PATH} - export ERL_ROOTDIR=$(pwd)/cache/otp/usr/local/lib/erlang - - mkdir -p ./cache/elixir - curl -fSL https://github.com/elixir-lang/elixir/archive/refs/tags/v${{ matrix.job.elixir }}.tar.gz -o ./cache/elixir/elixir-${{ matrix.job.elixir }}.tar.gz - cd ./cache/elixir - tar -xzf elixir-${{ matrix.job.elixir }}.tar.gz - cd elixir-${{ matrix.job.elixir }} - make compile - make -j$(sysctl -n hw.ncpu) install - - mix local.hex --force - mix local.rebar --force - - - uses: ilammy/msvc-dev-cmd@v1 - if: matrix.job.os == 'windows-2019' - with: - arch: x64 - - - name: Install system dependencies - if: matrix.job.os == 'ubuntu-20.04' - run: | - sudo apt-get update - sudo apt-get install -y build-essential automake autoconf pkg-config bc m4 unzip zip wget \ - gcc g++ \ - gcc-i686-linux-gnu g++-i686-linux-gnu \ - gcc-aarch64-linux-gnu g++-aarch64-linux-gnu \ - gcc-arm-linux-gnueabihf g++-arm-linux-gnueabihf \ - gcc-riscv64-linux-gnu g++-riscv64-linux-gnu \ - gcc-powerpc64le-linux-gnu g++-powerpc64le-linux-gnu \ - gcc-s390x-linux-gnu g++-s390x-linux-gnu - - - name: Get musl cross-compilers - if: matrix.job.os == 'ubuntu-20.04' - run: | - for musl_arch in x86_64 aarch64 riscv64 - do - wget "https://musl.cc/${musl_arch}-linux-musl-cross.tgz" -O "${musl_arch}-linux-musl-cross.tgz" - tar -xf "${musl_arch}-linux-musl-cross.tgz" - done - - - name: Create precompiled library - shell: bash - run: | - if [ "${{ matrix.job.os }}" = "macos-11" ]; then - export PATH=$(pwd)/cache/otp/usr/local/bin:$(pwd)/./cache/elixir/elixir-${{ matrix.job.elixir }}/bin:${PATH} - export ERL_ROOTDIR=$(pwd)/cache/otp/usr/local/lib/erlang - elif [ "${{ matrix.job.os }}" = "ubuntu-20.04" ]; then - for musl_arch in x86_64 aarch64 riscv64 - do - export PATH="$(pwd)/${musl_arch}-linux-musl-cross/bin:${PATH}" - done - fi - export ELIXIR_MAKE_CACHE_DIR=$(pwd)/cache - mkdir -p "${ELIXIR_MAKE_CACHE_DIR}" - mix deps.get - mix elixir_make.precompile - - - uses: softprops/action-gh-release@v1 - if: startsWith(github.ref, 'refs/tags/') - with: - files: | - cache/*.tar.gz diff --git a/.github/workflows/windows-precompile.yml b/.github/workflows/windows-precompile.yml new file mode 100644 index 0000000..e39ba9b --- /dev/null +++ b/.github/workflows/windows-precompile.yml @@ -0,0 +1,50 @@ +name: windows-precompile + +on: + push: + tags: + - 'v*' + +permissions: + contents: write + +jobs: + precompile: + runs-on: windows-2019 + env: + MIX_ENV: prod + strategy: + matrix: + arch: + - x64 + job: + - {otp: "27", elixir: "1.17"} + - {otp: "25", elixir: "1.14"} + + name: Windows ${{ matrix.arch }} - OTP ${{ matrix.job.otp }} - Elixir ${{ matrix.job.elixir }} + steps: + - name: Checkout + uses: actions/checkout@v4 + + - uses: erlef/setup-beam@v1 + with: + otp-version: ${{ matrix.job.otp }} + elixir-version: ${{ matrix.job.elixir }} + + - uses: ilammy/msvc-dev-cmd@v1 + with: + arch: ${{ matrix.arch }} + + - name: Pre-compile NIF library + shell: bash + run: | + export ELIXIR_MAKE_CACHE_DIR=$(pwd)/cache + mkdir -p "${ELIXIR_MAKE_CACHE_DIR}" + mix deps.get + mix elixir_make.precompile + + - uses: softprops/action-gh-release@v1 + if: startsWith(github.ref, 'refs/tags/') + with: + files: | + cache/*.tar.gz diff --git a/.gitignore b/.gitignore index 38ecf04..061ca3f 100644 --- a/.gitignore +++ b/.gitignore @@ -20,3 +20,6 @@ exqlite-*.tar # Temporary files for example tests /tmp *.db + +# Let the local developer choose +.tool-versions diff --git a/.tool-versions b/.tool-versions deleted file mode 100644 index ce0360e..0000000 --- a/.tool-versions +++ /dev/null @@ -1,2 +0,0 @@ -erlang 27.0.1 -elixir 1.17.2-otp-27 diff --git a/mix.exs b/mix.exs index 27abc29..491c720 100644 --- a/mix.exs +++ b/mix.exs @@ -17,12 +17,7 @@ defmodule Exqlite.MixProject do make_precompiler_url: "https://github.com/elixir-sqlite/exqlite/releases/download/v#{@version}/@{artefact_filename}", make_precompiler_filename: "sqlite3_nif", - make_precompiler_nif_versions: [ - versions: &nif_versions/1, - fallback_version: fn opts -> - hd(nif_versions(opts)) - end - ], + make_precompiler_nif_versions: make_precompiler_nif_versions(), make_env: Application.get_env(:exqlite, :make_env, %{}), cc_precompiler: cc_precompiler(), start_permanent: Mix.env() == :prod, @@ -136,13 +131,10 @@ defmodule Exqlite.MixProject do ] end - defp nif_versions(opts) do - if String.contains?(opts.target, "windows") or - String.contains?(opts.target, "darwin") do - ["2.16"] - else - ["2.15"] - end + def make_precompiler_nif_versions do + [ + versions: ["2.16", "2.17"] + ] end defp cc_precompiler do