From 6300aae896c12369606f134f96e2733c67bc5967 Mon Sep 17 00:00:00 2001
From: Fabien Chouteau <chouteau@adacore.com>
Date: Tue, 20 Aug 2024 17:58:47 +0200
Subject: [PATCH 1/4] Differentiate hosts for cross compilers packages

---
 specs/release_package.anod | 11 ++++++++++-
 1 file changed, 10 insertions(+), 1 deletion(-)

diff --git a/specs/release_package.anod b/specs/release_package.anod
index 0e2925c..28e375d 100644
--- a/specs/release_package.anod
+++ b/specs/release_package.anod
@@ -64,9 +64,18 @@ class ReleasePackage(spec("common")):
 
     @property
     def release_name(self):
+        platform = self.env.platform
+
+        # The target triplet for cross compilers on macOS (darwin) x86 and
+        # aarch64 is the same, to differentiate the two hosts we add host CPU
+        # name at the end of platform name. And for consistency we do this on
+        # all other hosts as well.
+        if self.env.is_cross:
+            platform += "-" + self.env.host.cpu.name
+
         return "%s-%s-%s-%s" % (
             self.package,
-            self.env.platform,
+            platform,
             self.version,
             self.package_release,
         )

From 51e82ef5a9dc60c848212517955aedbe510690e8 Mon Sep 17 00:00:00 2001
From: Fabien Chouteau <chouteau@adacore.com>
Date: Tue, 20 Aug 2024 19:20:41 +0200
Subject: [PATCH 2/4] GCC 14.2

---
 specs/avrlibc.anod         |  2 +-
 specs/gcc.anod             |  4 ++--
 specs/release_package.anod | 10 +++++-----
 3 files changed, 8 insertions(+), 8 deletions(-)

diff --git a/specs/avrlibc.anod b/specs/avrlibc.anod
index 1c699db..6f08885 100644
--- a/specs/avrlibc.anod
+++ b/specs/avrlibc.anod
@@ -18,7 +18,7 @@ class AVRLibc(spec("common")):
         return [
             self.HTTPSSourceBuilder(
                 name=self.tarball,
-                url="http://download.savannah.gnu.org/releases/avr-libc/" + self.tarball,
+                url="https://download.savannah.gnu.org/releases/avr-libc/" + self.tarball,
             )
         ]
 
diff --git a/specs/gcc.anod b/specs/gcc.anod
index eb8b805..77752f4 100644
--- a/specs/gcc.anod
+++ b/specs/gcc.anod
@@ -13,7 +13,7 @@ patch_name = "ld"
 class GCC(spec("gh-artifact")):
     @property
     def version(self):
-        return "14.1.0"
+        return "14.2.0"
 
     @property
     def tarball(self):
@@ -30,7 +30,7 @@ class GCC(spec("gh-artifact")):
                     if not self.host_is_macos_arm
                     else
                     "https://github.com/iains/gcc-14-branch/archive/refs/"
-                    + "tags/gcc-14.1-darwin-r1.tar.gz"
+                    + "tags/gcc-14.2-darwin-r1.tar.gz"
                 )
             ),
             self.LocalSourceBuilder(name=patch_name)
diff --git a/specs/release_package.anod b/specs/release_package.anod
index 28e375d..76d5295 100644
--- a/specs/release_package.anod
+++ b/specs/release_package.anod
@@ -54,13 +54,13 @@ class ReleasePackage(spec("common")):
             return "1"
         elif package == "gnat":
             if self.env.target.triplet == "arm-eabi":
-                return "3"
+                return "1"
             elif self.env.target.triplet == "riscv64-elf":
-                return "3"
-            elif self.env.target.triplet == "avr-elf":
-                return "3"
+                return "1"
+            elif self.env.target.triplet == "avr":
+                return "1"
             else:
-                return "3"
+                return "1"
 
     @property
     def release_name(self):

From a5581b8505cf50e5e6293438f0ff764aeabc341a Mon Sep 17 00:00:00 2001
From: Fabien Chouteau <chouteau@adacore.com>
Date: Wed, 21 Aug 2024 18:40:29 +0200
Subject: [PATCH 3/4] Add xtensa-esp32-elf builds

---
 .github/workflows/linux.yml            | 2 +-
 .github/workflows/macos.yml            | 2 +-
 .github/workflows/macos_arm.yml        | 5 ++++-
 .github/workflows/windows.yml          | 2 +-
 lib/platform_db.py                     | 3 +++
 sanity-checking/drivers/platform_db.py | 6 ++++++
 specs/gcc.anod                         | 5 +++++
 specs/release_package.anod             | 6 ++++++
 8 files changed, 27 insertions(+), 4 deletions(-)

diff --git a/.github/workflows/linux.yml b/.github/workflows/linux.yml
index 64e8a01..ed2a6cc 100644
--- a/.github/workflows/linux.yml
+++ b/.github/workflows/linux.yml
@@ -96,7 +96,7 @@ jobs:
   gnat_cross:
     strategy:
       matrix:
-        target: ["arm-elf", "riscv64-elf", "avr-elf"]
+        target: ["arm-elf", "riscv64-elf", "avr-elf", "xtensa-esp32-elf"]
     name: GNAT ${{ matrix.target }}-linux
     needs: gnat
     runs-on: ubuntu-20.04
diff --git a/.github/workflows/macos.yml b/.github/workflows/macos.yml
index c6ff4e8..443ac26 100644
--- a/.github/workflows/macos.yml
+++ b/.github/workflows/macos.yml
@@ -93,7 +93,7 @@ jobs:
   gnat_cross:
     strategy:
       matrix:
-        target: ["arm-elf", "riscv64-elf", "avr-elf"]
+        target: ["arm-elf", "riscv64-elf", "avr-elf", "xtensa-esp32-elf"]
     name: GNAT ${{ matrix.target }}-darwin
     needs: gnat
     runs-on: macos-12
diff --git a/.github/workflows/macos_arm.yml b/.github/workflows/macos_arm.yml
index 4aebc29..80e974a 100644
--- a/.github/workflows/macos_arm.yml
+++ b/.github/workflows/macos_arm.yml
@@ -53,7 +53,10 @@ jobs:
   gnat_cross:
     strategy:
       matrix:
-        target: ["arm-elf", "riscv64-elf", "avr-elf"]
+        target: ["arm-elf", "riscv64-elf", "xtensa-esp32-elf"]
+        # We don't enable avr on aarch64 macOS as libc-avr doesn't recognize
+        # aarch64-apple machine https://github.com/avrdudes/avr-libc/issues/978
+
     name: GNAT ${{ matrix.target }}-darwin
     needs: gnat
     runs-on: macos-14
diff --git a/.github/workflows/windows.yml b/.github/workflows/windows.yml
index 32259e4..fe88fe4 100644
--- a/.github/workflows/windows.yml
+++ b/.github/workflows/windows.yml
@@ -127,7 +127,7 @@ jobs:
   gnat_cross:
     strategy:
       matrix:
-        target: ["arm-elf", "riscv64-elf", "avr-elf"]
+        target: ["arm-elf", "riscv64-elf", "avr-elf", "xtensa-esp32-elf"]
     name: GNAT ${{ matrix.target }}-windows
     needs: gnat
     runs-on: windows-2019
diff --git a/lib/platform_db.py b/lib/platform_db.py
index 3f34762..e7408c6 100644
--- a/lib/platform_db.py
+++ b/lib/platform_db.py
@@ -4,6 +4,7 @@ class PlatDB(PlatformDBPlugin):
     def update_db(self) -> None:
         self.cpu_info.update(
             {
+                "xtensa": {"endian": "little", "bits": 32},
                 "riscv32": {"endian": "little", "bits": 32},
                 "riscv64": {"endian": "little", "bits": 64},
             }
@@ -34,6 +35,7 @@ def update_db(self) -> None:
         self.platform_info.update(
             {
                 "aarch64-darwin": {"cpu": "aarch64", "os": "darwin", "is_hie": False},
+                "xtensa-esp32-elf": {"cpu": "xtensa", "os": "none", "is_hie": True},
                 "riscv32-elf": {"cpu": "riscv32", "os": "none", "is_hie": True},
                 "riscv64-elf": {"cpu": "riscv64", "os": "none", "is_hie": True},
                 "riscv32-unknown-elf": {"cpu": "riscv32", "os": "none", "is_hie": True},
@@ -44,6 +46,7 @@ def update_db(self) -> None:
         self.build_targets.update(
             {
                 "aarch64-darwin": {"name": "aarch64-apple-darwin%(os_version)s"},
+                "xtensa-esp32-elf": {"name": "xtensa-esp32-elf"},
                 "riscv32-elf": {"name": "riscv32-elf"},
                 "riscv64-elf": {"name": "riscv64-elf"},
                 "riscv32-unknown-elf": {"name": "riscv32-unknown-elf"},
diff --git a/sanity-checking/drivers/platform_db.py b/sanity-checking/drivers/platform_db.py
index c88aed9..e7408c6 100644
--- a/sanity-checking/drivers/platform_db.py
+++ b/sanity-checking/drivers/platform_db.py
@@ -4,6 +4,7 @@ class PlatDB(PlatformDBPlugin):
     def update_db(self) -> None:
         self.cpu_info.update(
             {
+                "xtensa": {"endian": "little", "bits": 32},
                 "riscv32": {"endian": "little", "bits": 32},
                 "riscv64": {"endian": "little", "bits": 64},
             }
@@ -23,6 +24,7 @@ def update_db(self) -> None:
         self.host_guess.pop("x86-windows")
         self.host_guess.update(
             {
+                "aarch64-darwin": {"os": "Darwin", "cpu": "arm64"},
                 "x86_64-windows64": {
                     "os": "Windows",
                     "cpu": "AMD64",
@@ -32,6 +34,8 @@ def update_db(self) -> None:
 
         self.platform_info.update(
             {
+                "aarch64-darwin": {"cpu": "aarch64", "os": "darwin", "is_hie": False},
+                "xtensa-esp32-elf": {"cpu": "xtensa", "os": "none", "is_hie": True},
                 "riscv32-elf": {"cpu": "riscv32", "os": "none", "is_hie": True},
                 "riscv64-elf": {"cpu": "riscv64", "os": "none", "is_hie": True},
                 "riscv32-unknown-elf": {"cpu": "riscv32", "os": "none", "is_hie": True},
@@ -41,6 +45,8 @@ def update_db(self) -> None:
 
         self.build_targets.update(
             {
+                "aarch64-darwin": {"name": "aarch64-apple-darwin%(os_version)s"},
+                "xtensa-esp32-elf": {"name": "xtensa-esp32-elf"},
                 "riscv32-elf": {"name": "riscv32-elf"},
                 "riscv64-elf": {"name": "riscv64-elf"},
                 "riscv32-unknown-elf": {"name": "riscv32-unknown-elf"},
diff --git a/specs/gcc.anod b/specs/gcc.anod
index 77752f4..b3ef2e3 100644
--- a/specs/gcc.anod
+++ b/specs/gcc.anod
@@ -176,6 +176,11 @@ class GCC(spec("gh-artifact")):
             args += cross_commons
             args.append("--enable-multilib")
 
+        if self.env.target.triplet == "extensa-esp32-elf":
+            args += cross_commons
+            args.append("--enable-multilib")
+
+
         return args
 
     def artifact_build(self):
diff --git a/specs/release_package.anod b/specs/release_package.anod
index 76d5295..a43c03d 100644
--- a/specs/release_package.anod
+++ b/specs/release_package.anod
@@ -140,6 +140,12 @@ class ReleasePackage(spec("common")):
                     Anod.Dependency("avrlibc", track=True),
                 ]
 
+            elif self.env.target.triplet == "xtensa-esp32-elf":
+                return [
+                    Anod.Dependency("gcc", track=True),
+                    Anod.Dependency("gdb", track=True),
+                ]
+
             elif self.env.host.triplet == self.env.target.triplet:
                 # Native
                 return [

From d3303f9e3594d7a47ac0e1e8fb01c2c42fd9a20b Mon Sep 17 00:00:00 2001
From: Fabien Chouteau <chouteau@adacore.com>
Date: Thu, 22 Aug 2024 13:44:56 +0200
Subject: [PATCH 4/4] Install texinfo for cross builds on macOS aarch64

---
 .github/workflows/macos_arm.yml | 4 ++++
 1 file changed, 4 insertions(+)

diff --git a/.github/workflows/macos_arm.yml b/.github/workflows/macos_arm.yml
index 80e974a..c293b12 100644
--- a/.github/workflows/macos_arm.yml
+++ b/.github/workflows/macos_arm.yml
@@ -67,6 +67,10 @@ jobs:
     - name: Checkout Project
       uses: actions/checkout@v2
 
+
+    - name: Install texinfo with Homebrew
+      run: brew install texinfo
+
     - uses: actions/download-artifact@v2
       with:
         name: anod-artifacts