Skip to content

Commit 19f0312

Browse files
rod-chapmanmkannwischer
authored andcommitted
Add gcc to the NIX shell on macOS to support CBMC.
Leaves CC set as "clang" for compilation and testing on macOS. Always use gcc for pre-processing with goto-cc to get consistent C header files on all platforms, including macOS/Darwin. Ported from mlkem-native (pq-code-package/mlkem-native#1780, commit b828ccdb28db111695837efdbb3a85338b5ef112). Signed-off-by: Rod Chapman <rodchap@amazon.com> Signed-off-by: Hanno Becker <beckphan@amazon.co.uk>
1 parent 6e65c6e commit 19f0312

2 files changed

Lines changed: 15 additions & 1 deletion

File tree

nix/util.nix

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,15 @@ rec {
4949
# - On some machines, `native-gcc` needed to be evaluated lastly (placed as the last element of the toolchain list), or else would result in environment variables (CC, AR, ...) overriding issue.
5050
pkgs.lib.optionals cross [ pkgs.qemu pkgs.gcc-arm-embedded x86_64-gcc aarch64-gcc riscv64-gcc riscv32-gcc ppc64le-gcc ]
5151
++ pkgs.lib.optionals (cross && pkgs.stdenv.isLinux && pkgs.stdenv.isx86_64) [ aarch64_be-gcc ]
52+
# On Darwin, install GCC in addition to Clang. We reuse the exact same
53+
# `pkgs.gcc` attribute that the Linux native toolchain wraps (`native-gcc`
54+
# = `wrap-gcc pkgs`, whose compiler is `pkgs.gcc.cc`). Because both sides
55+
# reference the same package from the flake-locked nixpkgs, the Darwin GCC
56+
# version is always identical to the Linux one (do NOT pin a hardcoded
57+
# `gccNN` here, or the two platforms could drift apart on a nixpkgs bump).
58+
# Note that on Darwin, $CC remains set to "clang" for compilation and testing purposes,
59+
# while gcc is used for pre-processing sources for CBMC only.
60+
++ pkgs.lib.optionals pkgs.stdenv.isDarwin [ pkgs.gcc ]
5261
++ pkgs.lib.optionals cross [ native-gcc ]
5362
# git is not available in the nix shell on Darwin. As a workaround we add git as a dependency here.
5463
# Initially, we expected this to be fixed by https://github.com/NixOS/nixpkgs/pull/353893, but that does not seem to be the case.

proofs/cbmc/Makefile.common

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -330,7 +330,12 @@ CHECKFLAGS += $(CBMC_FLAG_UNSIGNED_OVERFLOW_CHECK)
330330
NONDET_STATIC ?=
331331

332332
# Flags to pass to goto-cc for compilation and linking
333-
COMPILE_FLAGS ?= -Wall -Werror --native-compiler $(CC)
333+
#
334+
# Note that we always use gcc for pre-processing with goto-cc
335+
# in order to get consistent header files on all platforms,
336+
# rather than using $(CC) (which might be preferred for compilation
337+
# on some platforms such as macOS/Darwin)
338+
COMPILE_FLAGS ?= -Wall -Werror --native-compiler gcc
334339
LINK_FLAGS ?= -Wall -Werror
335340
EXPORT_FILE_LOCAL_SYMBOLS ?= --export-file-local-symbols
336341

0 commit comments

Comments
 (0)