From 93ee9485b60f1ebcbdd26294803d653cac6c36bb Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?S=C3=A9bastien=20Villemot?= <sebastien@dynare.org> Date: Tue, 6 Sep 2022 12:05:50 +0200 Subject: [PATCH] macOS: bump to GCC 12 (for compilation and for use_dll) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit The formulas are taken from commit aae5963a69896021466a037f500aa06bef405be4 of the homebrew-core repository. The gcc.rb formula was modified by adding “cellar: :any” to all bottles (see https://github.com/Homebrew/brew/blob/master/docs/Bottles.md). The preprocessor has been updated accordingly. --- README.md | 2 +- .../source/installation-and-configuration.rst | 2 +- macOS/brewfiles/gcc.rb | 125 +++++++----------- macOS/brewfiles/isl.rb | 17 ++- macOS/brewfiles/zstd.rb | 61 +++++---- macOS/build.sh | 2 +- preprocessor | 2 +- 7 files changed, 94 insertions(+), 117 deletions(-) diff --git a/README.md b/README.md index a427e4fd56..67e121ccba 100644 --- a/README.md +++ b/README.md @@ -500,7 +500,7 @@ You can also choose a specific version of Dynare by checking out the correspondi - Configure Dynare from the source directory: ```sh -arch -x86_64 ./configure CC=gcc-11 CXX=g++-11 CPPFLAGS=-I/usr/local/include LDFLAGS=-L/usr/local/lib LEX=/usr/local/opt/flex/bin/flex YACC=/usr/local/opt/bison/bin/bison --with-matlab=/Applications/MATLAB_R2021b.app +arch -x86_64 ./configure CC=gcc-12 CXX=g++-12 CPPFLAGS=-I/usr/local/include LDFLAGS=-L/usr/local/lib LEX=/usr/local/opt/flex/bin/flex YACC=/usr/local/opt/bison/bin/bison --with-matlab=/Applications/MATLAB_R2021b.app ``` where you need to adapt the path to MATLAB. If you don’t have MATLAB, simply replace `--with-matlab=<…>` by `--disable-matlab`. Check the output of the command whether Dynare is configured for building everything except the internal docs of Dynare, Dynare++ and M2HTML. diff --git a/doc/manual/source/installation-and-configuration.rst b/doc/manual/source/installation-and-configuration.rst index 5c5a790bba..b45e993732 100644 --- a/doc/manual/source/installation-and-configuration.rst +++ b/doc/manual/source/installation-and-configuration.rst @@ -196,7 +196,7 @@ With Octave The compiler can be installed via Homebrew_. In a terminal, run:: - brew install gcc-11 + brew install gcc-12 Configuration ============= diff --git a/macOS/brewfiles/gcc.rb b/macOS/brewfiles/gcc.rb index b2f8233c9d..037597fe0c 100644 --- a/macOS/brewfiles/gcc.rb +++ b/macOS/brewfiles/gcc.rb @@ -1,42 +1,35 @@ class Gcc < Formula desc "GNU compiler collection" homepage "https://gcc.gnu.org/" - if Hardware::CPU.arm? - # Branch from the Darwin maintainer of GCC with Apple Silicon support, - # located at https://github.com/iains/gcc-darwin-arm64 and - # backported with his help to gcc-11 branch. Too big for a patch. - url "https://github.com/fxcoudert/gcc/archive/refs/tags/gcc-11.2.0-arm-20211124.tar.gz" - sha256 "d7f8af7a0d9159db2ee3c59ffb335025a3d42547784bee321d58f2b4712ca5fd" - version "11.2.0" - else - url "https://ftp.gnu.org/gnu/gcc/gcc-11.2.0/gcc-11.2.0.tar.xz" - mirror "https://ftpmirror.gnu.org/gcc/gcc-11.2.0/gcc-11.2.0.tar.xz" - sha256 "d08edc536b54c372a1010ff6619dd274c0f1603aa49212ba20f7aa2cda36fa8b" - - # Darwin 21 (Monterey) support + license "GPL-3.0-or-later" => { with: "GCC-exception-3.1" } + head "https://gcc.gnu.org/git/gcc.git", branch: "master" + + stable do + url "https://ftp.gnu.org/gnu/gcc/gcc-12.2.0/gcc-12.2.0.tar.xz" + mirror "https://ftpmirror.gnu.org/gcc/gcc-12.2.0/gcc-12.2.0.tar.xz" + sha256 "e549cf9cf3594a00e27b6589d4322d70e0720cdd213f39beb4181e06926230ff" + + # Branch from the Darwin maintainer of GCC, with a few generic fixes and + # Apple Silicon support, located at https://github.com/iains/gcc-12-branch patch do - url "https://github.com/iains/gcc-darwin-arm64/commit/20f61faaed3b335d792e38892d826054d2ac9f15.patch?full_index=1" - sha256 "c0605179a856ca046d093c13cea4d2e024809ec2ad4bf3708543fc3d2e60504b" + url "https://raw.githubusercontent.com/Homebrew/formula-patches/1d184289/gcc/gcc-12.2.0-arm.diff" + sha256 "a7843b5c6bf1401e40c20c72af69c8f6fc9754ae980bb4a5f0540220b3dcb62d" end end - license "GPL-3.0-or-later" => { with: "GCC-exception-3.1" } - revision 3 - head "https://gcc.gnu.org/git/gcc.git", branch: "master" - # We can't use `url :stable` here due to the ARM-specific branch above. livecheck do - url "https://ftp.gnu.org/gnu/gcc/" + url :stable regex(%r{href=["']?gcc[._-]v?(\d+(?:\.\d+)+)(?:/?["' >]|\.t)}i) end bottle do rebuild 1 - sha256 cellar: :any, arm64_monterey: "2d179246426328ee69b94a25b8bd4c25caeff0699b5ecb4b3d258fe4efd3673e" - sha256 cellar: :any, arm64_big_sur: "9dbb002aa1aab75071fe1a5432fd3ee61378d711aebe0d35d0ca7226a4225451" - sha256 cellar: :any, monterey: "198f5312ecfe6fc6437b55e2fb3bb380e8c597ae6fa255f8f7d0be90306e7601" - sha256 cellar: :any, big_sur: "d2d4543675948c7adf3f1d4934dc651b864f66d5dad6fb3c8bdcfc6f5eef42e6" - sha256 cellar: :any, catalina: "e721b6a3195d2a1e73e4c12d34d0138bc5ebe6a37fb1a8d63ad733316e944c59" - sha256 cellar: :any, x86_64_linux: "3717134ab0f56e7eeb167c4f4a993c81329d6c1248dae5ee6e39f59cfdfa0eee" + sha256 cellar: :any, arm64_monterey: "f37b8d3764f63e11a6e11dc23774eba527453de89fedb4e3b13aa3996059d386" + sha256 cellar: :any, arm64_big_sur: "5d98731c711f17707fe13276090a6a3669a9d68e766e56ead8c842465ff164bb" + sha256 cellar: :any, monterey: "453199069048503be8f072463aaa3cd60fc2764875528f234374872354528564" + sha256 cellar: :any, big_sur: "1f2aca239e706f455125dcb2c08df7744b8905b5b62d7aed4cdeae6cf5d5fcee" + sha256 cellar: :any, catalina: "98f37e3468e2a15343e02f613a2f8d7761d30eead960d04b2317f8292122e9ac" + sha256 cellar: :any_skip_relocation, x86_64_linux: "c7f773f9af560766b2d971d815a8d224c267088c05ed1f2b864bd1d9ebc26e1a" end # The bottles are built on systems with the CLT installed, and do not work @@ -58,15 +51,6 @@ class Gcc < Formula # GCC bootstraps itself, so it is OK to have an incompatible C++ stdlib cxxstdlib_check :skip - # Fix for https://gcc.gnu.org/bugzilla/show_bug.cgi?id=102992 - # Working around a macOS Monterey bug - if MacOS.version == :monterey - patch do - url "https://gcc.gnu.org/git/?p=gcc.git;a=patch;h=fabe8cc41e9b01913e2016861237d1d99d7567bf" - sha256 "9d3c2c91917cdc37d11385bdeba005cd7fa89efdbdf7ca38f7de3f6fa8a8e51b" - end - end - def version_suffix if build.head? "HEAD" @@ -80,18 +64,17 @@ class Gcc < Formula ENV.delete "LD" # We avoiding building: - # - Ada, which requires a pre-existing GCC Ada compiler to bootstrap + # - Ada and D, which require a pre-existing GCC to bootstrap # - Go, currently not supported on macOS # - BRIG languages = %w[c c++ objc obj-c++ fortran] - languages << "d" if Hardware::CPU.intel? pkgversion = "Homebrew GCC #{pkg_version} #{build.used_options*" "}".strip - cpu = Hardware::CPU.arm? ? "aarch64" : "x86_64" + # Use `lib/gcc/current` to provide a path that doesn't change with GCC's version. args = %W[ --prefix=#{opt_prefix} - --libdir=#{opt_lib}/gcc/#{version_suffix} + --libdir=#{opt_lib}/gcc/current --disable-nls --enable-checking=release --with-gcc-major-version-only @@ -104,30 +87,19 @@ class Gcc < Formula --with-zstd=#{Formula["zstd"].opt_prefix} --with-pkgversion=#{pkgversion} --with-bugurl=#{tap.issues_url} + --with-system-zlib ] - # libphobos is part of gdc - args << "--enable-libphobos" if Hardware::CPU.intel? if OS.mac? + cpu = Hardware::CPU.arm? ? "aarch64" : "x86_64" args << "--build=#{cpu}-apple-darwin#{OS.kernel_version.major}" - args << "--with-system-zlib" - - # Xcode 10 dropped 32-bit Intel support - args << "--disable-multilib" if Hardware::CPU.intel? && DevelopmentTools.clang_build_version >= 1000 - - # Workaround for Xcode 12.5 bug on Intel, remove in next version - # https://gcc.gnu.org/bugzilla/show_bug.cgi?id=100340 - args << "--without-build-config" if Hardware::CPU.intel? && DevelopmentTools.clang_build_version == 1205 # System headers may not be in /usr/include sdk = MacOS.sdk_path_if_needed - if sdk - args << "--with-native-system-header-dir=/usr/include" - args << "--with-sysroot=#{sdk}" - end + args << "--with-sysroot=#{sdk}" if sdk else # Fix cc1: error while loading shared libraries: libisl.so.15 - args << "--with-boot-ldflags=-static-libstdc++ -static-libgcc #{ENV["LDFLAGS"]}" + args << "--with-boot-ldflags=-static-libstdc++ -static-libgcc #{ENV.ldflags}" # Fix Linux error: gnu/stubs-32.h: No such file or directory. args << "--disable-multilib" @@ -141,7 +113,8 @@ class Gcc < Formula system "../configure", *args system "make" - # On Linux, strip the binaries + # Do not strip the binaries on macOS, it makes them unsuitable + # for loading plugins install_target = OS.mac? ? "install" : "install-strip" # To make sure GCC does not record cellar paths, we configure it with @@ -149,22 +122,27 @@ class Gcc < Formula # temporary location, then move into the cellar path. system "make", install_target, "DESTDIR=#{Pathname.pwd}/../instdir" mv Dir[Pathname.pwd/"../instdir/#{opt_prefix}/*"], prefix + end - bin.install_symlink bin/"gfortran-#{version_suffix}" => "gfortran" - bin.install_symlink bin/"gdc-#{version_suffix}" => "gdc" if Hardware::CPU.intel? + bin.install_symlink bin/"gfortran-#{version_suffix}" => "gfortran" - if OS.linux? - # Only the newest brewed gcc should install gfortan libs as we can only have one. - lib.install_symlink Dir[lib/"gcc/#{version_suffix}/libgfortran.*"] - end - end + # Provide a `lib/gcc/xy` directory to align with the versioned GCC formulae. + # We need to create `lib/gcc/xy` as a directory and not a symlink to avoid `brew link` conflicts. + (lib/"gcc"/version_suffix).install_symlink (lib/"gcc/current").children + + # Only the newest brewed gcc should install gfortan libs as we can only have one. + lib.install_symlink lib.glob("gcc/current/libgfortran.*") if OS.linux? # Handle conflicts between GCC formulae and avoid interfering # with system compilers. # Rename man7. - Dir.glob(man7/"*.7") { |file| add_suffix file, version_suffix } + man7.glob("*.7") { |file| add_suffix file, version_suffix } # Even when we disable building info pages some are still installed. info.rmtree + + # Work around GCC install bug + # https://gcc.gnu.org/bugzilla/show_bug.cgi?id=105664 + rm_rf bin.glob("*-gcc-tmp") end def add_suffix(file, suffix) @@ -235,7 +213,7 @@ class Gcc < Formula # * `-L#{HOMEBREW_PREFIX}/lib` instructs gcc to find the rest # brew libraries. # Note: *link will silently add #{libdir} first to the RPATH - libdir = HOMEBREW_PREFIX/"lib/gcc/#{version_suffix}" + libdir = HOMEBREW_PREFIX/"lib/gcc/current" specs.write specs_string + <<~EOS *cpp_unique_options: + -isysroot #{HOMEBREW_PREFIX}/nonexistent #{system_header_dirs.map { |p| "-idirafter #{p}" }.join(" ")} @@ -264,7 +242,7 @@ class Gcc < Formula } EOS system "#{bin}/gcc-#{version_suffix}", "-o", "hello-c", "hello-c.c" - assert_equal "Hello, world!\n", `./hello-c` + assert_equal "Hello, world!\n", shell_output("./hello-c") (testpath/"hello-cc.cc").write <<~EOS #include <iostream> @@ -279,7 +257,7 @@ class Gcc < Formula } EOS system "#{bin}/g++-#{version_suffix}", "-o", "hello-cc", "hello-cc.cc" - assert_equal "Hello, world!\n", `./hello-cc` + assert_equal "Hello, world!\n", shell_output("./hello-cc") (testpath/"test.f90").write <<~EOS integer,parameter::m=10000 @@ -293,19 +271,6 @@ class Gcc < Formula end EOS system "#{bin}/gfortran", "-o", "test", "test.f90" - assert_equal "Done\n", `./test` - - if Hardware::CPU.intel? - (testpath/"hello_d.d").write <<~EOS - import std.stdio; - int main() - { - writeln("Hello, world!"); - return 0; - } - EOS - system "#{bin}/gdc-#{version_suffix}", "-o", "hello-d", "hello_d.d" - assert_equal "Hello, world!\n", `./hello-d` - end + assert_equal "Done\n", shell_output("./test") end end diff --git a/macOS/brewfiles/isl.rb b/macOS/brewfiles/isl.rb index e1570e81b7..84038d63a8 100644 --- a/macOS/brewfiles/isl.rb +++ b/macOS/brewfiles/isl.rb @@ -10,8 +10,8 @@ class Isl < Formula # and update isl_version() function accordingly. All other names will # result in isl_version() function returning "UNKNOWN" and hence break # package detection. - url "https://libisl.sourceforge.io/isl-0.24.tar.xz" - sha256 "043105cc544f416b48736fff8caf077fb0663a717d06b1113f16e391ac99ebad" + url "https://libisl.sourceforge.io/isl-0.25.tar.xz" + sha256 "be7b210647ccadf90a2f0b000fca11a4d40546374a850db67adb32fad4b230d9" # Fix -flat_namespace being used on Big Sur and later. patch do @@ -26,13 +26,12 @@ class Isl < Formula end bottle do - sha256 cellar: :any, arm64_monterey: "be08c3e9765655ad5bfd227f9b97acb0ef88ad2307dc214ea4064cc1f51db641" - sha256 cellar: :any, arm64_big_sur: "cf7f8b77fc0e51bc9c9921306737176e6f9e03062255a525d9ab59cf91ed3d36" - sha256 cellar: :any, monterey: "6eca22a381c05adc4e33195e5b409bd695e035141d577480876ac22d811ec5bf" - sha256 cellar: :any, big_sur: "d8c7026042e122143e0729bf3a596be77753b8cfeddcae200cd3a3c18176800c" - sha256 cellar: :any, catalina: "f33ee49a23fbde05392be23110d14add72aaed390ffd3aefc400645eeb1772d4" - sha256 cellar: :any, mojave: "34b71567d6bfb7e4cb4aced1d089fe6d72988af02775730be26b5bcea483d065" - sha256 cellar: :any_skip_relocation, x86_64_linux: "7b58d25de0b7ed797118f32febe116ee2d7458767e6339d6a4ce51ff4ab11191" + sha256 cellar: :any, arm64_monterey: "764bde8aa0d015c13cbf53891489f3ef56a5951f617ad9906aea34382dc1f4d1" + sha256 cellar: :any, arm64_big_sur: "24f86a50eea8a2d4dbc24ecb5f8b8ded61f6f7cd7054886b5dafcb82854b28ed" + sha256 cellar: :any, monterey: "568dd08209728ad3a036cf45287ff8384b9ed821460a216a9a79fa80fdcfbf52" + sha256 cellar: :any, big_sur: "be6456799bb670c16115d89feacf72cee9b444fe87aca6b1bd350bfb89ff6247" + sha256 cellar: :any, catalina: "c2ccd96c92ab0bbfdb775ccd7c8f20c2057cbe976769cf078e728b6f5f5938bc" + sha256 cellar: :any_skip_relocation, x86_64_linux: "c0244c95ed9cc89b826868de83bec3150fcc120add1265017176770150757083" end head do diff --git a/macOS/brewfiles/zstd.rb b/macOS/brewfiles/zstd.rb index 9104e0e852..55ebf6b62a 100644 --- a/macOS/brewfiles/zstd.rb +++ b/macOS/brewfiles/zstd.rb @@ -1,42 +1,55 @@ class Zstd < Formula desc "Zstandard is a real-time compression algorithm" homepage "https://facebook.github.io/zstd/" - url "https://github.com/facebook/zstd/archive/v1.5.1.tar.gz" - mirror "http://fresh-center.net/linux/misc/zstd-1.5.1.tar.gz" - mirror "http://fresh-center.net/linux/misc/legacy/zstd-1.5.1.tar.gz" - sha256 "dc05773342b28f11658604381afd22cb0a13e8ba17ff2bd7516df377060c18dd" + url "https://github.com/facebook/zstd/archive/v1.5.2.tar.gz" + mirror "http://fresh-center.net/linux/misc/zstd-1.5.2.tar.gz" + mirror "http://fresh-center.net/linux/misc/legacy/zstd-1.5.2.tar.gz" + sha256 "f7de13462f7a82c29ab865820149e778cbfe01087b3a55b5332707abf9db4a6e" license "BSD-3-Clause" head "https://github.com/facebook/zstd.git", branch: "dev" bottle do - sha256 cellar: :any, arm64_monterey: "ba590597ae6a5d8b084478441af5332c94e0f3896a5d7a4be2e6f2c3be4f0df9" - sha256 cellar: :any, arm64_big_sur: "e49cf4084f3c9e60480d0d77cb73f760fdf2b5735fb2c12a45de3c687995aa57" - sha256 cellar: :any, monterey: "13190f9cfc7db924880c529ca5ae1867c0b7ed9a319463c5b95bd304fe12a547" - sha256 cellar: :any, big_sur: "5c1d562b1ee8087e3ecdd04134a8db4040a13190e42b1408c7aede140af3dace" - sha256 cellar: :any, catalina: "5b7a906469cb69b94e6e1e16839646cf7624e7ba94b41fe65fc852d4632ccccb" - sha256 cellar: :any_skip_relocation, x86_64_linux: "69f0d265612b10caf5533a0b0f6beba083504557aca269c4e2ab7e90cc8e355a" + rebuild 3 + sha256 cellar: :any, arm64_monterey: "844b957a277cd93f70f8de91bd4caa21579f9b9e2f55bd5daf0334eee8ef1196" + sha256 cellar: :any, arm64_big_sur: "091743749cec2f0ae34482ae370aa5a563d6c7841c42fbc25e0d061863f5faa5" + sha256 cellar: :any, monterey: "b0eabfa556c5aed039a5b22cd7e2e3dd52c7d2416c1141e4a8e9e825b9238fc3" + sha256 cellar: :any, big_sur: "585bced60a658bfbda88d6a500fa26671871aa354f65cef767f17ea46209b4f2" + sha256 cellar: :any, catalina: "bdd2d3349fbcaa7e299cb6184f43e7f2bf29bd5936396d4c7c3d132bd687cd15" + sha256 cellar: :any_skip_relocation, x86_64_linux: "006b5ab6a4616a8b6f59953cb9efb546d312e3ba231c303bb56749e7f66f56df" end depends_on "cmake" => :build - + depends_on "lz4" + depends_on "xz" uses_from_macos "zlib" def install - cd "build/cmake" do - system "cmake", "-S", ".", "-B", "builddir", - "-DZSTD_BUILD_CONTRIB=ON", - "-DCMAKE_INSTALL_RPATH=#{rpath}", - *std_cmake_args - system "cmake", "--build", "builddir" - system "cmake", "--install", "builddir" - end + # Legacy support is the default after + # https://github.com/facebook/zstd/commit/db104f6e839cbef94df4df8268b5fecb58471274 + # Set it to `ON` to be explicit about the configuration. + system "cmake", "-S", "build/cmake", "-B", "builddir", + "-DZSTD_PROGRAMS_LINK_SHARED=ON", # link `zstd` to `libzstd` + "-DZSTD_BUILD_CONTRIB=ON", + "-DCMAKE_INSTALL_RPATH=#{rpath}", + "-DZSTD_LEGACY_SUPPORT=ON", + "-DZSTD_ZLIB_SUPPORT=ON", + "-DZSTD_LZMA_SUPPORT=ON", + "-DZSTD_LZ4_SUPPORT=ON", + *std_cmake_args + system "cmake", "--build", "builddir" + system "cmake", "--install", "builddir" end test do - assert_equal "hello\n", - pipe_output("#{bin}/zstd | #{bin}/zstd -d", "hello\n", 0) - - assert_equal "hello\n", - pipe_output("#{bin}/pzstd | #{bin}/pzstd -d", "hello\n", 0) + [bin/"zstd", bin/"pzstd", "xz", "lz4", "gzip"].each do |prog| + data = "Hello, #{prog}" + assert_equal data, pipe_output("#{bin}/zstd -d", pipe_output(prog, data)) + if prog.to_s.end_with?("zstd") + # `pzstd` can only decompress zstd-compressed data. + assert_equal data, pipe_output("#{bin}/pzstd -d", pipe_output(prog, data)) + else + assert_equal data, pipe_output("#{prog} -d", pipe_output("#{bin}/zstd --format=#{prog}", data)) + end + end end end diff --git a/macOS/build.sh b/macOS/build.sh index 85dab2879e..2dcd84d83c 100755 --- a/macOS/build.sh +++ b/macOS/build.sh @@ -22,7 +22,7 @@ set -ex ROOTDIR=$(pwd)/.. # Set the GCC version -GCC_VERSION=11 +GCC_VERSION=12 # Set the compilers CC=gcc-$GCC_VERSION diff --git a/preprocessor b/preprocessor index c3cb7ca534..482ec5fb67 160000 --- a/preprocessor +++ b/preprocessor @@ -1 +1 @@ -Subproject commit c3cb7ca534b27e3c763f1dba62892b92d9c3f234 +Subproject commit 482ec5fb67782d80083c208d75c18f3a5a2f78d2 -- GitLab