Skip to content

Instantly share code, notes, and snippets.

@masakielastic
Last active December 2, 2025 03:34
Show Gist options
  • Select an option

  • Save masakielastic/7d4a573abf192b69f6f0efcefa6de74f to your computer and use it in GitHub Desktop.

Select an option

Save masakielastic/7d4a573abf192b69f6f0efcefa6de74f to your computer and use it in GitHub Desktop.
Fil-C で C 言語のコンパイル

Fil-C で C 言語のコンパイル

動作確認環境は Debian 12

バイナリの入手

次のツールが不足していたのでインストール

sudo apt install patchshelf

Github のリースから圧縮ファイルをダウンロードする。

tar Jxfv filc-0.675-linux-x86_64.tar.xz
cd filc-0.675-linux-x86_64
./setup.sh

C 言語のソースコードを用意する

#include <stdio.h>

int main() {
    printf("Hello from Fil-C!\n");
    return 0;
}

コンパイルする

build/bin/clang -O2 -g -o hello hello.c

nix

ビルドを避けるため、cachix をインストールします。

nix-env -iA cachix -f https://cachix.org/api/v1/install

パーミッションを設定する。

echo "trusted-users = root masakielastic" | sudo tee -a /etc/nix/nix.conf && sudo pkill nix-daemon

設定が反映されていることを確認する。

masakielastic@penguin:~$ cat /etc/nix/nix.conf

build-users-group = nixbld
experimental-features = nix-command flakes
trusted-users = root masakielastic

次のコマンドでインストールできる。

cachix use filc
nix profile add github:mbrock/filnix#filcc

環境を調べる。

masakielastic@penguin:~$ nix profile list
Name:               cachix
Store paths:        /nix/store/knc7ang3115l4xq0nl79pfl9xjrz2l7h-cachix-1.9.1-bin

Name:               devenv
Store paths:        /nix/store/xxlkhn30ndapab8740qhk6i0p3mq1zs0-devenv-1.11.2

Name:               filcc
Flake attribute:    packages.x86_64-linux.filcc
Original flake URL: github:mbrock/filnix
Locked flake URL:   github:mbrock/filnix/3df2d80703ea0335aa3cbe9601f4391b74a45ca2?narHash=sha256-20VVjK8CK5ZNDYMQweVtnVqzf6Ca3Lit8x5yHkMRdME%3D
Store paths:        /nix/store/dwmq57ih30j1wnpfrmdbf7fwnh201kjn-filc-cc-wrapper-
masakielastic@penguin:~$ clang -v
Fil-C 0.674 clang version 20.1.8
Target: x86_64-pc-linux-gnu
Thread model: posix
InstalledDir: /nix/store/i3lksm9i4l6hwhhgipxv1jkvjp9960ng-filc0-git/bin
Build config: +assertions
Found candidate GCC installation: /nix/store/kxm6wzygmj1439ylqdgyl9zqjgf10dy7-gcc-14.3.0/lib/gcc/x86_64-unknown-linux-gnu/14.3.0
Selected GCC installation: /nix/store/kxm6wzygmj1439ylqdgyl9zqjgf10dy7-gcc-14.3.0/lib/gcc/x86_64-unknown-linux-gnu/14.3.0
Candidate multilib: .;@m64
Selected multilib: .;@m64

cachix を導入せずに自前でビルドする場合、手元の Chromebook ではメモリ不足のため、エラーになってしまった。

[1/0/19 built, 0.0 MiB DL] building filc0-git (buildPhase): [B 1534/2957 3389.670s] /nix/store/602857s0iyn5ipzf35rn96x8pjf7q77Killed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment