Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Compilation for Linux, MacOS, and Windows #17

Closed
wants to merge 38 commits into from
Closed
Show file tree
Hide file tree
Changes from 20 commits
Commits
Show all changes
38 commits
Select commit Hold shift + click to select a range
1d0a6f5
Added Windows specific modifications
kuniss Mar 5, 2023
1eec841
Added Windows specifc modidications and helper function
kuniss Mar 5, 2023
5bc752d
Added Windows specific test code alternatives
kuniss Mar 5, 2023
ea14db9
Enabled matrix build for Linux, MaxOS, and Windows
kuniss Mar 5, 2023
dcfb072
Renamed build script to "build.yml"
kuniss Mar 5, 2023
3e0d2c5
Removed unittest job
kuniss Mar 5, 2023
17a0e69
Switched to ldc-latest for faster code.
kuniss Mar 13, 2023
acde0f7
Swicthed back to DMD for testing.
kuniss Mar 13, 2023
6084930
Added a release worflow
kuniss Dec 27, 2023
0cb4ecf
Pinned dmd and ldc versions
kuniss Dec 27, 2023
4ebccca
Pinned dmd and ldc versions
kuniss Dec 27, 2023
2467e84
Give executables unique names before upload
kuniss Dec 27, 2023
52150bf
Avoid GH releases are triggering build.yml
kuniss Dec 27, 2023
3a6aafa
Corrected release exe renaming for Windows
kuniss Dec 27, 2023
e6be91e
Ignore tags starting with 'v' only
kuniss Dec 27, 2023
f1f16b6
One asterisk is enough for matching a tag
kuniss Dec 27, 2023
6d2ebe2
Force a push to trigger a build
kuniss Dec 27, 2023
5befcc2
Revert back to original push event specification
kuniss Dec 27, 2023
405d93a
Ensure test is running before release upload.
kuniss Dec 27, 2023
11c93a9
Upgraded dscanner to version 0.14.0
kuniss Dec 27, 2023
9255ab6
Added executableName() for Windows' ".exe" extension
kuniss Dec 30, 2023
aac3c2a
Renamed build.yml to ci.yml
kuniss Dec 30, 2023
50d8851
Merge branch 'master' into cross-compilation
linkrope Dec 30, 2023
2f39e92
Refactored out reusable workflows
kuniss Jan 3, 2024
fb4287e
Referenced reusable workflows
kuniss Jan 3, 2024
c071bc8
Define compiler versions as workflow parameters
kuniss Jan 3, 2024
5425d17
Added uploading of built executables
kuniss Jan 3, 2024
60c44b0
Corrected source path for upload step
kuniss Jan 3, 2024
4b544ed
Bumped actions/upload-artifact to v4
kuniss Jan 3, 2024
79e239d
Rewritten release workflow
kuniss Jan 3, 2024
54388a8
Corrected the renaming for the Windows binary
kuniss Jan 3, 2024
4e54fcd
Avoid CI workflow is running on release publications
kuniss Jan 3, 2024
287aa96
Improved matrix names in GH Actions GUI
kuniss Jan 4, 2024
1839c5b
Improved formating
kuniss Jan 4, 2024
b534bcc
Refactored out upload workflow
kuniss Jan 4, 2024
ae44c3e
Removed secret declaration for GITHUB_TOKEN
kuniss Jan 4, 2024
de88bc1
Get rid of OS specific file path separators
kuniss Jan 4, 2024
49328b8
Made locally only used method private
kuniss Jan 6, 2024
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
62 changes: 62 additions & 0 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
name: Build on Push & PR
on: [push, pull_request]

jobs:
build:
name: Build Gamma
strategy:
matrix:
os: [ubuntu-latest, windows-latest, macOS-latest]

runs-on: ${{ matrix.os }}
steps:
- name: Checkout source code
uses: actions/checkout@v3

- name: Install D compiler
uses: dlang-community/setup-dlang@v1
with:
compiler: ldc-1.33.0

- name: Run build
run: |
dub build

test:
name: Test Gamma
strategy:
matrix:
os: [ubuntu-latest, windows-latest, macOS-latest]

runs-on: ${{ matrix.os }}
steps:
- name: Checkout source codet
uses: actions/checkout@v3

- name: Install D compiler
uses: dlang-community/setup-dlang@v1
with:
compiler: dmd-2.103.1

- name: Run tests
run: |
dub test --config=example

check:
name: Check Style
runs-on: ubuntu-latest
steps:
- name: Checkout source code
uses: actions/checkout@v3

- name: Install D compiler
uses: dlang-community/setup-dlang@v1
with:
compiler: dmd-2.103.1

- run: |
dub fetch [email protected]

- name: Check style
run: |
dub run dscanner -- --styleCheck src test
27 changes: 0 additions & 27 deletions .github/workflows/d.yml
linkrope marked this conversation as resolved.
Show resolved Hide resolved

This file was deleted.

66 changes: 66 additions & 0 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
name: Release
on:
release:
types: [published]

jobs:

test:
linkrope marked this conversation as resolved.
Show resolved Hide resolved
name: Test Gamma
strategy:
matrix:
os: [ubuntu-latest, windows-latest, macOS-latest]

runs-on: ${{ matrix.os }}
steps:
- name: Checkout source codet
uses: actions/checkout@v3

- name: Install D compiler
uses: dlang-community/setup-dlang@v1
with:
compiler: dmd-2.103.1

- name: Run tests
run: |
dub test --config=example

build:
name: Build Gamma
needs: test
strategy:
matrix:
os: [ubuntu-latest, windows-latest, macOS-latest]
include:
- os: windows-latest
rename: Rename-Item gamma.exe
exe: gamma.windows-amd64.exe
- os: ubuntu-latest
rename: mv ./gamma
exe: gamma.linux-amd64
- os: macOS-latest
rename: mv ./gamma
exe: gamma.macos-amd64

runs-on: ${{ matrix.os }}
steps:
- name: Checkout source code
uses: actions/checkout@v3

- name: Install D compiler
uses: dlang-community/setup-dlang@v1
with:
compiler: ldc-1.33.0

- name: Run build
run: |
dub build

- name: Rename binary
run: ${{ matrix.rename }} ${{ matrix.exe }}

- name: Upload release binary
uses: AButler/[email protected]
with:
files: ${{ matrix.exe }}
repo-token: ${{ secrets.GITHUB_TOKEN }}
21 changes: 20 additions & 1 deletion src/gamma/main.d
Original file line number Diff line number Diff line change
Expand Up @@ -239,9 +239,28 @@ void build(string[] fileNames, string outputDirectory)

if (!outputDirectory.empty)
{
version(Windows)
linkrope marked this conversation as resolved.
Show resolved Hide resolved
{
auto executableName = format!"%s.exe"(fileNames.front.stripExtension);
}
else
{
auto executableName = fileNames.front.stripExtension;
}
args ~= format!"-od=%s"(outputDirectory);
args ~= format!"-of=%s"(fileNames.front.stripExtension);
args ~= format!"-of=%s"(executableName);
}

version(Windows)
linkrope marked this conversation as resolved.
Show resolved Hide resolved
{
import std.string : translate;
for(int i; i < args.length; i++)
{
dchar[dchar] translation = ['/': '\\'];
args[i] = translate(args[i], translation);
}
}

info!"%s"(args.join(' '));

auto pid = spawnProcess(args);
Expand Down
21 changes: 20 additions & 1 deletion test/helper.d
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,18 @@ Result run(string fmt, A...)(lazy A args)
import std.process : executeShell;
import std.stdio : writeln;

const command = format!fmt(args);
auto command = format!fmt(args);

version(Windows)
{
import std.string : translate;
dchar[dchar] translation = ['/': '\\'];
command = translate(command, translation);

import std.regex : regex, replaceAll, replaceFirst;
command = replaceFirst(command, regex("echo\\s+\\|"), "echo. |");
command = replaceAll(command, regex("\\bcat\\b"), "type");
}

writeln(command);
return executeShell(command);
Expand Down Expand Up @@ -57,3 +68,11 @@ Result shouldFailWith(Result result, string pattern)
}
return result;
}

string asSingleLineDosInput(string multiLineInput)
{
import std.string : translate;

string[dchar] translation = ['\n' : " ", '|' : "^|", '<' : "^<", '>' : "^>"];
return translate(multiLineInput, translation);
}
43 changes: 35 additions & 8 deletions test/issues.d
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,17 @@ unittest
A: 'a' A.
`.outdent;

run!"cat <<EOF | ./gamma --output-directory %s%sEOF"(directory, eag)
.shouldFailWith("error: start symbol S is unproductive");
version(Windows)
{
run!"mkdir %s & echo %s > %s\\input.eag && type %s\\input.eag | ./gamma --output-directory %s"
(directory, eag.asSingleLineDosInput, directory, directory, directory)
.shouldFailWith("error: start symbol S is unproductive");
}
else
{
run!"cat <<EOF | ./gamma --output-directory %s%sEOF"(directory, eag)
.shouldFailWith("error: start symbol S is unproductive");
}
}
}

Expand All @@ -31,9 +40,18 @@ unittest
S <+ : S>: A | 'b'.
A: 'a' A.
`.outdent;

run!"cat <<EOF | ./gamma --output-directory %s%sEOF"(directory, eag)
.shouldPassWith("warn: A is unproductive");

version(Windows)
{
run!"mkdir %s & echo %s > %s\\input.eag && type %s\\input.eag | ./gamma --output-directory %s"
(directory, eag.asSingleLineDosInput, directory, directory, directory)
.shouldPassWith("warn: A is unproductive");
}
else
{
run!"cat <<EOF | ./gamma --output-directory %s%sEOF"(directory, eag)
.shouldPassWith("warn: A is unproductive");
}
}
}

Expand All @@ -50,9 +68,18 @@ unittest
S<+ '1' N: N>:
'a' S<N> 'b'.
`.outdent;

run!"cat <<EOF | ./gamma --output-directory %s%sEOF"(directory, eag)
.shouldPassWith("S grammar is SLAG");

version(Windows)
{
run!"mkdir %s & echo %s > %s\\input.eag && type %s\\input.eag | ./gamma --output-directory %s"
(directory, eag.asSingleLineDosInput, directory, directory, directory)
.shouldPassWith("S grammar is SLAG");
}
else
{
run!"cat <<EOF | ./gamma --output-directory %s%sEOF"(directory, eag)
.shouldPassWith("S grammar is SLAG");
}
run!"cd %s && echo aa bbb | ./S"(directory)
.shouldFailWith("syntax error, end expected");
}
Expand Down
57 changes: 42 additions & 15 deletions test/slag.d
Original file line number Diff line number Diff line change
Expand Up @@ -126,15 +126,22 @@ unittest
}
}

@("compile lexer-test.eag as SLAG and run compiler")
unittest
version(Windows)
{
with (sandbox)
// Unicode characters are not really supported on Windows command line...
}
else
{
@("compile lexer-test.eag as SLAG and run compiler")
unittest
{
run!"./gamma --space example/lexer-test.eag --output-directory %s"(directory)
.shouldPassWith("ε grammar is SLAG");
run!`cd %s && echo α β α β \\\\n α β β α| ./ε`(directory)
.shouldPassWith("^α α β β \n α α β β $");
with (sandbox)
{
run!"./gamma --space example/lexer-test.eag --output-directory %s"(directory)
.shouldPassWith("ε grammar is SLAG");
run!`cd %s && echo α β α β \\\\n α β β α| ./ε`(directory)
.shouldPassWith("^α α β β \n α α β β $");
}
}
}

Expand All @@ -159,10 +166,20 @@ unittest
{
run!"./gamma --space example/ebnf.eag --output-directory %s"(directory)
.shouldPassWith("S grammar is SLAG");
run!`cd %s && echo 'a, , ab' | ./S`(directory)
.shouldPassWith("^a , , a b $");
run!`cd %s && echo '"a", "", "ab"' | ./S`(directory)
.shouldPassWith("^a , , a b $");
version(Windows)
{
run!`cd %s && echo a, , ab | ./S`(directory)
.shouldPassWith("^a , , a b $");
run!`cd %s && echo "a", "", "ab" | ./S`(directory)
.shouldPassWith("^a , , a b $");
}
else
{
run!`cd %s && echo 'a, , ab' | ./S`(directory)
.shouldPassWith("^a , , a b $");
run!`cd %s && echo '"a", "", "ab"' | ./S`(directory)
.shouldPassWith("^a , , a b $");
}
}
}

Expand All @@ -173,9 +190,19 @@ unittest
{
run!"./gamma --space example/bnf/ebnf.eag --output-directory %s"(directory)
.shouldPassWith("S grammar is SLAG");
run!`cd %s && echo 'a, , ab' | ./S`(directory)
.shouldPassWith("^a , , a b $");
run!`cd %s && echo '"a", "", "ab"' | ./S`(directory)
.shouldPassWith("^a , , a b $");
version(Windows)
{
run!`cd %s && echo a, , ab | ./S`(directory)
.shouldPassWith("^a , , a b $");
run!`cd %s && echo "a", "", "ab" | ./S`(directory)
.shouldPassWith("^a , , a b $");
}
else
{
run!`cd %s && echo 'a, , ab' | ./S`(directory)
.shouldPassWith("^a , , a b $");
run!`cd %s && echo '"a", "", "ab"' | ./S`(directory)
.shouldPassWith("^a , , a b $");
}
}
}