Hacker News new | ask | show | jobs
by cb321 931 days ago
In a word, yes.

In more words: You should be able to use Cosmopolitan libc: https://github.com/Yardanico/cosmonim

If something does not work for you, Yardanico is super duper helpful in all things Nim.

Nim also compiles to Javascript (nim js) and C++ for integration with legacy codebases, but that is probably more to the side of your interests.

While I have never seen it done and always meant to give it a try, compiling to C should allow one to also do things like write Linux kernel modules in Nim without any special support from the Linux team.

1 comments

Nim has GC and runtime and Linux kernel developers do not allow third party runtimes in the kernel. Even meager Rust's "panic" runtime is a contentious issue. Can one disable runtime in Nim completely -- no GC, no exceptions?
> kernel developers do not allow third party runtimes in the kernel. Even meager Rust's "panic" runtime is a contentious

Much in Linux is contentious :-) which is why the module system is nice. A kernel module for C code requires no permission from Linux-core unless you need it distributed with the kernel (which, yes, might be required for "credibility" - but critically also might not). It may require many decls to access various kernel APIs, but those can be (semi-)automated or just done as-needed. So, Linux kernel policy is not so relevant (at best) which is what I meant by "no special support" (admittedly brief). Kernel coding is always a bit trickier, and you may need to build up some support code to make integration nice, though as well as decl generators (though none of that need be distributed "with Linux").

> Can one disable runtime in Nim completely -- no GC, no exceptions?

To answer your question, and as discussed elsewhere in this subthread, Nim has many options for memory management.. only stdlib seq/string really needs automatic methods. One can disable the runtime completely via os:standalone and statically check that no exceptions are raised with Nim's effect system (and there are also both setjmp & goto based exception impls which may/may not be workable in Linux/BSD kernel module settings).

As "proof more by example", a few people have written OS kernels in Nim recently[1,2] and there was another toy kernel long ago[3]. People have also written OS kernels in Go which "has a GC and runtime".[4] So, I acknowledge it's not quite the same example, but I also see no fundamental blockers for kernel modules.

[1] https://github.com/khaledh/axiom

[2] https://prosepoetrycode.potterpcs.net/2023/01/a-barebones-ke...

[3] https://github.com/dom96/nimkernel

[4] https://github.com/mit-pdos/biscuit/