Skip to content

Commit

Permalink
Allow dmd on macos arm64
Browse files Browse the repository at this point in the history
Signed-off-by: Andrei Horodniceanu <[email protected]>
  • Loading branch information
the-horo committed Jul 13, 2024
1 parent 7daa995 commit d8e9cb9
Show file tree
Hide file tree
Showing 8 changed files with 20 additions and 13 deletions.
9 changes: 7 additions & 2 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -48,8 +48,11 @@ jobs:
dmd-master,
]
include:
# macOS-latest is arm64, not supported by dmd
# Needs >=dmd-2.107.1 due to https://issues.dlang.org/show_bug.cgi?id=24137
- { os: macOS-latest, dc: dmd-2.108.1-rc.1 }
- { os: macOS-latest, dc: dmd-2.109 }
- { os: macOS-latest, dc: dmd-latest }
- { os: macOS-latest, dc: dmd-master }
- { os: macOS-13, dc: dmd-2.108.1-rc.1 }
- { os: macOS-13, dc: dmd-2.107 }
- { os: macOS-13, dc: dmd-latest }
Expand Down Expand Up @@ -124,7 +127,7 @@ jobs:
strategy:
fail-fast: false
matrix:
os: [ ubuntu-latest, windows-latest, macOS-13 ]
os: [ ubuntu-latest, windows-latest, macos-latest, macOS-13 ]
dc: [ ldc-latest, dmd-latest, gdc, gdc-12 ]
dub: [ 1.19.0, 1.23.0, latest ]
exclude:
Expand All @@ -135,6 +138,8 @@ jobs:
- { os: windows-latest, dc: gdc-12 }
- { os: macOS-13, dc: gdc }
- { os: macOS-13, dc: gdc-12 }
- { os: macOS-latest, dc: gdc }
- { os: macOS-latest, dc: gdc-12 }
runs-on: ${{ matrix.os }}
steps:
- uses: actions/checkout@v4
Expand Down
4 changes: 3 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -189,7 +189,6 @@ The default value for this input is `latest` and it is required when using GDC.
### DMD

All DMD versions of releases and pre-releases since 2.065.0 on https://downloads.dlang.org/releases/2.x/ and https://downloads.dlang.org/pre-releases/2.x/ are supported.
Be aware that with the `macos-latest` (that currently resolve to `macos-14`) runners, the cpu architecture is arm64 and because of this dmd doesn't work on them.

DMD releases come with some extra tools like `rdmd` and `dub`. You are free to use them at your leisure.

Expand Down Expand Up @@ -253,3 +252,6 @@ Now it is downloaded and setup unconditionally.
Introduces the `DMD` variable which will point to the dmd wrapper of the selected compiler.
For example if you install `ldc-1.37.0` then `DC` will point to `<extracted_path>/ldc2` and `DMD` will point to `<extracted_path>/ldmd2`
This variable is setup for all compilers, automatically.

`dmd` is now allowed on `macos-latest` (arm64).
It should work even if it's a x86_64 binary thanks to the Rosetta compatibility layer.
6 changes: 4 additions & 2 deletions __tests__/action_input.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import * as core from '@actions/core'
import * as d from '../src/d'
import * as testUtils from './test-helpers.test'
testUtils.saveProcessRestorePoint()
testUtils.disableNetwork()

describe('Testing compiler when...', function(){
beforeAll(() => jest.spyOn(core, 'getInput').mockReturnValue(''))
Expand Down Expand Up @@ -37,10 +38,11 @@ describe('Testing compiler when...', function(){
d_compiler: 'invalid text', gh_token: '', dub_version: '', gdmd_sha: '',})
})

test('it is dmd on arm64', () => {
// https://github.com/dlang-community/setup-dlang/issues/78
test('it is dmd on arm64 issue#78', () => {
Object.defineProperty(process, 'arch', { value: 'arm64' })
mockCompiler('dmd-beta')
expect(main.getActionInputs).toThrow('dmd')
expect(main.getActionInputs()).toHaveProperty('d_compiler', 'dmd-beta')
})
});

Expand Down
6 changes: 4 additions & 2 deletions __tests__/d-dmd.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -425,9 +425,11 @@ test('dmd gracefully handles invalid versions', async () => {
await expect(init(unexpected)).rejects.toThrow('dmd')
})

test('dmd fails on non-x64', async () => {
// https://github.com/dlang-community/setup-dlang/issues/78
test("dmd doesn't fail on arm64 macos #78", async () => {
Object.defineProperty(process, 'arch', { value: 'arm64' })
expect(init('dmd-2.109.0')).rejects.toThrow(process.arch)
Object.defineProperty(process, 'platform', { value: 'darwin' })
expect(init('dmd-2.109.0')).resolves.toHaveProperty('version', '2.109.0')
})

test('dmd fails on unsupported platforms', async () => {
Expand Down
2 changes: 1 addition & 1 deletion dist/index.js

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion dist/index.js.map

Large diffs are not rendered by default.

2 changes: 0 additions & 2 deletions src/d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -182,8 +182,6 @@ export class DMD extends Compiler {
All of the formats /except/ dmd-master come with a signature file.
*/
static async initialize(versionString: string, token: string): Promise<DMD> {
if (process.arch != 'x64')
throw new Error(`dmd can only be used on x86_64, not on '${process.arch}'`)
if (versionString == 'dmd-master') {
return await DMD.initializeFromMaster(token)
}
Expand Down
2 changes: 0 additions & 2 deletions src/main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,6 @@ export function getActionInputs() {
default_compiler = "ldc-latest";
}
const d_compiler = core.getInput('compiler') || default_compiler;
if (process.arch != "x64" && d_compiler.startsWith("dmd"))
throw new Error("The dmd compiler is not supported for non-x64 architecture");
const gh_token = core.getInput('gh_token') || "";
const dub_version = core.getInput('dub') || "";
const gdmd_sha = core.getInput('gdmd_sha') || ""
Expand Down

0 comments on commit d8e9cb9

Please sign in to comment.