Skip to content

Commit b66d9a0

Browse files
authored
added precompilation support (#234)
1 parent 6a6bae0 commit b66d9a0

File tree

4 files changed

+120
-2
lines changed

4 files changed

+120
-2
lines changed

.github/workflows/precompile.yml

Lines changed: 88 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,88 @@
1+
name: precompile
2+
3+
on:
4+
push:
5+
tags:
6+
- 'v*'
7+
8+
permissions:
9+
contents: write
10+
11+
jobs:
12+
precompile:
13+
runs-on: ${{ matrix.os }}
14+
env:
15+
MIX_ENV: "prod"
16+
17+
name: Precompile for Elixir ${{ matrix.elixir }}, OTP ${{ matrix.otp }}, OS ${{ matrix.os }}
18+
strategy:
19+
fail-fast: false
20+
matrix:
21+
os: ["ubuntu-20.04", "windows-2019", "macos-11"]
22+
elixir: ["1.14"]
23+
otp: ["25", "23"]
24+
exclude:
25+
- os: "windows-2019"
26+
otp: "23"
27+
steps:
28+
- uses: actions/checkout@v3
29+
- uses: erlef/setup-beam@v1
30+
if: matrix.os != 'macos-11'
31+
with:
32+
otp-version: ${{ matrix.otp }}
33+
elixir-version: ${{ matrix.elixir }}
34+
- name: Install erlang and elixir
35+
if: matrix.os == 'macos-11'
36+
run: |
37+
if [ "${{ matrix.otp }}" = "23" ]; then
38+
brew install "erlang@${{ matrix.otp }}"
39+
brew link --overwrite "erlang@${{ matrix.otp }}"
40+
41+
export ELIXIR_VER=1.14.3
42+
mkdir -p "${HOME}/.elixir/v${ELIXIR_VER}"
43+
cd "${HOME}/.elixir/v${ELIXIR_VER}"
44+
wget "https://github.com/elixir-lang/elixir/releases/download/v${ELIXIR_VER}/elixir-otp-${{ matrix.otp }}.zip" -O "elixir-${ELIXIR_VER}.zip"
45+
unzip "elixir-${ELIXIR_VER}.zip"
46+
rm -f "elixir-${ELIXIR_VER}.zip"
47+
export PATH="${HOME}/.elixir/v${ELIXIR_VER}/bin:${PATH}"
48+
else
49+
brew install erlang elixir
50+
fi
51+
mix local.hex --force
52+
mix local.rebar --force
53+
54+
- uses: ilammy/msvc-dev-cmd@v1
55+
if: matrix.os == 'windows-2019'
56+
with:
57+
arch: x64
58+
59+
- name: Install system dependencies
60+
if: matrix.os == 'ubuntu-20.04'
61+
run: |
62+
sudo apt-get update
63+
sudo apt-get install -y build-essential automake autoconf pkg-config bc m4 unzip zip \
64+
gcc g++ \
65+
gcc-i686-linux-gnu g++-i686-linux-gnu \
66+
gcc-aarch64-linux-gnu g++-aarch64-linux-gnu \
67+
gcc-arm-linux-gnueabihf g++-arm-linux-gnueabihf \
68+
gcc-riscv64-linux-gnu g++-riscv64-linux-gnu \
69+
gcc-powerpc64le-linux-gnu g++-powerpc64le-linux-gnu \
70+
gcc-s390x-linux-gnu g++-s390x-linux-gnu
71+
72+
- name: Create precompiled library
73+
shell: bash
74+
run: |
75+
if [ "${{ matrix.os }}" = "macos-11" ]; then
76+
export ELIXIR_VER=1.14.3
77+
export PATH="${HOME}/.elixir/v${ELIXIR_VER}/bin:${PATH}"
78+
fi
79+
export ELIXIR_MAKE_CACHE_DIR=$(pwd)/cache
80+
mkdir -p "${ELIXIR_MAKE_CACHE_DIR}"
81+
mix deps.get
82+
mix elixir_make.precompile
83+
84+
- uses: softprops/action-gh-release@v1
85+
if: startsWith(github.ref, 'refs/tags/')
86+
with:
87+
files: |
88+
cache/*.tar.gz

.gitignore

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,8 @@
44
/doc/
55
/.fetch
66

7+
checksum.exs
8+
79
erl_crash.dump
810
*.ez
911

mix.exs

Lines changed: 28 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,15 @@ defmodule Exqlite.MixProject do
1212
compilers: [:elixir_make] ++ Mix.compilers(),
1313
make_targets: ["all"],
1414
make_clean: ["clean"],
15+
make_precompiler: make_precompiler(),
16+
make_precompiler_url:
17+
"https://github.com/elixir-sqlite/exqlite/releases/download/v#{@version}/@{artefact_filename}",
18+
make_precompiler_filename: "sqlite3_nif",
19+
make_precompiler_nif_versions: [
20+
versions: ["2.15", "2.16"],
21+
availability: &target_available_for_nif_version?/2
22+
],
23+
cc_precompiler: [cleanup: "clean"],
1524
start_permanent: Mix.env() == :prod,
1625
aliases: aliases(),
1726
deps: deps(),
@@ -43,7 +52,8 @@ defmodule Exqlite.MixProject do
4352
[
4453
{:db_connection, "~> 2.1"},
4554
{:ex_sqlean, "~> 0.8.5", only: [:dev, :test]},
46-
{:elixir_make, "~> 0.6", runtime: false},
55+
{:elixir_make, "~> 0.7", runtime: false},
56+
{:cc_precompiler, "~> 0.1", runtime: false},
4757
{:ex_doc, "~> 0.27", only: :dev, runtime: false},
4858
{:temp, "~> 0.4", only: [:dev, :test]},
4959
{:credo, "~> 1.6", only: [:dev, :test], runtime: false},
@@ -62,6 +72,22 @@ defmodule Exqlite.MixProject do
6272
"An Elixir SQLite3 library"
6373
end
6474

75+
defp make_precompiler do
76+
if System.get_env("EXQLITE_USE_SYSTEM") != nil do
77+
nil
78+
else
79+
{:nif, CCPrecompiler}
80+
end
81+
end
82+
83+
def target_available_for_nif_version?(target, nif_version) do
84+
if String.contains?(target, "windows") do
85+
nif_version == "2.16"
86+
else
87+
true
88+
end
89+
end
90+
6591
defp package do
6692
[
6793
files: ~w(
@@ -73,6 +99,7 @@ defmodule Exqlite.MixProject do
7399
.clang-format
74100
c_src
75101
Makefile*
102+
checksum.exs
76103
),
77104
name: "exqlite",
78105
licenses: ["MIT"],

mix.lock

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,12 @@
11
%{
22
"bunt": {:hex, :bunt, "0.2.1", "e2d4792f7bc0ced7583ab54922808919518d0e57ee162901a16a1b6664ef3b14", [:mix], [], "hexpm", "a330bfb4245239787b15005e66ae6845c9cd524a288f0d141c148b02603777a5"},
3+
"cc_precompiler": {:hex, :cc_precompiler, "0.1.5", "ac3ef86f31ab579b856192a948e956cc3e4bb5006e303c4ab4b24958108e218a", [:mix], [{:elixir_make, "~> 0.7.3", [hex: :elixir_make, repo: "hexpm", optional: false]}], "hexpm", "ee5b2e56eb03798231a3d322579fff509139a534ef54205d04c188e18cab1f57"},
34
"connection": {:hex, :connection, "1.1.0", "ff2a49c4b75b6fb3e674bfc5536451607270aac754ffd1bdfe175abe4a6d7a68", [:mix], [], "hexpm", "722c1eb0a418fbe91ba7bd59a47e28008a189d47e37e0e7bb85585a016b2869c"},
45
"credo": {:hex, :credo, "1.6.7", "323f5734350fd23a456f2688b9430e7d517afb313fbd38671b8a4449798a7854", [:mix], [{:bunt, "~> 0.2.1", [hex: :bunt, repo: "hexpm", optional: false]}, {:file_system, "~> 0.2.8", [hex: :file_system, repo: "hexpm", optional: false]}, {:jason, "~> 1.0", [hex: :jason, repo: "hexpm", optional: false]}], "hexpm", "41e110bfb007f7eda7f897c10bf019ceab9a0b269ce79f015d54b0dcf4fc7dd3"},
56
"db_connection": {:hex, :db_connection, "2.4.2", "f92e79aff2375299a16bcb069a14ee8615c3414863a6fef93156aee8e86c2ff3", [:mix], [{:connection, "~> 1.0", [hex: :connection, repo: "hexpm", optional: false]}, {:telemetry, "~> 0.4 or ~> 1.0", [hex: :telemetry, repo: "hexpm", optional: false]}], "hexpm", "4fe53ca91b99f55ea249693a0229356a08f4d1a7931d8ffa79289b145fe83668"},
67
"dialyxir": {:hex, :dialyxir, "1.1.0", "c5aab0d6e71e5522e77beff7ba9e08f8e02bad90dfbeffae60eaf0cb47e29488", [:mix], [{:erlex, ">= 0.2.6", [hex: :erlex, repo: "hexpm", optional: false]}], "hexpm", "07ea8e49c45f15264ebe6d5b93799d4dd56a44036cf42d0ad9c960bc266c0b9a"},
78
"earmark_parser": {:hex, :earmark_parser, "1.4.29", "149d50dcb3a93d9f3d6f3ecf18c918fb5a2d3c001b5d3305c926cddfbd33355b", [:mix], [], "hexpm", "4902af1b3eb139016aed210888748db8070b8125c2342ce3dcae4f38dcc63503"},
8-
"elixir_make": {:hex, :elixir_make, "0.6.3", "bc07d53221216838d79e03a8019d0839786703129599e9619f4ab74c8c096eac", [:mix], [], "hexpm", "f5cbd651c5678bcaabdbb7857658ee106b12509cd976c2c2fca99688e1daf716"},
9+
"elixir_make": {:hex, :elixir_make, "0.7.5", "784cc00f5fa24239067cc04d449437dcc5f59353c44eb08f188b2b146568738a", [:mix], [{:castore, "~> 0.1", [hex: :castore, repo: "hexpm", optional: true]}], "hexpm", "c3d63e8d5c92fa3880d89ecd41de59473fa2e83eeb68148155e25e8b95aa2887"},
910
"erlex": {:hex, :erlex, "0.2.6", "c7987d15e899c7a2f34f5420d2a2ea0d659682c06ac607572df55a43753aa12e", [:mix], [], "hexpm", "2ed2e25711feb44d52b17d2780eabf998452f6efda104877a3881c2f8c0c0c75"},
1011
"ex_doc": {:hex, :ex_doc, "0.29.0", "4a1cb903ce746aceef9c1f9ae8a6c12b742a5461e6959b9d3b24d813ffbea146", [:mix], [{:earmark_parser, "~> 1.4.19", [hex: :earmark_parser, repo: "hexpm", optional: false]}, {:makeup_elixir, "~> 0.14", [hex: :makeup_elixir, repo: "hexpm", optional: false]}, {:makeup_erlang, "~> 0.1", [hex: :makeup_erlang, repo: "hexpm", optional: false]}], "hexpm", "f096adb8bbca677d35d278223361c7792d496b3fc0d0224c9d4bc2f651af5db1"},
1112
"ex_sqlean": {:hex, :ex_sqlean, "0.8.8", "be03d0aa4ee2955b59b386743ccaccbf0cc56f9635f701f185fe2d962b2ab214", [:mix], [], "hexpm", "de3644787ee736880597886decdf86f104c1778398401615c37d1ec4563146fa"},

0 commit comments

Comments
 (0)