Skip to content

Commit 1e1a817

Browse files
authored
Install Intel version of MATLAB on Apple silicon prior to R2023b (#113)
* Install Intel version on Apple silicon prior to R2023b * Use x64 not x86 * Add sym toolbox to macos-14 * Install Rosetta 2 when release <R2023b * Properly install sys deps for Apple silicon * Remove unnecessary mock
1 parent 6985e68 commit 1e1a817

File tree

5 files changed

+47
-5
lines changed

5 files changed

+47
-5
lines changed

.github/workflows/bat.yml

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,11 @@ jobs:
5858
products: Symbolic_Math_Toolbox
5959
check-matlab: matlabVer = ver('matlab'); assert(~isempty(matlabVer));
6060
check-toolbox: symbolicVer = ver('symbolic'); assert(~isempty(symbolicVer));
61+
- os: macos-14
62+
release: R2023a
63+
products: Symbolic_Math_Toolbox
64+
check-matlab: matlabVer = ver('matlab'); assert(strcmp(matlabVer.Release,'(R2023a)'));
65+
check-toolbox: symbolicVer = ver('symbolic'); assert(strcmp(symbolicVer.Release,'(R2023a)'));
6166
steps:
6267
- uses: actions/download-artifact@v4
6368
with:

src/install.ts

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -29,23 +29,28 @@ export async function install(platform: string, architecture: string, release: s
2929
);
3030

3131
await core.group("Setting up MATLAB", async () => {
32+
let matlabArch = architecture;
33+
if (platform === "darwin" && architecture === "arm64" && releaseInfo.name < "r2023b") {
34+
matlabArch = "x64";
35+
}
36+
3237
let [destination, alreadyExists]: [string, boolean] = await matlab.getToolcacheDir(platform, releaseInfo);
3338
let cacheHit = false;
3439

3540
if (useCache) {
3641
const supportFilesDir = matlab.getSupportPackagesPath(platform, releaseInfo.name);
37-
cacheHit = await cache.restoreMATLAB(releaseInfo, platform, architecture, products, destination, supportFilesDir);
42+
cacheHit = await cache.restoreMATLAB(releaseInfo, platform, matlabArch, products, destination, supportFilesDir);
3843
}
3944

4045
if (!alreadyExists && !cacheHit) {
41-
const mpmPath: string = await mpm.setup(platform, architecture);
46+
const mpmPath: string = await mpm.setup(platform, matlabArch);
4247
await mpm.install(mpmPath, releaseInfo, products, destination);
4348
}
4449

4550
core.addPath(path.join(destination, "bin"));
4651
core.setOutput('matlabroot', destination);
4752

48-
await matlab.setupBatch(platform, architecture);
53+
await matlab.setupBatch(platform, matlabArch);
4954
});
5055

5156
return;

src/install.unit.test.ts

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -128,4 +128,16 @@ describe("install procedure", () => {
128128
expect(mpmSetupMock).toHaveBeenCalledTimes(1);
129129
expect(mpmInstallMock).toHaveBeenCalledTimes(1);
130130
});
131+
132+
it("installs Intel version on Apple silicon prior to R2023b", async () => {
133+
matlabGetReleaseInfoMock.mockResolvedValue({
134+
name: "r2023a",
135+
version: "9.14.0",
136+
updateNumber: "latest"
137+
});
138+
await expect(install.install("darwin", "arm64", "r2023a", products, true)).resolves.toBeUndefined();
139+
expect(matlabInstallSystemDependenciesMock).toHaveBeenCalledWith("darwin", "arm64", "r2023a");
140+
expect(matlabSetupBatchMock).toHaveBeenCalledWith("darwin", "x64");
141+
expect(mpmSetupMock).toHaveBeenCalledWith("darwin", "x64");
142+
});
131143
});

src/matlab.ts

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -207,7 +207,18 @@ export async function installSystemDependencies(platform: string, architecture:
207207
if (platform === "linux") {
208208
return script.downloadAndRunScript(platform, properties.matlabDepsUrl, [release]);
209209
} else if (platform === "darwin" && architecture === "arm64") {
210-
return installAppleSiliconJdk();
210+
if (release < "r2023b") {
211+
return installAppleSiliconRosetta();
212+
} else {
213+
return installAppleSiliconJdk();
214+
}
215+
}
216+
}
217+
218+
async function installAppleSiliconRosetta() {
219+
const exitCode = await exec.exec(`sudo softwareupdate --install-rosetta --agree-to-license`);
220+
if (exitCode !== 0) {
221+
return Promise.reject(Error("Unable to install Rosetta 2."));
211222
}
212223
}
213224

src/matlab.unit.test.ts

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -285,7 +285,7 @@ describe("matlab tests", () => {
285285
let tcDownloadToolMock: jest.Mock;
286286
let execMock: jest.Mock;
287287
const arch = "x64";
288-
const release = "R2023b";
288+
const release = "r2023b";
289289

290290
beforeEach(() => {
291291
downloadAndRunScriptMock = script.downloadAndRunScript as jest.Mock;
@@ -330,6 +330,15 @@ describe("matlab tests", () => {
330330
expect(tcDownloadToolMock).toHaveBeenCalledWith(properties.appleSiliconJdkUrl, expect.anything());
331331
expect(execMock).toHaveBeenCalledWith(`sudo installer -pkg "java.jdk" -target /`);
332332
});
333+
334+
it(`works on mac with apple silicon <R2023b`, async () => {
335+
const platform = "darwin";
336+
execMock.mockResolvedValue(0);
337+
await expect(
338+
matlab.installSystemDependencies(platform, "arm64", "r2023a")
339+
).resolves.toBeUndefined();
340+
expect(execMock).toHaveBeenCalledWith(`sudo softwareupdate --install-rosetta --agree-to-license`);
341+
});
333342
});
334343

335344
it("rejects when the apple silicon JDK download fails", async () => {

0 commit comments

Comments
 (0)