Skip to content
Open
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
12 changes: 11 additions & 1 deletion c2rust-ast-exporter/build.rs
Original file line number Diff line number Diff line change
Expand Up @@ -149,8 +149,18 @@ fn build_native(llvm_info: &LLVMInfo) {
}
};

// Statically link against 'clangAstExporter' which requires 'tinycbor'
// Use a custom tinybor directory via an environment variable
if let Ok(tinycbor_dir) = env::var("TINYCBOR_DIR") {
let include_dir = Path::new(&tinycbor_dir).join("include");
let lib_dir = Path::new(&tinycbor_dir).join("lib");

println!("cargo:rustc-link-search=native={}", lib_dir.display());
println!("cargo:rerun-if-changed={}", include_dir.display());
}

println!("cargo:rustc-link-lib=static=tinycbor");

// Statically link against 'clangAstExporter' which requires 'tinycbor'
println!("cargo:rustc-link-lib=static=clangAstExporter");

println!("cargo:rustc-link-search=native={}", llvm_lib_dir);
Expand Down
119 changes: 18 additions & 101 deletions flake.lock

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

117 changes: 83 additions & 34 deletions flake.nix
Original file line number Diff line number Diff line change
Expand Up @@ -2,54 +2,69 @@
description = "Flake for c2rust";

inputs = {
nixpkgs.url = "github:NixOS/nixpkgs/nixos-23.11";
nixpkgs.url = "github:NixOS/nixpkgs/nixos-unstable";
utils.url = "github:numtide/flake-utils";
fenix = {
url = "github:nix-community/fenix";
};
oxalica = {
url = "github:oxalica/rust-overlay";
inputs.nixpkgs.follows = "nixpkgs";
};
};

outputs = inputs@{ self, nixpkgs, utils, fenix, oxalica}:
outputs = inputs@{ self, nixpkgs, utils, fenix}:
utils.lib.eachDefaultSystem (system:
let
fenixStable = fenix.packages.${system}.fromToolchainFile {
file = ./rust-toolchain.toml;
sha256 = "sha256-r/8YBFuFa4hpwgE3FnME7nQA2Uc1uqj0eCE1NWmI1u0";
};
let
fenixToolchain =
let
toml = with builtins; (fromTOML (readFile ./rust-toolchain.toml)).toolchain;
in
(fenix.packages.${system}.fromToolchainName {
name = toml.channel;
sha256 = "sha256-r/8YBFuFa4hpwgE3FnME7nQA2Uc1uqj0eCE1NWmI1u0";
})."completeToolchain";

pkgs = import nixpkgs {
inherit system;
overlays = [
(import oxalica)
];
overlays = [ ];
config = {
allowUnfree = true;
};
};
in {
defaultPackage = self.devShell.${system};
devShell = pkgs.mkShell.override { } {

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 =
myLLVM = pkgs.llvmPackages_18;
myStdenv = pkgs.clang18Stdenv;

rustPlatform = pkgs.makeRustPlatform {
cargo = fenixToolchain;
rustc = fenixToolchain;
};
env = with pkgs; {
LIBCLANG_PATH = "${myLLVM.libclang.lib}/lib";
CMAKE_LLVM_DIR = "${myLLVM.libllvm.dev}/lib/cmake/llvm";
CMAKE_CLANG_DIR = "${myLLVM.libclang.dev}/lib/cmake/clang";
LLVM_CONFIG_PATH = "${myLLVM.libllvm.dev}/bin/llvm-config";
CLANG_PATH = "${myLLVM.clang}/bin/clang";
TINYCBOR_DIR = "${pkgs.tinycbor}";
NIX_ENFORCE_NO_NATIVE = 0; # Enable SSE instructions.
# Enable nix in the c2rust test suite
# This flag is used to tell the test scripts to look for
# libraries under nix paths.
C2RUST_USE_NIX = 1;
RUST_SRC_PATH = "${fenixToolchain}/lib/rustlib/src/rust/library";
};
in rec {
packages = {
default = rustPlatform.buildRustPackage (with pkgs; env // {
pname = "c2rust";
version = "0.20.0";
src = ./.;
doCheck = false; # Can use checkFlags to disable specific tests

patches = [ ./nix-tinycbor-cmake.patch ];

nativeBuildInputs =
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;
Expand All @@ -68,9 +83,43 @@
]
)
)
myStdenv.cc
myLLVM.libclang
myLLVM.clang
myLLVM.llvm
myLLVM.libllvm
];

buildInputs =
with pkgs; [
rustPlatform.bindgenHook
myStdenv.cc
myLLVM.libclang
myLLVM.clang
myLLVM.llvm
myLLVM.libllvm
tinycbor
openssl
zlib
(rust-bin.fromRustupToolchainFile ./rust-toolchain.toml)
fenixToolchain
];
};
});

cargoLock = {
lockFile = ./Cargo.lock;
};
});
};
defaultPackage = packages.default;

devShells = {
# Include a fixed version of clang in the development environment for testing.
default = pkgs.mkShell (with pkgs; env // {
strictDeps = true;
inputsFrom = [ packages.default ];
buildInputs = [ ];
});
};

devShell = devShells.default;
});
}
Loading