Skip to content

Commit

Permalink
Merge branch 'windows' of github.com:dabrahams/citron
Browse files Browse the repository at this point in the history
  • Loading branch information
dabrahams committed Dec 29, 2023
2 parents 3a059c1 + 4c72f9a commit 90d3d61
Show file tree
Hide file tree
Showing 46 changed files with 1,683 additions and 46 deletions.
4 changes: 4 additions & 0 deletions .devcontainer/Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
ARG SWIFT_VERSION

FROM swift:${SWIFT_VERSION}

46 changes: 46 additions & 0 deletions .devcontainer/devcontainer.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
{
"name": "Swift",
"build": {
"dockerfile": "Dockerfile",
"args": {
"SWIFT_VERSION" : "5.8"
}
},
"features": {
"ghcr.io/devcontainers/features/common-utils:2": {
"installZsh": "false",
"username": "vscode",
"userUid": "1000",
"userGid": "1000",
"upgradePackages": "false"
},
"ghcr.io/devcontainers/features/git:1": {
"version": "os-provided",
"ppa": "false"
}
},
"runArgs": [
"--cap-add=SYS_PTRACE",
"--security-opt",
"seccomp=unconfined"
],
// Configure tool-specific properties.
"customizations": {
// Configure properties specific to VS Code.
"vscode": {
// Set *default* container specific settings.json values on container create.
"settings": {
"lldb.library": "/usr/lib/liblldb.so"
},
// Add the IDs of extensions you want installed when the container is created.
"extensions": [
"sswg.swift-lang"
]
}
},
// Use 'forwardPorts' to make a list of ports inside the container available locally.
// "forwardPorts": [],

// Set `remoteUser` to `root` to connect as root instead. More info: https://aka.ms/vscode-remote/containers/non-root.
"remoteUser": "vscode"
}
80 changes: 80 additions & 0 deletions .github/workflows/build-and-test.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,80 @@
---
name: Build and test

"on":
push:
branches: ["**"]

jobs:

devcontainer:
name: "Devcontainer: ${{ matrix.os }}/${{ matrix.configuration }}"
strategy:
matrix:
os: [ubuntu-latest]
configuration: [debug]

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

- name: Build and Test
uses: devcontainers/ci@v0.3
with:
runCmd: swift test -c ${{ matrix.configuration }}

native:
name: "Native: ${{ matrix.os }}/${{ matrix.configuration }}"
strategy:
fail-fast: false
matrix:
os: [macos-latest, ubuntu-latest, windows-latest]

configuration: [debug]

include:
# Default values to add
- shell: 'bash -eo pipefail {0}'
- build-options: '--explicit-target-dependency-import-check=error'

# Overrides for the defaults
- shell: pwsh
os: windows-latest

runs-on: ${{ matrix.os }}

defaults:
run:
shell: ${{ matrix.shell }}

steps:
- name: Checkout
uses: actions/checkout@v3

- name: Setup Swift (Unices)
if: ${{ matrix.os != 'windows-latest' }}
uses: 'swift-actions/setup-swift@v1'
with:
version: 5.9

- name: Setup Swift (Windows)
if: ${{ matrix.os == 'windows-latest' }}
uses: 'compnerd/gha-setup-swift@main'
with:
github-repo: thebrowsercompany/swift-build
release-asset-name: installer-amd64.exe
release-tag-name: 20231010.3
github-token: ${{ secrets.GITHUB_TOKEN }}

- name: Build and Test (${{ matrix.configuration }})
run: >
swift test -c ${{ matrix.configuration }} ${{ matrix.build-options }}
--explicit-target-dependency-import-check=error
- name: Test non-reentrant build (Windows)
if: ${{ matrix.os == 'windows-latest' }}
run: |
swift package clean
$env:SPM_BUILD_TOOL_SUPPORT_NO_REENTRANT_BUILD=1
swift build -c ${{ matrix.configuration }} ${{ matrix.build-options }} --product citron
swift test -c ${{ matrix.configuration }} ${{ matrix.build-options }}
22 changes: 19 additions & 3 deletions Package.swift
Original file line number Diff line number Diff line change
@@ -1,8 +1,17 @@
// swift-tools-version:5.6
// The swift-tools-version declares the minimum version of Swift required to build this package.

import Foundation
import PackageDescription

// Define a constant to clean up dependency management for SPM bug workarounds (see
// LocalTargetCommandDemoPlugin below). Swift only allows conditional compilation at statement
// granularity so that becomes very inconvenient otherwise.
#if os(Windows)
let osIsWindows = true
#else
let osIsWindows = false
#endif

let package = Package(
name: "citron",
products: [
Expand All @@ -12,12 +21,13 @@ let package = Package(
.plugin(name: "CitronParserGenerator", targets: ["CitronParserGenerator"])
],
targets: [
.executableTarget(name: "citron"),
.executableTarget(name: "citron", dependencies: ["CitronCLibrary"]),
.target(name: "CitronParserModule", exclude: ["LICENSE.txt"]),
.target(name: "CitronLexerModule", exclude: ["LICENSE.txt"]),
.target(name: "CitronCLibrary"),
.plugin(
name: "CitronParserGenerator", capability: .buildTool(),
dependencies: ["citron"]),
dependencies: osIsWindows ? [] : ["citron"]),

// Examples
.executableTarget(
Expand Down Expand Up @@ -47,5 +57,11 @@ let package = Package(
path: "examples/functype_ec",
exclude: ["README.md", "Makefile"],
plugins: [.plugin(name: "CitronParserGenerator")]),

.testTarget(
name: "CitronTests",
// https://github.com/apple/swift-package-manager/issues/6367
dependencies: osIsWindows ? [] : ["expr", "expr_ec", "functype", "functype_ec"]
),
]
)
10 changes: 5 additions & 5 deletions Plugins/CitronParserGenerator/CitronParserGenerator.swift
Original file line number Diff line number Diff line change
@@ -1,20 +1,20 @@
import PackagePlugin

@main
struct CitronParserGenerator: BuildToolPlugin {
struct CitronParserGenerator: SPMBuildToolPlugin {

func createBuildCommands(context: PluginContext, target: Target) throws -> [Command] {
func buildCommands(context: PluginContext, target: Target) throws -> [SPMBuildCommand] {
guard let target = target as? SourceModuleTarget else { return [] }
let inputFiles = target.sourceFiles.filter({ [ "citron", "y"].contains($0.path.extension) })
return try inputFiles.map {
return inputFiles.map {
let inputFile = $0
let inputPath = inputFile.path
let outputName = inputPath.stem + ".swift"
let outputPath = context.pluginWorkDirectory.appending(outputName)
return .buildCommand(
displayName: "Generating \(outputName) from \(inputPath.lastComponent)",
executable: try context.tool(named: "citron").path,
arguments: [ "\(inputPath)", "-o", "\(outputPath)" ],
executable: .targetInThisPackage("citron"),
arguments: [ "\(inputPath.platformString)", "-o", "\(outputPath.platformString)" ],
inputFiles: [ inputPath, ],
outputFiles: [ outputPath ]
)
Expand Down
1 change: 1 addition & 0 deletions Plugins/CitronParserGenerator/SPMBuildToolSupport.swift
4 changes: 4 additions & 0 deletions SPMBuildToolSupport/.devcontainer/Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
ARG SWIFT_VERSION

FROM swift:${SWIFT_VERSION}

46 changes: 46 additions & 0 deletions SPMBuildToolSupport/.devcontainer/devcontainer.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
{
"name": "Swift",
"build": {
"dockerfile": "Dockerfile",
"args": {
"SWIFT_VERSION" : "5.8"
}
},
"features": {
"ghcr.io/devcontainers/features/common-utils:2": {
"installZsh": "false",
"username": "vscode",
"userUid": "1000",
"userGid": "1000",
"upgradePackages": "false"
},
"ghcr.io/devcontainers/features/git:1": {
"version": "os-provided",
"ppa": "false"
}
},
"runArgs": [
"--cap-add=SYS_PTRACE",
"--security-opt",
"seccomp=unconfined"
],
// Configure tool-specific properties.
"customizations": {
// Configure properties specific to VS Code.
"vscode": {
// Set *default* container specific settings.json values on container create.
"settings": {
"lldb.library": "/usr/lib/liblldb.so"
},
// Add the IDs of extensions you want installed when the container is created.
"extensions": [
"sswg.swift-lang"
]
}
},
// Use 'forwardPorts' to make a list of ports inside the container available locally.
// "forwardPorts": [],

// Set `remoteUser` to `root` to connect as root instead. More info: https://aka.ms/vscode-remote/containers/non-root.
"remoteUser": "vscode"
}
4 changes: 4 additions & 0 deletions SPMBuildToolSupport/.dir-locals.el
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
;;; Directory Local Variables -*- no-byte-compile: t -*-
;;; For more information see (info "(emacs) Directory Variables")

((nil . ((fill-column . 100))))
12 changes: 12 additions & 0 deletions SPMBuildToolSupport/.editorconfig
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
# EditorConfig is awesome: https://EditorConfig.org

# top-most EditorConfig file
root = true

# A newline ending every file
[*]
# end_of_line = lf
insert_final_newline = true
charset = utf-8
indent_style = space
indent_size = 2
94 changes: 94 additions & 0 deletions SPMBuildToolSupport/.github/workflows/build-and-test.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,94 @@
---
name: Build and test

"on":
push:
branches: [main, rewrite]
paths-ignore:
- "Docs/**"
- "**.md"
- "README.md"
- "LICENSE"
- ".gitignore"
pull_request:
branches: ["**"]
paths-ignore:
- "Docs/**"
- "**.md"
- "README.md"
- "LICENSE"
- ".gitignore"

jobs:

devcontainer:
name: "Devcontainer: ${{ matrix.os }}/${{ matrix.configuration }}"
strategy:
matrix:
os: [ubuntu-latest]
configuration: [debug]

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

- name: Build and Test
uses: devcontainers/ci@v0.3
with:
runCmd: swift test -c ${{ matrix.configuration }}

native:
name: "Native: ${{ matrix.os }}/${{ matrix.configuration }}"
strategy:
fail-fast: false
matrix:
os: [macos-latest, ubuntu-latest, windows-latest]

configuration: [debug]

include:
# Default values to add
- shell: 'bash -eo pipefail {0}'
- build-options: '--explicit-target-dependency-import-check=error'

# Overrides for the defaults
- shell: pwsh
os: windows-latest

runs-on: ${{ matrix.os }}

defaults:
run:
shell: ${{ matrix.shell }}

steps:
- name: Checkout
uses: actions/checkout@v3

- name: Setup Swift (Unices)
if: ${{ matrix.os != 'windows-latest' }}
uses: 'swift-actions/setup-swift@v1'
with:
version: 5.9

- name: Setup Swift (Windows)
if: ${{ matrix.os == 'windows-latest' }}
uses: 'compnerd/gha-setup-swift@main'
with:
github-repo: thebrowsercompany/swift-build
release-asset-name: installer-amd64.exe
release-tag-name: 20231010.3
github-token: ${{ secrets.GITHUB_TOKEN }}

- name: Build and Test (${{ matrix.configuration }})
run: >
swift test -c ${{ matrix.configuration }} ${{ matrix.build-options }}
--explicit-target-dependency-import-check=error
- name: Test non-reentrant build (Windows)
if: ${{ matrix.os == 'windows-latest' }}
run: |
swift package clean
$env:SPM_BUILD_TOOL_SUPPORT_NO_REENTRANT_BUILD=1
swift build -c ${{ matrix.configuration }} ${{ matrix.build-options }} --product GenerateResource
swift test -c ${{ matrix.configuration }} ${{ matrix.build-options }}
Loading

0 comments on commit 90d3d61

Please sign in to comment.