Skip to content

Commit a5710b6

Browse files
committed
Add precompilation workflow
1 parent 2b8f6f2 commit a5710b6

File tree

9 files changed

+164
-14
lines changed

9 files changed

+164
-14
lines changed

.github/workflows/release.yml

Lines changed: 110 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,110 @@
1+
name: Release
2+
on:
3+
push:
4+
tags:
5+
- "v*.*.*"
6+
permissions:
7+
contents: write
8+
jobs:
9+
linux:
10+
runs-on: ubuntu-20.04
11+
env:
12+
MIX_ENV: prod
13+
ELIXIR_VERSION: "1.15.3"
14+
strategy:
15+
matrix:
16+
otp_version: ["25.3"]
17+
name: Linux x86_64 (${{ matrix.otp_version }})
18+
steps:
19+
- uses: actions/checkout@v4
20+
- uses: erlef/setup-beam@v1
21+
with:
22+
otp-version: ${{ matrix.otp_version }}
23+
elixir-version: ${{ env.ELIXIR_VERSION }}
24+
- name: Install system dependecies
25+
run: |
26+
sudo apt-get update
27+
sudo apt-get install -y build-essential automake autoconf pkg-config bc m4 unzip zip \
28+
gcc g++ \
29+
gcc-i686-linux-gnu g++-i686-linux-gnu \
30+
gcc-aarch64-linux-gnu g++-aarch64-linux-gnu \
31+
gcc-arm-linux-gnueabihf g++-arm-linux-gnueabihf \
32+
gcc-riscv64-linux-gnu g++-riscv64-linux-gnu \
33+
gcc-powerpc64le-linux-gnu g++-powerpc64le-linux-gnu \
34+
gcc-s390x-linux-gnu g++-s390x-linux-gnu
35+
- name: Precompile
36+
run: |
37+
export ELIXIR_MAKE_CACHE_DIR=$(pwd)/cache
38+
mkdir -p "${ELIXIR_MAKE_CACHE_DIR}"
39+
mix deps.get
40+
mix elixir_make.precompile
41+
- uses: softprops/action-gh-release@v2
42+
if: startsWith(github.ref, 'refs/tags/')
43+
with:
44+
draft: true
45+
files: |
46+
cache/*.tar.gz
47+
cache/*.sha256
48+
49+
macos:
50+
runs-on: macos-13
51+
env:
52+
MIX_ENV: prod
53+
ELIXIR_VERSION: "1.15.3"
54+
strategy:
55+
matrix:
56+
otp_version: ["25.3"]
57+
name: macOS x86_64 (${{ matrix.otp_version }})
58+
steps:
59+
- uses: actions/checkout@v4
60+
- run: |
61+
curl -fsSO https://elixir-lang.org/install.sh
62+
sh install.sh elixir@${{ env.ELIXIR_VERSION }} otp@${{ matrix.otp_version }}
63+
otp_bin=($HOME/.elixir-install/installs/otp/*/bin)
64+
elixir_bin=($HOME/.elixir-install/installs/elixir/*/bin)
65+
echo "$otp_bin" >> "$GITHUB_PATH"
66+
echo "$elixir_bin" >> "$GITHUB_PATH"
67+
- name: Precompile
68+
run: |
69+
export ELIXIR_MAKE_CACHE_DIR=$(pwd)/cache
70+
mkdir -p "${ELIXIR_MAKE_CACHE_DIR}"
71+
mix deps.get
72+
mix elixir_make.precompile
73+
- uses: softprops/action-gh-release@v2
74+
if: startsWith(github.ref, 'refs/tags/')
75+
with:
76+
draft: true
77+
files: |
78+
cache/*.tar.gz
79+
cache/*.sha256
80+
81+
windows:
82+
runs-on: windows-2019
83+
env:
84+
MIX_ENV: prod
85+
ELIXIR_VERSION: "1.15.3"
86+
strategy:
87+
matrix:
88+
otp_version: ["25.3"]
89+
name: Windows x86_64 (${{ matrix.otp_version }})
90+
steps:
91+
- uses: actions/checkout@v4
92+
- uses: erlef/setup-beam@v1
93+
with:
94+
otp-version: ${{ matrix.otp_version }}
95+
elixir-version: ${{ env.ELIXIR_VERSION }}
96+
- uses: ilammy/msvc-dev-cmd@v1
97+
- name: Precompile
98+
shell: bash
99+
run: |
100+
export ELIXIR_MAKE_CACHE_DIR=$(pwd)/cache
101+
mkdir -p "${ELIXIR_MAKE_CACHE_DIR}"
102+
mix deps.get
103+
mix elixir_make.precompile
104+
- uses: softprops/action-gh-release@v2
105+
if: startsWith(github.ref, 'refs/tags/')
106+
with:
107+
draft: true
108+
files: |
109+
cache/*.tar.gz
110+
cache/*.sha256

.github/workflows/test.yml

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,10 @@
11
name: Test
2-
32
on:
43
pull_request:
54
push:
65
branches:
76
- main
87
- "v*.*"
9-
108
jobs:
119
linux:
1210
runs-on: ubuntu-20.04
@@ -28,7 +26,7 @@ jobs:
2826
env:
2927
MIX_ENV: test
3028
PYTHONX_TEST_PYTHON_MINOR: ${{ matrix.python_minor }}
31-
name: Linux (3.${{ matrix.python_minor }}, ${{ matrix.pair.elixir }}, ${{ matrix.pair.otp }})
29+
name: Linux x86_64 (3.${{ matrix.python_minor }}, ${{ matrix.pair.elixir }}, ${{ matrix.pair.otp }})
3230
steps:
3331
- uses: actions/checkout@v4
3432
- uses: erlef/setup-beam@v1
@@ -66,7 +64,7 @@ jobs:
6664
env:
6765
MIX_ENV: test
6866
PYTHONX_TEST_PYTHON_MINOR: ${{ matrix.python_minor }}
69-
name: Windows (3.${{ matrix.python_minor }}, ${{ matrix.pair.elixir }}, ${{ matrix.pair.otp }})
67+
name: Windows x86_64 (3.${{ matrix.python_minor }}, ${{ matrix.pair.elixir }}, ${{ matrix.pair.otp }})
7068
steps:
7169
- uses: actions/checkout@v4
7270
- uses: erlef/setup-beam@v1
@@ -99,7 +97,7 @@ jobs:
9997
env:
10098
MIX_ENV: test
10199
PYTHONX_TEST_PYTHON_MINOR: ${{ matrix.python_minor }}
102-
name: macOS (3.${{ matrix.python_minor }}, ${{ matrix.pair.elixir }}, ${{ matrix.pair.otp }})
100+
name: macOS x86_64 (3.${{ matrix.python_minor }}, ${{ matrix.pair.elixir }}, ${{ matrix.pair.otp }})
103101
steps:
104102
- uses: actions/checkout@v4
105103
- run: |

.gitignore

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,3 +21,6 @@ pythonx-*.tar
2121

2222
# Temporary files, for example, from tests.
2323
/tmp/
24+
25+
# Checksums for precompile binaries.
26+
/checksum.exs

CHANGELOG.md

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
# Changelog
2+
3+
All notable changes to this project will be documented in this file.
4+
5+
The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/).
6+
7+
## [v0.3.0](https://github.com/livebook-dev/pythonx/tree/v0.3.0) (Unreleased)
8+
9+
Initial release.
10+
11+
## Previous versions
12+
13+
Prior to v0.3, this package was being published and developed in [this repository](https://github.com/elixir-pythonx/pythonx).

Makefile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,4 +30,4 @@ build: $(NIF_PATH)
3030

3131
$(NIF_PATH): $(SOURCES) $(HEADERS)
3232
@ mkdir -p $(PRIV_DIR)
33-
$(CC) $(CPPFLAGS) $(SOURCES) -o $(NIF_PATH)
33+
$(CXX) $(CPPFLAGS) $(SOURCES) -o $(NIF_PATH)

README.md

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -166,6 +166,15 @@ For more details refer to the official documentation on
166166

167167
<!-- Docs -->
168168

169+
## Release
170+
171+
1. Update version in `mix.exs` and update CHANGELOG.
172+
2. Run `git tag x.y.z` and `git push --tags`.
173+
1. Wait for CI to precompile all artifacts.
174+
3. Run `mix elixir_make.checksum --all`.
175+
4. Run `mix hex.publish`.
176+
5. Bump version in `mix.exs` and add `-dev`.
177+
169178
## Acknowledgement
170179

171180
Thank you to Cocoa Xu (@cocoa-xu) for building the first prototype of

c_src/pythonx/pythonx.cpp

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -205,12 +205,6 @@ void raise_if_failed(ErlNifEnv *env, const char *buffer) {
205205
}
206206
}
207207

208-
void raise_if_failed(ErlNifEnv *env, int result) {
209-
if (result == -1) {
210-
raise_py_error(env);
211-
}
212-
}
213-
214208
void raise_if_failed(ErlNifEnv *env, Py_ssize_t size) {
215209
if (size == -1) {
216210
raise_py_error(env);

mix.exs

Lines changed: 24 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,15 +5,27 @@ end
55
defmodule Pythonx.MixProject do
66
use Mix.Project
77

8+
@version "0.3.0-dev"
9+
@description "Python interpreter embedded in Elixir"
10+
@github_url "https://github.com/livebook-dev/pythonx"
11+
812
def project do
913
[
1014
app: :pythonx,
11-
version: "0.3.0",
15+
version: @version,
1216
elixir: "~> 1.15",
17+
name: "Pythonx",
18+
description: @description,
1319
start_permanent: Mix.env() == :prod,
1420
deps: deps(),
1521
compilers: [:elixir_make] ++ Mix.compilers(),
16-
docs: &docs/0
22+
docs: docs(),
23+
package: package(),
24+
# Precompilation
25+
make_precompiler: {:nif, CCPrecompiler},
26+
make_precompiler_url: "#{@github_url}/releases/download/v#{@version}/@{artefact_filename}",
27+
make_precompiler_filename: "libpythonx",
28+
make_precompiler_nif_versions: [versions: ["2.16"]]
1729
]
1830
end
1931

@@ -27,11 +39,21 @@ defmodule Pythonx.MixProject do
2739
defp deps do
2840
[
2941
{:elixir_make, "~> 0.9", runtime: false},
42+
{:cc_precompiler, "~> 0.1", runtime: false},
3043
{:ex_doc, "~> 0.36", only: :dev, runtime: false}
3144
]
3245
end
3346

3447
defp docs() do
3548
[]
3649
end
50+
51+
defp package do
52+
[
53+
licenses: ["Apache-2.0"],
54+
links: %{"GitHub" => @github_url},
55+
files:
56+
~w(c_src lib mix.exs README.md LICENSE CHANGELOG.md Makefile Makefile.win checksum.exs)
57+
]
58+
end
3759
end

mix.lock

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
%{
2+
"cc_precompiler": {:hex, :cc_precompiler, "0.1.10", "47c9c08d8869cf09b41da36538f62bc1abd3e19e41701c2cea2675b53c704258", [:mix], [{:elixir_make, "~> 0.7", [hex: :elixir_make, repo: "hexpm", optional: false]}], "hexpm", "f6e046254e53cd6b41c6bacd70ae728011aa82b2742a80d6e2214855c6e06b22"},
23
"earmark_parser": {:hex, :earmark_parser, "1.4.42", "f23d856f41919f17cd06a493923a722d87a2d684f143a1e663c04a2b93100682", [:mix], [], "hexpm", "6915b6ca369b5f7346636a2f41c6a6d78b5af419d61a611079189233358b8b8b"},
34
"elixir_make": {:hex, :elixir_make, "0.9.0", "6484b3cd8c0cee58f09f05ecaf1a140a8c97670671a6a0e7ab4dc326c3109726", [:mix], [], "hexpm", "db23d4fd8b757462ad02f8aa73431a426fe6671c80b200d9710caf3d1dd0ffdb"},
45
"ex_doc": {:hex, :ex_doc, "0.36.1", "4197d034f93e0b89ec79fac56e226107824adcce8d2dd0a26f5ed3a95efc36b1", [:mix], [{:earmark_parser, "~> 1.4.42", [hex: :earmark_parser, repo: "hexpm", optional: false]}, {:makeup_c, ">= 0.1.0", [hex: :makeup_c, repo: "hexpm", optional: true]}, {:makeup_elixir, "~> 0.14 or ~> 1.0", [hex: :makeup_elixir, repo: "hexpm", optional: false]}, {:makeup_erlang, "~> 0.1 or ~> 1.0", [hex: :makeup_erlang, repo: "hexpm", optional: false]}, {:makeup_html, ">= 0.1.0", [hex: :makeup_html, repo: "hexpm", optional: true]}], "hexpm", "d7d26a7cf965dacadcd48f9fa7b5953d7d0cfa3b44fa7a65514427da44eafd89"},

0 commit comments

Comments
 (0)