Skip to content

Commit 7373fdc

Browse files
committed
First commit
0 parents  commit 7373fdc

File tree

16 files changed

+614
-0
lines changed

16 files changed

+614
-0
lines changed

.formatter.exs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
# Used by "mix format"
2+
[
3+
inputs: ["{mix,.formatter}.exs", "{config,lib,test}/**/*.{ex,exs}"]
4+
]

.github/workflows/ci.yaml

Lines changed: 154 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,154 @@
1+
name: Build precompiled NIFs
2+
3+
env:
4+
NIF_DIRECTORY: "native/mjml"
5+
6+
on:
7+
push:
8+
branches:
9+
- main
10+
tags:
11+
- "*"
12+
13+
defaults:
14+
run:
15+
# Sets the working dir for "run" scripts.
16+
# Note that this won't change the directory for actions (tasks with "uses").
17+
working-directory: "./native/mjml"
18+
19+
jobs:
20+
build_release:
21+
name: NIF ${{ matrix.nif }} - ${{ matrix.job.target }} (${{ matrix.job.os }})
22+
runs-on: ${{ matrix.job.os }}
23+
strategy:
24+
fail-fast: false
25+
matrix:
26+
nif: ["2.16"]
27+
job:
28+
- {
29+
target: arm-unknown-linux-gnueabihf,
30+
os: ubuntu-20.04,
31+
use-cross: true,
32+
}
33+
- {
34+
target: aarch64-unknown-linux-gnu,
35+
os: ubuntu-20.04,
36+
use-cross: true,
37+
}
38+
# - { target: aarch64-apple-darwin, os: macos-11 }
39+
# - { target: x86_64-apple-darwin, os: macos-11 }
40+
- { target: x86_64-unknown-linux-gnu, os: ubuntu-20.04 }
41+
- {
42+
target: x86_64-unknown-linux-musl,
43+
os: ubuntu-20.04,
44+
use-cross: true,
45+
}
46+
# - { target: x86_64-pc-windows-gnu, os: windows-2019 }
47+
# - { target: x86_64-pc-windows-msvc, os: windows-2019 }
48+
49+
env:
50+
RUSTLER_NIF_VERSION: ${{ matrix.nif }}
51+
steps:
52+
- name: Checkout source code
53+
uses: actions/checkout@v2
54+
55+
- name: Install prerequisites
56+
shell: bash
57+
run: |
58+
case ${{ matrix.job.target }} in
59+
arm-unknown-linux-*) sudo apt-get -y update ; sudo apt-get -y install gcc-arm-linux-gnueabihf ;;
60+
aarch64-unknown-linux-gnu) sudo apt-get -y update ; sudo apt-get -y install gcc-aarch64-linux-gnu ;;
61+
esac
62+
- name: Extract crate information
63+
shell: bash
64+
run: |
65+
echo "PROJECT_NAME=$(sed -n 's/^name = "\(.*\)"/\1/p' Cargo.toml | head -n1)" >> $GITHUB_ENV
66+
# Get the project version from mix.exs
67+
echo "PROJECT_VERSION=$(sed -n 's/^ @version "\(.*\)"/\1/p' ../../mix.exs | head -n1)" >> $GITHUB_ENV
68+
- name: Install Rust toolchain
69+
uses: actions-rs/toolchain@v1
70+
with:
71+
toolchain: stable
72+
target: ${{ matrix.job.target }}
73+
override: true
74+
profile: minimal
75+
76+
- name: Show version information (Rust, cargo, GCC)
77+
shell: bash
78+
run: |
79+
gcc --version || true
80+
rustup -V
81+
rustup toolchain list
82+
rustup default
83+
cargo -V
84+
rustc -V
85+
rustc --print=cfg
86+
- name: Download cross from GitHub releases
87+
uses: giantswarm/install-binary-action@v1.0.0
88+
if: ${{ matrix.job.use-cross }}
89+
with:
90+
binary: "cross"
91+
version: "v0.2.2"
92+
download_url: "https://github.com/cross-rs/cross/releases/download/${version}/cross-x86_64-unknown-linux-gnu.tar.gz"
93+
tarball_binary_path: "${binary}"
94+
smoke_test: "${binary} --version"
95+
96+
- name: Build
97+
shell: bash
98+
run: |
99+
if [ "${{ matrix.job.use-cross }}" == "true" ]; then
100+
cross build --release --target=${{ matrix.job.target }}
101+
else
102+
cargo build --release --target=${{ matrix.job.target }}
103+
fi
104+
- name: Rename lib to the final name
105+
id: rename
106+
shell: bash
107+
run: |
108+
LIB_PREFIX="lib"
109+
case ${{ matrix.job.target }} in
110+
*-pc-windows-*) LIB_PREFIX="" ;;
111+
esac;
112+
# Figure out suffix of lib
113+
# See: https://doc.rust-lang.org/reference/linkage.html
114+
LIB_SUFFIX=".so"
115+
case ${{ matrix.job.target }} in
116+
*-apple-darwin) LIB_SUFFIX=".dylib" ;;
117+
*-pc-windows-*) LIB_SUFFIX=".dll" ;;
118+
esac;
119+
CICD_INTERMEDIATES_DIR=$(mktemp -d)
120+
# Setup paths
121+
LIB_DIR="${CICD_INTERMEDIATES_DIR}/released-lib"
122+
mkdir -p "${LIB_DIR}"
123+
LIB_NAME="${LIB_PREFIX}${{ env.PROJECT_NAME }}${LIB_SUFFIX}"
124+
LIB_PATH="${LIB_DIR}/${LIB_NAME}"
125+
# Copy the release build lib to the result location
126+
cp "target/${{ matrix.job.target }}/release/${LIB_NAME}" "${LIB_DIR}"
127+
# Final paths
128+
# In the end we use ".so" for MacOS in the final build
129+
# See: https://www.erlang.org/doc/man/erlang.html#load_nif-2
130+
LIB_FINAL_SUFFIX="${LIB_SUFFIX}"
131+
case ${{ matrix.job.target }} in
132+
*-apple-darwin) LIB_FINAL_SUFFIX=".so" ;;
133+
esac;
134+
LIB_FINAL_NAME="${LIB_PREFIX}${PROJECT_NAME}-v${PROJECT_VERSION}-nif-${RUSTLER_NIF_VERSION}-${{ matrix.job.target }}${LIB_FINAL_SUFFIX}"
135+
# Copy lib to final name on this directory
136+
cp "${LIB_PATH}" "${LIB_FINAL_NAME}"
137+
tar -cvzf "${LIB_FINAL_NAME}.tar.gz" "${LIB_FINAL_NAME}"
138+
# Passes the path relative to the root of the project.
139+
LIB_FINAL_PATH="${NIF_DIRECTORY}/${LIB_FINAL_NAME}.tar.gz"
140+
# Let subsequent steps know where to find the lib
141+
echo ::set-output name=LIB_FINAL_PATH::${LIB_FINAL_PATH}
142+
echo ::set-output name=LIB_FINAL_NAME::${LIB_FINAL_NAME}.tar.gz
143+
- name: "Artifact upload"
144+
uses: actions/upload-artifact@v2
145+
with:
146+
name: ${{ steps.rename.outputs.LIB_FINAL_NAME }}
147+
path: ${{ steps.rename.outputs.LIB_FINAL_PATH }}
148+
149+
- name: Publish archives and packages
150+
uses: softprops/action-gh-release@v1
151+
with:
152+
files: |
153+
${{ steps.rename.outputs.LIB_FINAL_PATH }}
154+
if: startsWith(github.ref, 'refs/tags/')

.gitignore

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
# The directory Mix will write compiled artifacts to.
2+
/_build/
3+
4+
# If you run "mix test --cover", coverage assets end up here.
5+
/cover/
6+
7+
# The directory Mix downloads your dependencies sources to.
8+
/deps/
9+
10+
# Where third-party dependencies like ExDoc output generated docs.
11+
/doc/
12+
13+
# Ignore .fetch files in case you like to edit your project deps locally.
14+
/.fetch
15+
16+
# If the VM crashes, it generates a dump, let's ignore it too.
17+
erl_crash.dump
18+
19+
# Also ignore archive artifacts (built via "mix archive.build").
20+
*.ez
21+
22+
# Ignore package tarball (built via "mix hex.build").
23+
rustler_mjml-*.tar
24+
25+
# Temporary files, for example, from tests.
26+
/tmp/
27+
28+
.elixir_ls

README.md

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
# RustlerMjml
2+
3+
**TODO: Add description**
4+
5+
## Installation
6+
7+
If [available in Hex](https://hex.pm/docs/publish), the package can be installed
8+
by adding `rustler_mjml` to your list of dependencies in `mix.exs`:
9+
10+
```elixir
11+
def deps do
12+
[
13+
{:rustler_mjml, "~> 0.1.0"}
14+
]
15+
end
16+
```
17+
18+
Documentation can be generated with [ExDoc](https://github.com/elixir-lang/ex_doc)
19+
and published on [HexDocs](https://hexdocs.pm). Once published, the docs can
20+
be found at <https://hexdocs.pm/rustler_mjml>.
21+

lib/rustler_mjml.ex

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
defmodule RustlerMjml do
2+
use Rustler, otp_app: :rustler_mjml, crate: "mjml"
3+
4+
def to_html(_a), do: :erlang.nif_error(:nif_not_loaded)
5+
end

mix.exs

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
defmodule RustlerMjml.MixProject do
2+
use Mix.Project
3+
4+
def project do
5+
[
6+
app: :rustler_mjml,
7+
version: "0.1.0",
8+
elixir: "~> 1.13",
9+
start_permanent: Mix.env() == :prod,
10+
deps: deps()
11+
]
12+
end
13+
14+
# Run "mix help compile.app" to learn about applications.
15+
def application do
16+
[
17+
extra_applications: [:logger]
18+
]
19+
end
20+
21+
# Run "mix help deps" to learn about dependencies.
22+
defp deps do
23+
[
24+
{:rustler, "~> 0.25"}
25+
]
26+
end
27+
end

mix.lock

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
%{
2+
"jason": {:hex, :jason, "1.3.0", "fa6b82a934feb176263ad2df0dbd91bf633d4a46ebfdffea0c8ae82953714946", [:mix], [{:decimal, "~> 1.0 or ~> 2.0", [hex: :decimal, repo: "hexpm", optional: true]}], "hexpm", "53fc1f51255390e0ec7e50f9cb41e751c260d065dcba2bf0d08dc51a4002c2ac"},
3+
"rustler": {:hex, :rustler, "0.25.0", "32526b51af7e58a740f61941bf923486ce6415a91c3934cc16c281aa201a2240", [:mix], [{:jason, "~> 1.0", [hex: :jason, repo: "hexpm", optional: false]}, {:toml, "~> 0.6", [hex: :toml, repo: "hexpm", optional: false]}], "hexpm", "6b43a11a37fe79c6234d88c4102ab5dfede7a6a764dc5c7b539956cfa02f3cf4"},
4+
"toml": {:hex, :toml, "0.6.2", "38f445df384a17e5d382befe30e3489112a48d3ba4c459e543f748c2f25dd4d1", [:mix], [], "hexpm", "d013e45126d74c0c26a38d31f5e8e9b83ea19fc752470feb9a86071ca5a672fa"},
5+
}

native/mjml/.cargo/config

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
[target.'cfg(target_os = "macos")']
2+
rustflags = [
3+
"-C", "link-arg=-undefined",
4+
"-C", "link-arg=dynamic_lookup",
5+
]

native/mjml/.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
/target

0 commit comments

Comments
 (0)