Skip to content

Commit 82616ec

Browse files
authored
Merge pull request #3 from haubie/precompiled
Precompiled release
2 parents eb75d62 + c72809d commit 82616ec

File tree

11 files changed

+288
-54
lines changed

11 files changed

+288
-54
lines changed

.github/workflows/release.yml

Lines changed: 91 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ on:
44
push:
55
branches:
66
- main
7+
# - precompiled
78
paths:
89
# Just run on main branch if "native" path changed.
910
- "native/**"
@@ -22,17 +23,16 @@ jobs:
2223
matrix:
2324
nif: ["2.15"]
2425
job:
25-
- { target: arm-unknown-linux-gnueabihf , os: ubuntu-20.04 , use-cross: true }
26-
- { target: aarch64-unknown-linux-gnu , os: ubuntu-20.04 , use-cross: true }
27-
- { target: aarch64-unknown-linux-musl , os: ubuntu-20.04 , use-cross: true }
2826
- { target: aarch64-apple-darwin , os: macos-11 }
29-
- { target: riscv64gc-unknown-linux-gnu , os: ubuntu-20.04 , use-cross: true }
3027
- { target: x86_64-apple-darwin , os: macos-11 }
31-
- { target: x86_64-unknown-linux-gnu , os: ubuntu-20.04 }
32-
- { target: x86_64-unknown-linux-musl , os: ubuntu-20.04 , use-cross: true }
33-
- { target: x86_64-pc-windows-gnu , os: windows-2019 }
28+
- { target: x86_64-unknown-linux-gnu , os: ubuntu-20.04 , apt: musl-tools alsa-utils alsa-tools libasound2-dev libudev-dev pkg-config portaudio19-dev build-essential libpulse-dev libdbus-1-dev llvm-dev libclang-dev clang }
29+
- { target: x86_64-unknown-linux-musl , os: ubuntu-20.04 , apt: musl-tools alsa-utils alsa-tools libasound2-dev libudev-dev pkg-config portaudio19-dev build-essential libpulse-dev libdbus-1-dev llvm-dev libclang-dev clang }
30+
- { target: aarch64-unknown-linux-gnu , os: ubuntu-22.04 , arch: aarch64 , apt: "libasound2-dev:arm64 pkg-config libgcc-s1:arm64 libc6:arm64 gcc-aarch64-linux-gnu build-essential crossbuild-essential-arm64" }
31+
- { target: aarch64-unknown-linux-musl , os: ubuntu-22.04 , arch: aarch64 , apt: "musl-tools libasound2-dev:arm64 pkg-config libgcc-s1:arm64 libc6:arm64 gcc-aarch64-linux-gnu build-essential crossbuild-essential-arm64" }
32+
- { target: riscv64gc-unknown-linux-gnu , os: ubuntu-22.04 , arch: riscv64 , apt: "wget gcc-riscv64-linux-gnu libc6-riscv64-cross crossbuild-essential-riscv64 libasound2-dev:riscv64 pkg-config" }
33+
- { target: x86_64-pc-windows-gnu , os: windows-2022 }
3434
- { target: x86_64-pc-windows-msvc , os: windows-2019 }
35-
- { target: x86_64-unknown-freebsd , os: ubuntu-22.04, use-cross: true }
35+
# 32 bit cross compiling not working - { target: arm-unknown-linux-gnueabihf , arch: armhf , os: ubuntu-latest , apt: "libatomic1:armhf libasound2-dev:armhf libudev-dev:armhf pkg-config build-essential crossbuild-essential-armhf" }
3636

3737
steps:
3838
- name: Checkout source code
@@ -44,6 +44,88 @@ jobs:
4444
# Get the project version from mix.exs
4545
echo "PROJECT_VERSION=$(sed -n 's/^ @version "\(.*\)"/\1/p' mix.exs | head -n1)" >> $GITHUB_ENV
4646
47+
- name: "Patch azure archives for [amd64, i386] use only"
48+
if: contains(fromJSON('["macos", "ubuntu"]'), matrix.job.os)
49+
shell: bash
50+
run: |
51+
sudo sed -i'' -E 's/^(deb|deb-src) http:\/\/(archive|azure.archive|security).ubuntu.com/\1 [arch=amd64,i386] http:\/\/\2.ubuntu.com/' /etc/apt/sources.list
52+
53+
- name: Set architecture for package manager
54+
if: ${{ matrix.job.arch }}
55+
continue-on-error: true
56+
shell: bash
57+
run: |
58+
# sudo apt-get clean
59+
# sudo apt-get autoclean
60+
# sudo rm -rf /var/lib/apt/lists/
61+
sudo apt-get update -y
62+
sudo dpkg --add-architecture arm64
63+
sudo dpkg --add-architecture ${{ matrix.job.arch }}
64+
# echo "deb [arch=arm64,riscv64,amd64] http://mirror.aarnet.edu.au/pub/ubuntu/ports/ jammy main" | sudo tee -a /etc/apt/sources.list
65+
# echo "deb [arch=arm64,riscv64,amd64] http://mirror.aarnet.edu.au/pub/ubuntu/ports/ jammy-updates main" | sudo tee -a /etc/apt/sources.list
66+
# echo "deb [arch=arm64,riscv64,amd64] http://mirror.aarnet.edu.au/pub/ubuntu/ports/ jammy universe" | sudo tee -a /etc/apt/sources.list
67+
# echo "deb [arch=arm64,riscv64,amd64] http://mirror.aarnet.edu.au/pub/ubuntu/ports/ jammy-updates universe" | sudo tee -a /etc/apt/sources.list
68+
# echo "deb [arch=arm64,riscv64,amd64] http://mirror.aarnet.edu.au/pub/ubuntu/ports/ jammy-security main restricted" | sudo tee -a /etc/apt/sources.list
69+
# echo "deb [arch=arm64,riscv64,amd64] http://mirror.aarnet.edu.au/pub/ubuntu/ports/ jammy-security universe" | sudo tee -a /etc/apt/sources.list
70+
# echo "deb [arch=arm64,riscv64,amd64] http://mirror.aarnet.edu.au/pub/ubuntu/ports/ jammy-security multiverse" | sudo tee -a /etc/apt/sources.list
71+
echo "deb [arch=arm64,riscv64,armhf] http://ports.ubuntu.com/ubuntu-ports/ jammy main restricted universe" | sudo tee -a /etc/apt/sources.list
72+
echo "deb [arch=arm64,riscv64,armhf] http://ports.ubuntu.com/ubuntu-ports/ jammy-updates main restricted universe" | sudo tee -a /etc/apt/sources.list
73+
echo "deb [arch=arm64,riscv64,armhf] http://ports.ubuntu.com/ubuntu-ports/ jammy-backports main restricted universe" | sudo tee -a /etc/apt/sources.list
74+
echo "deb [arch=arm64,riscv64,armhf] http://ports.ubuntu.com/ubuntu-ports/ jammy-security main restricted universe" | sudo tee -a /etc/apt/sources.list
75+
sudo apt-get update
76+
# sudo apt --fix-broken install
77+
78+
- name: Print apt sources
79+
if: contains(fromJSON('["macos", "ubuntu"]'), matrix.job.os)
80+
shell: bash
81+
run: cat /etc/apt/sources.list
82+
83+
- name: List architectures
84+
if: contains(fromJSON('["macos", "ubuntu"]'), matrix.job.os)
85+
shell: bash
86+
run: |
87+
sudo dpkg --print-architecture
88+
sudo dpkg --print-foreign-architectures
89+
90+
- name: Install additional apt packages
91+
if: ${{ matrix.job.apt }}
92+
continue-on-error: true
93+
shell: bash
94+
run: sudo apt install ${{ matrix.job.apt }}
95+
96+
# - name: Print /lib/riscv64-linux-gnu directory
97+
# shell: bash
98+
# run: ls /lib/riscv64-linux-gnu
99+
100+
- name: Install RISCV build tools
101+
if: ${{ matrix.job.arch == 'riscv64' }}
102+
shell: bash
103+
run: |
104+
# Download RISCV build tools precompile packaged from https://github.com/riscv-collab/riscv-gnu-toolchain/releases/
105+
wget -P ~/Downloads/ https://github.com/riscv-collab/riscv-gnu-toolchain/releases/download/2023.07.07/riscv64-glibc-ubuntu-22.04-gcc-nightly-2023.07.07-nightly.tar.gz
106+
# Unzip it /opt
107+
tar -xvzf ~/Downloads/riscv64-glibc-ubuntu-22.04-gcc-nightly-2023.07.07-nightly.tar.gz -C /opt/
108+
echo PATH="/opt/riscv/bin/:$PATH" >> $GITHUB_ENV
109+
110+
# - name: Install additional apt packages
111+
# if: ${{ matrix.job.apt }}
112+
# uses: awalsh128/cache-apt-pkgs-action@latest
113+
# with:
114+
# packages: ${{ matrix.job.apt }}
115+
# version: 1.0
116+
117+
# - name: Add to the package path
118+
# shell: bash
119+
# run: echo "PKG_CONFIG_PATH=$(find /usr/lib/ -name alsa.pc -print | head -1 | xargs -0 dirname):/usr/lib/pkgconfig:$PKG_CONFIG_PATH" >> $GITHUB_ENV
120+
- name: PKG_CONFIG_PATH package path
121+
if: contains(fromJSON('["macos", "ubuntu"]'), matrix.job.os)
122+
shell: bash
123+
run: |
124+
echo $PKG_CONFIG_PATH
125+
echo $PATH
126+
which riscv64-unknown-linux-gnu-gcc
127+
whereis riscv64-unknown-linux-gnu-gcc
128+
47129
- name: Install Rust toolchain
48130
uses: dtolnay/rust-toolchain@stable
49131
with:
@@ -72,4 +154,4 @@ jobs:
72154
with:
73155
files: |
74156
${{ steps.build-crate.outputs.file-path }}
75-
if: startsWith(github.ref, 'refs/tags/')
157+
if: startsWith(github.ref, 'refs/tags/')

BUILDING.md

Lines changed: 29 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,34 @@
33
[![Documentation](http://img.shields.io/badge/hex.pm-docs-green.svg?style=flat)](https://hexdocs.pm/midiex)
44
[![Package](https://img.shields.io/hexpm/v/supercollider.svg)](https://hex.pm/packages/midiex)
55

6+
## Precompiled binaries
7+
Since v0.6, Midiex uses [Rustler Precompiled](https://dashbit.co/blog/rustler-precompiled) to provide precompiled binaries on the following platforms:
8+
9+
- Apple Mac:
10+
- M-series: aarch64-apple-darwin
11+
- x86-series: x86_64-apple-darwin
12+
- Linux x86 based:
13+
- x86_64-unknown-linux-gnu
14+
- x86_64-unknown-linux-musl
15+
- Linux ARM based:
16+
- aarch64-unknown-linux-gnu
17+
- aarch64-unknown-linux-musl
18+
- Linux RISC-V based:
19+
- riscv64gc-unknown-linux-gnu
20+
- Windows x86 based:
21+
- x86_64-pc-windows-msvc
22+
- x86_64-pc-windows-gnu
23+
24+
For the above platforms you should not need Rust's build tools as Rustler will download Midiex's precompiled NIF for the correct platform.
25+
26+
### Forcing compilation
27+
Should you wish to build your own binary of Midiex's Rust-based NIF on the above platforms, you can force that by setting the environmental `MIDIEX_BUILD` to `true` or `1`, e.g.:
28+
29+
```
30+
export MIDIEX_BUILD=true
31+
```
32+
You'll need to have the Rust build toolchain installed (see below).
33+
634
# Building Midiex
735
In most cases, the standard Rust build toolchain is all you need. That being said there may be additional packages that need to be installed on Linux distributions related to ALSA (Advanced Linux Sound Architecture) as well as compilation in general (pkg-config).
836

@@ -14,7 +42,4 @@ Additionally on Linux (currently tested on Ubuntu 22.04), you may need some addi
1442

1543
If using the apt package manager, you can install those via the terminal prompt with:
1644

17-
```sudo apt install libasound2-dev pkg-config.```
18-
19-
## Future - precompiled binaries
20-
It is a goal of this project to migrate to [Rustler Precompiled](https://dashbit.co/blog/rustler-precompiled) so that the rust build tools don't have to be installed and the precompiled binaries of Midiex's Rust-based NIF is downloaded for the correct platform.
45+
```sudo apt install libasound2-dev pkg-config.```

README.md

Lines changed: 24 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ Using WinRT or Jack requires special feature flags enabled. See the [midir GitHu
2222
The hot-plug support of MIDI devices on MacOS is made possible with with the Rust [coremidi](https://github.com/chris-zen/coremidi) library.
2323

2424
## Status
25-
This library is currently under active development and it’s API is likely to change. It's been tested on MacOS only.
25+
This library is currently under active development and it’s API is likely to change. It's been tested on MacOS only although it is currently building on Mac (M-series and x86), Linux (64-bit ARM, RISC-V and x86) and Windows (x86_64) with precompiled binary packages (see the Getting started section below).
2626

2727
## API
2828
At it's most basic level, the core functions of Midiex are for:
@@ -74,22 +74,42 @@ Midiex.send_msg(piano, note_off)
7474

7575
## Getting started
7676

77+
### Platforms with precompiled binaries
78+
Since v0.6, Midiex uses [Rustler Precompiled](https://dashbit.co/blog/rustler-precompiled) to provide precompiled binaries on the following platforms:
79+
80+
- Apple Mac:
81+
- M-series: aarch64-apple-darwin
82+
- x86-series: x86_64-apple-darwin
83+
- Linux x86 based:
84+
- x86_64-unknown-linux-gnu
85+
- x86_64-unknown-linux-musl
86+
- Linux ARM based:
87+
- aarch64-unknown-linux-gnu
88+
- aarch64-unknown-linux-musl
89+
- Linux RISC-V based:
90+
- riscv64gc-unknown-linux-gnu
91+
- Windows x86 based:
92+
- x86_64-pc-windows-msvc
93+
- x86_64-pc-windows-gnu
94+
95+
This means you shouldn't need the Rust build tools for the above plaforms. Just add midiex as a dependency to your Elixir file and Rustler will download and install the correct binary.
96+
7797
### Rust build tools
78-
If you don't already have Rust's build tools installed, you'll likely need to. See [BUILDING.md](BUILDING.md) for more information.
98+
If you want to use Midiex on a different platform than those listed above, or want to force complication, you'll need to have Rust's build tools installed. See [BUILDING.md](BUILDING.md) for more information.
7999

80100
### Adding it to your Elixir project
81101
The package can be installed by adding midiex to your list of dependencies in mix.exs:
82102
```
83103
def deps do
84104
[
85-
{:midiex, "~> 0.5.3"}
105+
{:midiex, "~> 0.6.0"}
86106
]
87107
End
88108
```
89109

90110
### Using within LiveBook and IEx
91111
```
92-
Mix.install([{:midiex, "~> 0.5.3"}])
112+
Mix.install([{:midiex, "~> 0.6.0"}])
93113
```
94114

95115
#### LiveBook tour

lib/midiex/backend.ex

Lines changed: 26 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -1,35 +1,34 @@
11
defmodule Midiex.Backend do
22
@moduledoc false
33

4-
use Rustler,
5-
otp_app: :midiex,
6-
crate: :midiex
4+
# use Rustler,
5+
# otp_app: :midiex,
6+
# crate: :midiex
77

8-
# mix_config = Mix.Project.config()
9-
# version = mix_config[:version]
10-
# github_url = mix_config[:package][:links]["GitHub"]
11-
# mode = if Mix.env() in [:dev, :test], do: :debug, else: :release
8+
mix_config = Mix.Project.config()
9+
version = mix_config[:version]
10+
github_url = mix_config[:package][:links]["GitHub"]
11+
mode = if Mix.env() in [:dev, :test], do: :debug, else: :release
1212

13-
# use RustlerPrecompiled,
14-
# otp_app: :midiex,
15-
# crate: :midiex,
16-
# version: version,
17-
# base_url: "#{github_url}/releases/download/v#{version}",
18-
# targets: ~w(
19-
# aarch64-apple-darwin
20-
# aarch64-unknown-linux-gnu
21-
# aarch64-unknown-linux-musl
22-
# riscv64gc-unknown-linux-gnu
23-
# x86_64-apple-darwin
24-
# x86_64-pc-windows-msvc
25-
# x86_64-pc-windows-gnu
26-
# x86_64-unknown-linux-gnu
27-
# x86_64-unknown-linux-musl
28-
# x86_64-unknown-freebsd
29-
# ),
30-
# nif_versions: ["2.15"],
31-
# mode: mode,
32-
# force_build: System.get_env("MIDIEX_BUILD") in ["1", "true"]
13+
use RustlerPrecompiled,
14+
otp_app: :midiex,
15+
crate: :midiex,
16+
version: version,
17+
base_url: "#{github_url}/releases/download/v#{version}",
18+
targets: ~w(
19+
aarch64-apple-darwin
20+
x86_64-apple-darwin
21+
x86_64-unknown-linux-gnu
22+
x86_64-unknown-linux-musl
23+
aarch64-unknown-linux-gnu
24+
aarch64-unknown-linux-musl
25+
riscv64gc-unknown-linux-gnu
26+
x86_64-pc-windows-msvc
27+
x86_64-pc-windows-gnu
28+
),
29+
nif_versions: ["2.15"],
30+
mode: mode,
31+
force_build: System.get_env("MIDIEX_BUILD") in ["1", "true"]
3332

3433
# ##########
3534
# NATIVE API

mix.exs

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,14 @@
11
defmodule Midiex.MixProject do
22
use Mix.Project
33

4+
@version "0.6.0"
5+
46
def project do
57
[
68
app: :midiex,
79
name: "Midiex",
810
description: "A cross-platform, realtime MIDI processing in Elixir library which wraps the midir Rust library.",
9-
version: "0.5.3",
11+
version: @version,
1012
elixir: "~> 1.14",
1113
start_permanent: Mix.env() == :prod,
1214
deps: deps(),
@@ -68,9 +70,9 @@ defmodule Midiex.MixProject do
6870
# Run "mix help deps" to learn about dependencies.
6971
defp deps do
7072
[
71-
# {:rustler_precompiled, "~> 0.6"},
72-
{:rustler, "~> 0.26.0"},
73-
# {:rustler, ">= 0.0.0", optional: true},
73+
{:rustler_precompiled, "~> 0.6"},
74+
{:rustler, "~> 0.26.0", optional: true},
75+
# {:rustler, "~> 0.26.0"},
7476
{:ex_doc, ">= 0.0.0", only: :dev, runtime: false}
7577
]
7678
end

native/midiex/.a.out.swp

16 KB
Binary file not shown.

0 commit comments

Comments
 (0)