From a9fdfebc6bab2782b0751f19d2885b195002b2bd Mon Sep 17 00:00:00 2001 From: Andreas Rammhold Date: Tue, 17 Mar 2020 16:33:13 +0100 Subject: [PATCH] buildRustCrate: support proc-macro in default prelude --- .../rust/build-rust-crate/build-crate.nix | 3 +++ .../rust/build-rust-crate/test/default.nix | 12 ++++++++++++ 2 files changed, 15 insertions(+) diff --git a/pkgs/build-support/rust/build-rust-crate/build-crate.nix b/pkgs/build-support/rust/build-rust-crate/build-crate.nix index 9759235e30e3..d6d1cebb2e91 100644 --- a/pkgs/build-support/rust/build-rust-crate/build-crate.nix +++ b/pkgs/build-support/rust/build-rust-crate/build-crate.nix @@ -16,6 +16,9 @@ ++ [crateFeatures] ++ extraRustcOpts ++ lib.optional (stdenv.hostPlatform != stdenv.buildPlatform) "--target ${rust.toRustTarget stdenv.hostPlatform} -C linker=${stdenv.hostPlatform.config}-gcc" + # since rustc 1.42 the "proc_macro" crate is part of the default crate prelude + # https://github.com/rust-lang/cargo/commit/4d64eb99a4#diff-7f98585dbf9d30aa100c8318e2c77e79R1021-R1022 + ++ lib.optional (lib.elem "proc-macro" crateType) "--extern proc_macro" ; rustcMeta = "-C metadata=${metadata} -C extra-filename=-${metadata}"; diff --git a/pkgs/build-support/rust/build-rust-crate/test/default.nix b/pkgs/build-support/rust/build-rust-crate/test/default.nix index fba938f62372..674ef2599093 100644 --- a/pkgs/build-support/rust/build-rust-crate/test/default.nix +++ b/pkgs/build-support/rust/build-rust-crate/test/default.nix @@ -412,6 +412,18 @@ let "test ignore_main ... ok" ]; }; + procMacroInPrelude = { + procMacro = true; + edition = "2018"; + src = symlinkJoin { + name = "proc-macro-in-prelude"; + paths = [ + (mkFile "src/lib.rs" '' + use proc_macro::TokenTree; + '') + ]; + }; + }; }; brotliCrates = (callPackage ./brotli-crates.nix {}); tests = lib.mapAttrs (key: value: mkTest (value // lib.optionalAttrs (!value?crateName) { crateName = key; })) cases;