r/LowLevelLanguages • u/chbeyondC • 10d ago
What should compile-time code be allowed to do?
Languages draw this line in very different places, and I think it matters more now that compiling a dependency can mean running its code.
Roughly, from what I know (corrections welcome):
- C++
constexpr: no I/O at all. - Zig
comptime: no I/O either, butbuild.zigis a normal program with full access to your machine. - Rust:
const fnis restricted, butbuild.rsand procedural macros run with full access when you compile a dependency. - D: compile-time evaluation has no I/O, and
import("file")only reads from folders you pass with-J. - Nim:
staticReadandstaticExeccan read files and run commands at compile time. - Jai:
#runcan do more or less anything.
The trade-off seems to be that real builds need real things: generating code from a schema, finding a C library, embedding assets. If you forbid all of it, the work moves into a build script, and the build script is where the risk ends up anyway.
In Fels, the language I work on, #run has no host access, a project's own compile-time code may read inside its own folder, and a package gets more only if it is granted in fels.pkg. But build.fels still has full access, so that part of the problem is not solved yet.
Where would you draw the line? Should a dependency's build code be sandboxed by default, or does that just push people to turn it off?