From 2abd224fe14f7b9ccc7564b95fcb3e5013fc276c Mon Sep 17 00:00:00 2001
From: Andrew Morgan <andrew@amorgan.xyz>
Date: Tue, 3 Dec 2024 17:40:15 +0000
Subject: [PATCH 1/5] Revert "Stop building wheels for macOS"

This reverts commit 650492ed4d95ca8bf9a41eb0456c7e82b4616a22.
---
 .github/workflows/release-artifacts.yml | 10 ++++++++--
 1 file changed, 8 insertions(+), 2 deletions(-)

diff --git a/.github/workflows/release-artifacts.yml b/.github/workflows/release-artifacts.yml
index 0c0e023c753..42a374fa190 100644
--- a/.github/workflows/release-artifacts.yml
+++ b/.github/workflows/release-artifacts.yml
@@ -5,7 +5,7 @@ name: Build release artifacts
 on:
   # we build on PRs and develop to (hopefully) get early warning
   # of things breaking (but only build one set of debs). PRs skip
-  # building wheels on ARM.
+  # building wheels on macOS & ARM.
   pull_request:
   push:
     branches: ["develop", "release-*"]
@@ -111,7 +111,7 @@ jobs:
     runs-on: ${{ matrix.os }}
     strategy:
       matrix:
-        os: [ubuntu-22.04]
+        os: [ubuntu-22.04, macos-13]
         arch: [x86_64, aarch64]
         # is_pr is a flag used to exclude certain jobs from the matrix on PRs.
         # It is not read by the rest of the workflow.
@@ -119,6 +119,12 @@ jobs:
           - ${{ startsWith(github.ref, 'refs/pull/') }}
 
         exclude:
+          # Don't build macos wheels on PR CI.
+          - is_pr: true
+            os: "macos-13"
+          # Don't build aarch64 wheels on mac.
+          - os: "macos-13"
+            arch: aarch64
           # Don't build aarch64 wheels on PR CI.
           - is_pr: true
             arch: aarch64

From 2555b6734bbe77221ee2deaae71cf5e6af64d76b Mon Sep 17 00:00:00 2001
From: Andrew Morgan <andrew@amorgan.xyz>
Date: Tue, 3 Dec 2024 17:38:54 +0000
Subject: [PATCH 2/5] Pin Rust to 1.82.0 when building wheels

---
 pyproject.toml | 7 +++++--
 1 file changed, 5 insertions(+), 2 deletions(-)

diff --git a/pyproject.toml b/pyproject.toml
index 6fd6a952197..60c62015b7e 100644
--- a/pyproject.toml
+++ b/pyproject.toml
@@ -386,8 +386,11 @@ build-backend = "poetry.core.masonry.api"
 #    c.f. https://github.com/matrix-org/synapse/pull/14259
 skip = "cp36* cp37* cp38* pp37* pp38* *-musllinux_i686 pp*aarch64 *-musllinux_aarch64"
 
-# We need a rust compiler
-before-all =  "curl https://sh.rustup.rs -sSf | sh -s -- --default-toolchain stable -y --profile minimal"
+# We need a rust compiler.
+#
+# We temporarily pin Rust to 1.82.0 to work around
+# https://github.com/element-hq/synapse/issues/17988
+before-all =  "curl https://sh.rustup.rs -sSf | sh -s -- --default-toolchain 1.82.0 -y --profile minimal"
 environment= { PATH = "$PATH:$HOME/.cargo/bin" }
 
 # For some reason if we don't manually clean the build directory we

From 2050ee49f9f8e4c0085b84c2d6c1e066f7dd6b18 Mon Sep 17 00:00:00 2001
From: Andrew Morgan <andrew@amorgan.xyz>
Date: Tue, 3 Dec 2024 17:41:32 +0000
Subject: [PATCH 3/5] TEMP: Build MacOS wheels on PR CI

---
 .github/workflows/release-artifacts.yml | 13 ++++---------
 1 file changed, 4 insertions(+), 9 deletions(-)

diff --git a/.github/workflows/release-artifacts.yml b/.github/workflows/release-artifacts.yml
index 42a374fa190..74a0f60333b 100644
--- a/.github/workflows/release-artifacts.yml
+++ b/.github/workflows/release-artifacts.yml
@@ -119,12 +119,7 @@ jobs:
           - ${{ startsWith(github.ref, 'refs/pull/') }}
 
         exclude:
-          # Don't build macos wheels on PR CI.
-          - is_pr: true
-            os: "macos-13"
-          # Don't build aarch64 wheels on mac.
-          - os: "macos-13"
-            arch: aarch64
+          # Temporarily build wheels on PR CI to test.
           # Don't build aarch64 wheels on PR CI.
           - is_pr: true
             arch: aarch64
@@ -151,9 +146,9 @@ jobs:
         if: matrix.arch == 'aarch64'
         run: echo 'CIBW_ARCHS_LINUX=aarch64' >> $GITHUB_ENV
 
-      - name: Only build a single wheel on PR
-        if: startsWith(github.ref, 'refs/pull/')
-        run: echo "CIBW_BUILD="cp39-manylinux_${{ matrix.arch }}"" >> $GITHUB_ENV
+      # - name: Only build a single wheel on PR
+      #   if: startsWith(github.ref, 'refs/pull/')
+      #   run: echo "CIBW_BUILD="cp39-manylinux_${{ matrix.arch }}"" >> $GITHUB_ENV
 
       - name: Build wheels
         run: python -m cibuildwheel --output-dir wheelhouse

From 239f77cca336db89be834f1d355fdebbdd1fd7c1 Mon Sep 17 00:00:00 2001
From: Andrew Morgan <andrew@amorgan.xyz>
Date: Tue, 3 Dec 2024 17:44:37 +0000
Subject: [PATCH 4/5] newsfile

---
 changelog.d/17993.misc | 1 +
 1 file changed, 1 insertion(+)
 create mode 100644 changelog.d/17993.misc

diff --git a/changelog.d/17993.misc b/changelog.d/17993.misc
new file mode 100644
index 00000000000..149cb358c3c
--- /dev/null
+++ b/changelog.d/17993.misc
@@ -0,0 +1 @@
+Fix building wheels for MacOS which was temporarily disabled in Synapse 1.120.2.
\ No newline at end of file

From f0bc9927ff33689f37e50cbeb3952819553255b7 Mon Sep 17 00:00:00 2001
From: Andrew Morgan <andrew@amorgan.xyz>
Date: Wed, 4 Dec 2024 12:09:44 +0000
Subject: [PATCH 5/5] Revert "TEMP: Build MacOS wheels on PR CI"

This reverts commit 2050ee49f9f8e4c0085b84c2d6c1e066f7dd6b18.
---
 .github/workflows/release-artifacts.yml | 13 +++++++++----
 1 file changed, 9 insertions(+), 4 deletions(-)

diff --git a/.github/workflows/release-artifacts.yml b/.github/workflows/release-artifacts.yml
index 74a0f60333b..42a374fa190 100644
--- a/.github/workflows/release-artifacts.yml
+++ b/.github/workflows/release-artifacts.yml
@@ -119,7 +119,12 @@ jobs:
           - ${{ startsWith(github.ref, 'refs/pull/') }}
 
         exclude:
-          # Temporarily build wheels on PR CI to test.
+          # Don't build macos wheels on PR CI.
+          - is_pr: true
+            os: "macos-13"
+          # Don't build aarch64 wheels on mac.
+          - os: "macos-13"
+            arch: aarch64
           # Don't build aarch64 wheels on PR CI.
           - is_pr: true
             arch: aarch64
@@ -146,9 +151,9 @@ jobs:
         if: matrix.arch == 'aarch64'
         run: echo 'CIBW_ARCHS_LINUX=aarch64' >> $GITHUB_ENV
 
-      # - name: Only build a single wheel on PR
-      #   if: startsWith(github.ref, 'refs/pull/')
-      #   run: echo "CIBW_BUILD="cp39-manylinux_${{ matrix.arch }}"" >> $GITHUB_ENV
+      - name: Only build a single wheel on PR
+        if: startsWith(github.ref, 'refs/pull/')
+        run: echo "CIBW_BUILD="cp39-manylinux_${{ matrix.arch }}"" >> $GITHUB_ENV
 
       - name: Build wheels
         run: python -m cibuildwheel --output-dir wheelhouse