Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

draft: package c2rust as a "nix flake" #440

Open
wants to merge 3 commits into
base: master
Choose a base branch
from

Conversation

mstone
Copy link

@mstone mstone commented Jun 10, 2022

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-linux at least due to support offline build #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.

@theduke
Copy link
Contributor

theduke commented Jun 16, 2022

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: #328 can be closed when this is merged.

@theduke
Copy link
Contributor

theduke commented Jun 16, 2022

@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

@milahu
Copy link
Contributor

milahu commented Jun 29, 2022

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

@HKalbasi
Copy link
Contributor

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?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants