From 1f4feb7c6f2bb7d257e860b2d8413a746fbe50c8 Mon Sep 17 00:00:00 2001 From: Thomas Watson Date: Sun, 1 Jan 2023 11:12:23 -0600 Subject: [PATCH 1/2] avr-gcc: fix build on Darwin Adds a patch which fixes a compilation error generated by Clang 11 compiling GCC 11.3. --- .../gcc/11/avr-gcc-11.3-darwin.patch | 20 +++++++++++++++++++ pkgs/development/compilers/gcc/11/default.nix | 2 ++ 2 files changed, 22 insertions(+) create mode 100644 pkgs/development/compilers/gcc/11/avr-gcc-11.3-darwin.patch diff --git a/pkgs/development/compilers/gcc/11/avr-gcc-11.3-darwin.patch b/pkgs/development/compilers/gcc/11/avr-gcc-11.3-darwin.patch new file mode 100644 index 000000000000..787862fbcffa --- /dev/null +++ b/pkgs/development/compilers/gcc/11/avr-gcc-11.3-darwin.patch @@ -0,0 +1,20 @@ +--- a/gcc/config/avr/avr.c 2022-10-08 19:18:33.000000000 +0200 ++++ b/gcc/config/avr/avr.patched.c 2022-10-08 19:19:34.000000000 +0200 +@@ -10196,7 +10196,7 @@ + to track need of __do_copy_data. */ + + static void +-avr_output_data_section_asm_op (const void *data) ++avr_output_data_section_asm_op (const char *data) + { + avr_need_copy_data_p = true; + +@@ -10209,7 +10209,7 @@ + to track need of __do_clear_bss. */ + + static void +-avr_output_bss_section_asm_op (const void *data) ++avr_output_bss_section_asm_op (const char *data) + { + avr_need_clear_bss_p = true; + diff --git a/pkgs/development/compilers/gcc/11/default.nix b/pkgs/development/compilers/gcc/11/default.nix index de764b9ccc7c..20b9c32bdf88 100644 --- a/pkgs/development/compilers/gcc/11/default.nix +++ b/pkgs/development/compilers/gcc/11/default.nix @@ -72,6 +72,8 @@ let majorVersion = "11"; sha256 = "sha256-LFAXUEoYD7YeCG8V9mWanygyQOI7U5OhCRIKOVCCDAg="; }) ] + # https://github.com/osx-cross/homebrew-avr/issues/280#issuecomment-1272381808 + ++ optional (stdenv.isDarwin && targetPlatform.isAvr) ./avr-gcc-11.3-darwin.patch # Obtain latest patch with ../update-mcfgthread-patches.sh ++ optional (!crossStageStatic && targetPlatform.isMinGW && threadsCross.model == "mcf") ./Added-mcf-thread-model-support-from-mcfgthread.patch; From 6e13168f479f7e840a2434dc2e2520c031fa285f Mon Sep 17 00:00:00 2001 From: Thomas Watson Date: Sun, 1 Jan 2023 12:09:45 -0600 Subject: [PATCH 2/2] simavr: fix build on Darwin Remove unnecessary compiler flag not recognized by Clang. Borrow setup hook from Wine which filters out Darwin-specific flags not recognized by avr-gcc, which is used to build the test firmware. --- pkgs/development/tools/simavr/default.nix | 18 ++++++---- .../tools/simavr/setup-hook-darwin.sh | 34 +++++++++++++++++++ 2 files changed, 46 insertions(+), 6 deletions(-) create mode 100644 pkgs/development/tools/simavr/setup-hook-darwin.sh diff --git a/pkgs/development/tools/simavr/default.nix b/pkgs/development/tools/simavr/default.nix index 8aa9ccd5388a..11b146e55c5e 100644 --- a/pkgs/development/tools/simavr/default.nix +++ b/pkgs/development/tools/simavr/default.nix @@ -1,9 +1,17 @@ -{ lib, stdenv, fetchFromGitHub, libelf, which, pkg-config, freeglut +{ lib, stdenv, makeSetupHook, fetchFromGitHub, libelf, which, pkg-config, freeglut , avrgcc, avrlibc , libGLU, libGL , GLUT }: -stdenv.mkDerivation rec { +let + setupHookDarwin = makeSetupHook { + name = "darwin-avr-gcc-hook"; + substitutions = { + darwinSuffixSalt = stdenv.cc.suffixSalt; + avrSuffixSalt = avrgcc.suffixSalt; + }; + } ./setup-hook-darwin.sh; +in stdenv.mkDerivation rec { pname = "simavr"; version = "1.7"; @@ -22,9 +30,8 @@ stdenv.mkDerivation rec { "AVR=avr-" ]; - NIX_CFLAGS_COMPILE = [ "-Wno-error=stringop-truncation" ]; - - nativeBuildInputs = [ which pkg-config avrgcc ]; + nativeBuildInputs = [ which pkg-config avrgcc ] + ++ lib.optional stdenv.isDarwin setupHookDarwin; buildInputs = [ libelf freeglut libGLU libGL ] ++ lib.optional stdenv.isDarwin GLUT; @@ -35,7 +42,6 @@ stdenv.mkDerivation rec { checkTarget = "-C tests run_tests"; meta = with lib; { - broken = stdenv.isDarwin; description = "A lean and mean Atmel AVR simulator"; homepage = "https://github.com/buserror/simavr"; license = licenses.gpl3; diff --git a/pkgs/development/tools/simavr/setup-hook-darwin.sh b/pkgs/development/tools/simavr/setup-hook-darwin.sh new file mode 100644 index 000000000000..3861e45973ac --- /dev/null +++ b/pkgs/development/tools/simavr/setup-hook-darwin.sh @@ -0,0 +1,34 @@ + +fixupCFlagsForDarwin() { + # Because it’s getting called from a Darwin stdenv, avr-gcc will pick up on + # Darwin-specific flags, and it will barf and die on -iframework in + # particular. Strip them out, so simavr can compile its test firmware. + cflagsFilter='s|-F[^ ]*||g;s|-iframework [^ ]*||g;s|-isystem [^ ]*||g;s| *| |g' + + # The `CoreFoundation` reference is added by `linkSystemCoreFoundationFramework` in the + # Apple SDK’s setup hook. Remove that because avr-gcc will fail due to file not found. + ldFlagsFilter='s|/nix/store/[^-]*-apple-framework-CoreFoundation[^ ]*||g' + + # `cc-wrapper.sh`` supports getting flags from a system-specific salt. While it is currently a + # tuple, that’s not considered a stable interface, so the derivation will provide them. + export NIX_CFLAGS_COMPILE_@darwinSuffixSalt@=${NIX_CFLAGS_COMPILE-} + export NIX_LDFLAGS_@darwinSuffixSalt@=${NIX_LDFLAGS-} + + echo removing @darwinSuffixSalt@-specific flags from NIX_CFLAGS_COMPILE for @avrSuffixSalt@ + export NIX_CFLAGS_COMPILE_@avrSuffixSalt@+="$(sed "$cflagsFilter" <<< "$NIX_CFLAGS_COMPILE")" + echo removing @darwinSuffixSalt@-specific flags from NIX_LDFLAGS for @avrSuffixSalt@ + export NIX_LDFLAGS_@avrSuffixSalt@+="$(sed "$ldFlagsFilter;$cflagsFilter" <<< "$NIX_LDFLAGS")" + + # Make sure the global flags aren’t accidentally influencing the platform-specific flags. + export NIX_CFLAGS_COMPILE="" + export NIX_LDFLAGS="" +} + +# This is pretty hacky, but this hook _must_ run after `linkSystemCoreFoundationFramework`. +function runFixupCFlagsForDarwinLast() { + preConfigureHooks+=(fixupCFlagsForDarwin) +} + +if [ -z "${dontFixupCFlagsForDarwin-}" ]; then + postUnpackHooks+=(runFixupCFlagsForDarwinLast) +fi