我想要 extern "C"
I want extern "fil-C"

原始链接: https://domenkozar.com/2026/08/13/i-want-extern-fil-c/

Rust 当前的 C FFI 迫使开发者在内存安全的 Rust 和内存不安全的 C 之间做出危险的权衡,且不得不依赖难以强制执行的契约。为了解决这一问题,作者提出了一种用于 Rust 的新型“Fil-C”ABI。 Fil-C 通过功能(capabilities)和运行时检查重新编译 C/C++ 代码,将内存违规转换为 panic。通过将其集成到 Rust 中,开发者可以获得对遗留 C 库的“安全”访问。虽然这会引入性能开销(即“安全税”),但它也激励开发者将性能关键型代码迁移到 Rust,从而使检查转为静态,并消除这些开销。关键在于,这座桥梁必须维持 Fil-C 的“全系统”安全保证,且不能留下任何“Yolo-C”式的后门。 构建此方案需要跨生态系统的协作。相关基础设施正在涌现:`filnix` 提供了可重复的构建环境,Zig 也正在探索类似的内存安全 ABI 概念。作者展望了一个未来:C 将成为一条安全的兼容路径,而非天生危险的存在。为了实现这一愿景,作者呼吁 Rust、Fil-C、Zig 和 Nix 社区的开发者参加明年的 OceanSprint,共同设计这座桥梁。

Hacker News 最新 | 过往 | 评论 | 提问 | 展示 | 招聘 | 提交 登录 我想要 extern "fil-C" (domenkozar.com) 7 点,由 domenkozar 于 1 小时前发布 | 隐藏 | 过往 | 收藏 | 讨论 帮助 指南 | 常见问题 | 列表 | API | 安全 | 法律 | 申请 YC | 联系 搜索:
相关文章

原文

Rust’s C FFI gives us access to decades of useful software, but the bargain is backwards.

We use Rust to prove memory safety at compile time. Then we cross an unsafe boundary and trust the C library to respect a contract that neither language can enforce. The legacy code remains the cheap path, while rewriting it is the expensive one.

Fil-C offers a more interesting bargain. It recompiles C and C++ with capabilities, runtime checks, and a concurrent garbage collector. Memory-safety violations panic instead of becoming exploits. Existing software often needs few or no source changes, but it pays for safety at runtime.

I want a Rust FFI that speaks the Fil-C ABI.

The first version could be deliberately narrow: scalar values, copied strings and slices, and opaque handles. It would generate safe Rust wrappers, compile the complete C dependency graph with Fil-C, and provide no escape hatch back to ordinary unsafe C. Shared memory could come later, once the bridge can give Fil-C a capability that Rust can reliably revoke.

This is not a new option for bindgen. Fil-C is source-compatible with C but intentionally not ABI-compatible, and ordinary Rust extern "C" speaks the ABI Fil-C calls Yolo-C. Building the bridge means teaching Rust, Fil-C, or a pair of generated stubs how to exchange values without losing Fil-C’s guarantees. If it were easy, it would already exist.

One important part of this stack is already taking shape. filnix packages Fil-C as a Nix cross-compilation platform and has ports for more than 100 nixpkgs packages. Treating Fil-C as a platform means Nix rebuilds the transitive dependency closure for the Fil-C ABI instead of accidentally linking ordinary C into it. filnix is not the Rust bridge yet, but it provides the reproducible toolchain, package universe, and test bed where one could be built.

Zig is approaching the same problem from another direction. Andrew Kelley has proposed an optional fil ABI inspired by Fil-C. It would be an independent implementation in the Zig compiler and standard library, intended to compile a Zig program and its entire C and C++ dependency tree with runtime memory safety. That is remarkably close to the world a Rust bridge would need to enter.

But the result would give us exactly the right incentives.

We could use Rust for compile-time safety and then pay a performance penalty for using C.

Keep the legacy library and it remains memory-safe, but every pointer operation is checked and its memory participates in garbage collection. Rewrite the hot path in Rust and those checks become static, so the tax disappears. C becomes the safe compatibility path rather than the permanent fast path.

“100% safe” here means memory-safe across the whole supported boundary, not free of logic bugs, deadlocks, or bad APIs. That boundary is the hard part. Fil-C currently requires the whole program and its dependencies to use its ABI. The project also treats interoperability with ordinary C as a non-goal. A Rust bridge would have to preserve that whole-world guarantee rather than quietly punching a Yolo-shaped hole through it.

I want extern "fil-c": Rust on the fast path, old C on the safe path, and a performance reason to finish the migration.

I would also like to see cross-ecosystem collaboration instead of several almost-compatible islands. Fil-C has the capability model and working runtime. Rust has compile-time safety. Zig is exploring a Fil-C-inspired ABI. Nix and filnix can rebuild and test complete dependency graphs. This problem deserves the best minds from all four communities in the same room.

So here is the invitation: join us at OceanSprint next year in Lanzarote and build it together. Mikael Brockman, who is building filnix, has already accepted.

Who else is joining us?

联系我们 contact @ memedata.com