← Back to list

Erlang VM から Zig を呼び出す

Bun という JavaScript ランタイムが Zig で書かれていたため、Zig に興味を持っています。

V · 2022-07-30 14:22 · 1 claps · 1.9 min read
#erlang #zig #rebar3
Open on Medium ↗
Wiki topics: 🌐 · Web Development

Erlang VM から Zig を呼び出す

Bun という JavaScript ランタイムが Zig で書かれていたため、Zig に興味を持っています。

自分たちの使い道としては Zig 単体で使うことはほとんどありませんが、Erlang VM から Zig を呼び出すということを想定しています。

なぜ Zig なのかは別記事にまとめていますので、興味があればどうぞ。

[embed]なぜ Zig の採用を検討しているのか かなり雑に書いてるので、雑に読んでください。voluntas.medium.com

rebar3 zig プラグイン

Erlang のビルドツールである rebar3 から zig をビルドして Erlang VM から読み込めるのを簡単にする rebar3 プラグインを公開しました。

[embed]GitHub - shiguredo/rebar3_zig: Rebar3 plugin to call Zig functions from Erlang using NIF Erlang から Zig で書かれたコードを利用可能にするための Rebar3 プラグインです。 内部では Erlang の NIF (Native Implemented Functions) という機能を利用しています。 We…github.com

const std = @import("std");

pub fn add(x: c_int, y: c_int) c_int {
    return x + y;
}

test "add" {
    try std.testing.expectEqual(add(1, 2), 3);
}

こんな感じの add 関数を erlang 側から呼び出すことが出来ます。

$ rebar3 shell
===> Verifying dependencies...
===> Analyzing applications...
===> Compiling zig_sample
Erlang/OTP 25 [erts-13.0.1] [source] [64-bit] [smp:10:10] [ds:10:10:10] [async-threads:1] [jit]
Eshell V13.0.1  (abort with ^G)
1> sample:add(1,2).
3

こんな感じで Erlang 経由で zig の add を呼び出せるようになります。

もし Erlang と Zig の両方に興味がある人がいたら、是非触ってみてください。


메타데이터
post_id
a6b15e31a655
slug
erlang-vm-から-zig-を呼び出す-a6b15e31a655
url
https://medium.com/@voluntas/erlang-vm-%E3%81%8B%E3%82%89-zig-%E3%82%92%E5%91%BC%E3%81%B3%E5%87%BA%E3%81%99-a6b15e31a655
canonical_url
https://medium.com/@voluntas/erlang-vm-%E3%81%8B%E3%82%89-zig-%E3%82%92%E5%91%BC%E3%81%B3%E5%87%BA%E3%81%99-a6b15e31a655
author_url
https://medium.com/@voluntas
status
ok
fetched_at
2026-07-26 19:44:40