Skip to content

Nix refactor #1285

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
wants to merge 5 commits into
base: master
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -52,3 +52,6 @@ inspect/
*.rs.fixed
analysis.txt
polonius_cache/

# Nix output symlinks
result*
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ For example, the official LLVM packages from [apt.llvm.org](https://apt.llvm.org
- **NixOS / nix:**

```sh
nix-shell
nix shell github:immunant/c2rust
```

- **macOS:** Xcode command-line tools and recent LLVM (we recommend the Homebrew version) are required.
Expand Down
30 changes: 11 additions & 19 deletions default.nix
Original file line number Diff line number Diff line change
@@ -1,22 +1,14 @@
final: prev:
let
nixpkgs = import <nixpkgs> { };
inherit (nixpkgs) pkgs llvmPackages;
stdenv = pkgs.clangStdenv;
# Get rust-overlay from the flake.lock file
rustNodes = (builtins.fromJSON (builtins.readFile ./flake.lock)).nodes.rust-overlay.locked;
rust-overlay = final.fetchFromGitHub {
inherit (rustNodes) owner repo rev;
hash = rustNodes.narHash;
};

overlain = final.extend (import rust-overlay);
in
stdenv.mkDerivation {
name = "c2rust";
buildInputs = [
pkgs.clang
pkgs.cmake
pkgs.llvm
pkgs.libllvm
pkgs.openssl
pkgs.pkgconfig
pkgs.python3
pkgs.rustup
pkgs.zlib
];
LIBCLANG_PATH = "${pkgs.libclang.lib}/lib";
CMAKE_LLVM_DIR = "${llvmPackages.libllvm.dev}/lib/cmake/llvm";
CMAKE_CLANG_DIR = "${llvmPackages.libclang.dev}/lib/cmake/clang";
{
c2rust = overlain.callPackage ./nix { };
}
149 changes: 23 additions & 126 deletions flake.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

96 changes: 33 additions & 63 deletions flake.nix
Original file line number Diff line number Diff line change
Expand Up @@ -2,75 +2,45 @@
description = "Flake for c2rust";

inputs = {
nixpkgs.url = "github:NixOS/nixpkgs/nixos-23.11";
utils.url = "github:numtide/flake-utils";
fenix = {
url = "github:nix-community/fenix";
};
oxalica = {
url = "github:oxalica/rust-overlay";
};
nixpkgs.url = "https://nixos.org/channels/nixos-unstable/nixexprs.tar.xz";
flake-utils.url = "github:numtide/flake-utils";
rust-overlay.url = "github:oxalica/rust-overlay/snapshot/2024-08-01";
rust-overlay.inputs.nixpkgs.follows = "nixpkgs";
};

outputs = inputs@{ self, nixpkgs, utils, fenix, oxalica}:
utils.lib.eachDefaultSystem (system:
let
fenixStable = fenix.packages.${system}.fromToolchainFile {
file = ./rust-toolchain.toml;
sha256 = "sha256-r/8YBFuFa4hpwgE3FnME7nQA2Uc1uqj0eCE1NWmI1u0";
};
outputs =
{
self,
nixpkgs,
flake-utils,
rust-overlay,
}:
flake-utils.lib.eachDefaultSystem (
system:
let
pkgs = import nixpkgs {
inherit system;
overlays = [
(import oxalica)
(import rust-overlay)
(import self)
];
config = {
allowUnfree = true;
};
};
in {
defaultPackage = self.devShell.${system};
devShell = pkgs.mkShell.override { } {
in
{
packages = {
default = pkgs.c2rust;
unwrapped = pkgs.c2rust.unwrapped;
};

overlays = import self;

LIBCLANG_PATH = "${pkgs.llvmPackages_14.libclang.lib}/lib";
CMAKE_LLVM_DIR = "${pkgs.llvmPackages_14.libllvm.dev}/lib/cmake/llvm";
CMAKE_CLANG_DIR = "${pkgs.llvmPackages_14.libclang.dev}/lib/cmake/clang";
shellHook = ''
export CARGO_TARGET_DIR="$(git rev-parse --show-toplevel)/target_dirs/nix_rustc";
'';
RUST_SRC_PATH = pkgs.rustPlatform.rustLibSrc;
buildInputs =
with pkgs; [
clangStdenv.cc
llvmPackages_14.libclang
pkg-config
fenix.packages.${system}.rust-analyzer
llvmPackages_14.clang
cmake
llvmPackages_14.llvm
llvmPackages_14.libllvm
openssl
(python3.withPackages
(python-pkgs:
with python-pkgs;
[ "bencode-python3"
cbor
colorlog
mako
pip
plumbum
psutil
pygments
typing
"scan-build"
pyyaml
toml
]
)
)
zlib
(rust-bin.fromRustupToolchainFile ./rust-toolchain.toml)
];
};
});
devShells.default = pkgs.callPackage ./shell.nix { };

formatter = pkgs.nixfmt-tree;
checks = {
inherit (pkgs) c2rust;
devShell = self.devShells.${system}.default;
};
}
);
}
28 changes: 28 additions & 0 deletions nix/default.nix
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
{
lib,
runCommand,
callPackage,
makeBinaryWrapper,
llvmPackages,
}:
let
c2rust = callPackage ./package.nix { };
in
runCommand "c2rust-${c2rust.version}"
{
inherit (c2rust) version meta;
nativeBuildInputs = [
makeBinaryWrapper
];

passthru.unwrapped = c2rust;
}
''
makeWrapper ${lib.getExe c2rust} "$out/bin/c2rust" \
--prefix PATH : ${
lib.makeBinPath [
c2rust.toolchain
llvmPackages.libllvm
]
}
''
Loading