From be616aa32fbc341e70e3c3c91e8d63c0aa40d0f1 Mon Sep 17 00:00:00 2001 From: mcafaro Date: Mon, 6 May 2024 17:45:05 -0400 Subject: [PATCH 1/6] Install Intel version on Apple silicon prior to R2023b --- .github/workflows/bat.yml | 4 ++++ src/install.ts | 3 +++ 2 files changed, 7 insertions(+) diff --git a/.github/workflows/bat.yml b/.github/workflows/bat.yml index 77eba90..6be53c4 100644 --- a/.github/workflows/bat.yml +++ b/.github/workflows/bat.yml @@ -58,6 +58,10 @@ jobs: products: Symbolic_Math_Toolbox check-matlab: matlabVer = ver('matlab'); assert(~isempty(matlabVer)); check-toolbox: symbolicVer = ver('symbolic'); assert(~isempty(symbolicVer)); + - os: macos-14 + release: R2023a + check-matlab: matlabVer = ver('matlab'); assert(strcmp(matlabVer.Release,'(R2023a)')); + check-toolbox: symbolicVer = ver('symbolic'); assert(strcmp(symbolicVer.Release,'(R2023a)')); steps: - uses: actions/download-artifact@v4 with: diff --git a/src/install.ts b/src/install.ts index 6d4b0df..2fc83be 100644 --- a/src/install.ts +++ b/src/install.ts @@ -23,6 +23,9 @@ export async function install(platform: string, architecture: string, release: s if (releaseInfo.name < "r2020b") { return Promise.reject(Error(`Release '${releaseInfo.name}' is not supported. Use 'R2020b' or a later release.`)); } + if (platform === "darwin" && architecture === "arm64" && releaseInfo.name < "r2023b") { + architecture = "x86"; + } await core.group("Preparing system for MATLAB", async () => matlab.installSystemDependencies(platform, architecture, releaseInfo.name) From 84823928fc2fcf5c6aabbe9e3f1f1a72e34c936c Mon Sep 17 00:00:00 2001 From: mcafaro Date: Mon, 6 May 2024 17:47:56 -0400 Subject: [PATCH 2/6] Use x64 not x86 --- src/install.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/install.ts b/src/install.ts index 2fc83be..32f0cfb 100644 --- a/src/install.ts +++ b/src/install.ts @@ -24,7 +24,7 @@ export async function install(platform: string, architecture: string, release: s return Promise.reject(Error(`Release '${releaseInfo.name}' is not supported. Use 'R2020b' or a later release.`)); } if (platform === "darwin" && architecture === "arm64" && releaseInfo.name < "r2023b") { - architecture = "x86"; + architecture = "x64"; } await core.group("Preparing system for MATLAB", async () => From 950812041dc30827e9033d929f87f9dfeccf1eac Mon Sep 17 00:00:00 2001 From: mcafaro Date: Mon, 6 May 2024 17:56:16 -0400 Subject: [PATCH 3/6] Add sym toolbox to macos-14 --- .github/workflows/bat.yml | 1 + 1 file changed, 1 insertion(+) diff --git a/.github/workflows/bat.yml b/.github/workflows/bat.yml index 6be53c4..350a91f 100644 --- a/.github/workflows/bat.yml +++ b/.github/workflows/bat.yml @@ -60,6 +60,7 @@ jobs: check-toolbox: symbolicVer = ver('symbolic'); assert(~isempty(symbolicVer)); - os: macos-14 release: R2023a + products: Symbolic_Math_Toolbox check-matlab: matlabVer = ver('matlab'); assert(strcmp(matlabVer.Release,'(R2023a)')); check-toolbox: symbolicVer = ver('symbolic'); assert(strcmp(symbolicVer.Release,'(R2023a)')); steps: From 32380731a2c60cad0887d1fdef00dc119d6e9d3c Mon Sep 17 00:00:00 2001 From: mcafaro Date: Tue, 7 May 2024 10:59:37 -0400 Subject: [PATCH 4/6] Install Rosetta 2 when release { expect(mpmSetupMock).toHaveBeenCalledTimes(1); expect(mpmInstallMock).toHaveBeenCalledTimes(1); }); + + it("installs Intel version on Apple silicon prior to R2023b", async () => { + matlabGetReleaseInfoMock.mockResolvedValue({ + name: "r2023a", + version: "9.14.0", + updateNumber: "latest" + }); + await expect(install.install("darwin", "arm64", "r2023a", products, useCache)).resolves.toBeUndefined(); + expect(matlabInstallSystemDependenciesMock).toHaveBeenCalledWith("darwin","x64","r2023a"); + expect(matlabSetupBatchMock).toHaveBeenCalledWith("darwin","x64"); + expect(mpmSetupMock).toHaveBeenCalledWith("darwin","x64"); + }); }); diff --git a/src/matlab.ts b/src/matlab.ts index ac552c8..27f6d25 100644 --- a/src/matlab.ts +++ b/src/matlab.ts @@ -207,7 +207,18 @@ export async function installSystemDependencies(platform: string, architecture: if (platform === "linux") { return script.downloadAndRunScript(platform, properties.matlabDepsUrl, [release]); } else if (platform === "darwin" && architecture === "arm64") { - return installAppleSiliconJdk(); + if (release < "r2023b") { + return installAppleSiliconRosetta(); + } else { + return installAppleSiliconJdk(); + } + } +} + +async function installAppleSiliconRosetta() { + const exitCode = await exec.exec(`sudo softwareupdate --install-rosetta --agree-to-license`); + if (exitCode !== 0) { + return Promise.reject(Error("Unable to install Rosetta 2.")); } } diff --git a/src/matlab.unit.test.ts b/src/matlab.unit.test.ts index 3b262b4..8022747 100644 --- a/src/matlab.unit.test.ts +++ b/src/matlab.unit.test.ts @@ -285,7 +285,7 @@ describe("matlab tests", () => { let tcDownloadToolMock: jest.Mock; let execMock: jest.Mock; const arch = "x64"; - const release = "R2023b"; + const release = "r2023b"; beforeEach(() => { downloadAndRunScriptMock = script.downloadAndRunScript as jest.Mock; @@ -330,6 +330,16 @@ describe("matlab tests", () => { expect(tcDownloadToolMock).toHaveBeenCalledWith(properties.appleSiliconJdkUrl, expect.anything()); expect(execMock).toHaveBeenCalledWith(`sudo installer -pkg "java.jdk" -target /`); }); + + it(`works on mac with apple silicon { + const platform = "darwin"; + tcDownloadToolMock.mockResolvedValue("java.jdk"); + execMock.mockResolvedValue(0); + await expect( + matlab.installSystemDependencies(platform, "arm64", "r2023a") + ).resolves.toBeUndefined(); + expect(execMock).toHaveBeenCalledWith(`sudo softwareupdate --install-rosetta --agree-to-license`); + }); }); it("rejects when the apple silicon JDK download fails", async () => { From be3d7f8199abc47dc3a96512918a1a138a8e5435 Mon Sep 17 00:00:00 2001 From: mcafaro Date: Tue, 7 May 2024 11:29:26 -0400 Subject: [PATCH 5/6] Properly install sys deps for Apple silicon --- src/install.ts | 14 ++++++++------ src/install.unit.test.ts | 4 ++-- 2 files changed, 10 insertions(+), 8 deletions(-) diff --git a/src/install.ts b/src/install.ts index 32f0cfb..0803608 100644 --- a/src/install.ts +++ b/src/install.ts @@ -23,32 +23,34 @@ export async function install(platform: string, architecture: string, release: s if (releaseInfo.name < "r2020b") { return Promise.reject(Error(`Release '${releaseInfo.name}' is not supported. Use 'R2020b' or a later release.`)); } - if (platform === "darwin" && architecture === "arm64" && releaseInfo.name < "r2023b") { - architecture = "x64"; - } await core.group("Preparing system for MATLAB", async () => matlab.installSystemDependencies(platform, architecture, releaseInfo.name) ); await core.group("Setting up MATLAB", async () => { + let matlabArch = architecture; + if (platform === "darwin" && architecture === "arm64" && releaseInfo.name < "r2023b") { + matlabArch = "x64"; + } + let [destination, alreadyExists]: [string, boolean] = await matlab.getToolcacheDir(platform, releaseInfo); let cacheHit = false; if (useCache) { const supportFilesDir = matlab.getSupportPackagesPath(platform, releaseInfo.name); - cacheHit = await cache.restoreMATLAB(releaseInfo, platform, architecture, products, destination, supportFilesDir); + cacheHit = await cache.restoreMATLAB(releaseInfo, platform, matlabArch, products, destination, supportFilesDir); } if (!alreadyExists && !cacheHit) { - const mpmPath: string = await mpm.setup(platform, architecture); + const mpmPath: string = await mpm.setup(platform, matlabArch); await mpm.install(mpmPath, releaseInfo, products, destination); } core.addPath(path.join(destination, "bin")); core.setOutput('matlabroot', destination); - await matlab.setupBatch(platform, architecture); + await matlab.setupBatch(platform, matlabArch); }); return; diff --git a/src/install.unit.test.ts b/src/install.unit.test.ts index 778c65c..a704f83 100644 --- a/src/install.unit.test.ts +++ b/src/install.unit.test.ts @@ -135,8 +135,8 @@ describe("install procedure", () => { version: "9.14.0", updateNumber: "latest" }); - await expect(install.install("darwin", "arm64", "r2023a", products, useCache)).resolves.toBeUndefined(); - expect(matlabInstallSystemDependenciesMock).toHaveBeenCalledWith("darwin","x64","r2023a"); + await expect(install.install("darwin", "arm64", "r2023a", products, true)).resolves.toBeUndefined(); + expect(matlabInstallSystemDependenciesMock).toHaveBeenCalledWith("darwin","arm64","r2023a"); expect(matlabSetupBatchMock).toHaveBeenCalledWith("darwin","x64"); expect(mpmSetupMock).toHaveBeenCalledWith("darwin","x64"); }); From 6125a80b0c4b537f2cdf1eb6a7fa394e8193e21b Mon Sep 17 00:00:00 2001 From: mcafaro Date: Tue, 7 May 2024 11:41:48 -0400 Subject: [PATCH 6/6] Remove unnecessary mock --- src/install.unit.test.ts | 6 +++--- src/matlab.unit.test.ts | 1 - 2 files changed, 3 insertions(+), 4 deletions(-) diff --git a/src/install.unit.test.ts b/src/install.unit.test.ts index a704f83..96beb20 100644 --- a/src/install.unit.test.ts +++ b/src/install.unit.test.ts @@ -136,8 +136,8 @@ describe("install procedure", () => { updateNumber: "latest" }); await expect(install.install("darwin", "arm64", "r2023a", products, true)).resolves.toBeUndefined(); - expect(matlabInstallSystemDependenciesMock).toHaveBeenCalledWith("darwin","arm64","r2023a"); - expect(matlabSetupBatchMock).toHaveBeenCalledWith("darwin","x64"); - expect(mpmSetupMock).toHaveBeenCalledWith("darwin","x64"); + expect(matlabInstallSystemDependenciesMock).toHaveBeenCalledWith("darwin", "arm64", "r2023a"); + expect(matlabSetupBatchMock).toHaveBeenCalledWith("darwin", "x64"); + expect(mpmSetupMock).toHaveBeenCalledWith("darwin", "x64"); }); }); diff --git a/src/matlab.unit.test.ts b/src/matlab.unit.test.ts index 8022747..780aa56 100644 --- a/src/matlab.unit.test.ts +++ b/src/matlab.unit.test.ts @@ -333,7 +333,6 @@ describe("matlab tests", () => { it(`works on mac with apple silicon { const platform = "darwin"; - tcDownloadToolMock.mockResolvedValue("java.jdk"); execMock.mockResolvedValue(0); await expect( matlab.installSystemDependencies(platform, "arm64", "r2023a")