draft: package c2rust as a "nix flake"
Nix flakes are an emerging technology for composing software which solves a related but complementary problem to the one addressed today via c2rust's shell.nix/nix-shell support.
This PR provides a rough-draft-quality flake for c2rust. Notable future work includes:
- testing. So far, I have only tested it on
aarch64-darwin, where it works as expected so far, and is able to transpile and run the demo for my current subject of interest, osqp. - wider platform support. While untested so far, I expect builds to fail on
x86_64-linuxat least due to #356.
The benefit is that flakes enable easy building, development, and usage of c2rust with pinned, shareable, but still easily editable LLVM, clang, and rust toolchain versions via convenient commands like
-
nix build -
nix shell - etc.
or with URI-like "flake-refs" (which also support naming specific branches/commits/...) like:
-
nix build github:mstone/c2rust, -
nix shell github:mstone/c2rust, -
nix run github:mstone/c2rust, or -
nix profile install github:mstone/c2rust
or their upstream equivalents, if merged.
Great to see this.
I would recommend not committing the flake.lock in the repo and leave the nixpkgs dependency as ephemeral so you don't have to do nix shell --no-write-lock-file --recreate-lock-file github:mstone/c2rust to avoid pulling in a whole separate set of nix packages.
ps: https://github.com/immunant/c2rust/pull/328 can be closed when this is merged.
@mstone building currently fails because the build tries to download some dependencies.
status_string: "Couldn't resolve host name"
log:
--- LOG BEGIN ---
Could not resolve host: github.com
Closing connection 0
--- LOG END ---
error: downloading 'https://github.com/intel/tinycbor/archive/v0.5.3.tar.gz' failed
status_code: 6
status_string: "Couldn't resolve host name"
log:
--- LOG BEGIN ---
Could not resolve host: github.com
Closing connection 0
--- LOG END ---
error: downloading 'https://github.com/intel/tinycbor/archive/v0.5.3.tar.gz' failed
status_code: 6
status_string: "Couldn't resolve host name"
log:
--- LOG BEGIN ---
Could not resolve host: github.com
Closing connection 0
--- LOG END ---
error: downloading 'https://github.com/intel/tinycbor/archive/v0.5.3.tar.gz' failed
status_code: 6
status_string: "Couldn't resolve host name"
log:
--- LOG BEGIN ---
Could not resolve host: github.com
Closing connection 0
--- LOG END ---
make[3]: *** [CMakeFiles/tinycbor_build.dir/build.make:98: tinycbor/src/tinycbor_build-stamp/tinycbor_build-download] Error 1
make[2]: *** [CMakeFiles/Makefile2:91: CMakeFiles/tinycbor_build.dir/all] Error 2
make[1]: *** [CMakeFiles/Makefile2:254: CMakeFiles/clangAstExporter.dir/rule] Error 2
make: *** [Makefile:202: clangAstExporter] Error 2
thread 'main' panicked at '
command did not execute successfully, got: exit status: 2
fwiw, my c2rust.nix draft from 2 months ago i had to set some envs so the builder would find clang and llvm i used tinycbor from nix as shown in #356
The current shell.nix doesn't work for me (#1045), neither the flake included in this PR.
Does anyone in this thread knows how to build c2rust on nix?