Skip to content

Commit

Permalink
Linux Support (#1188)
Browse files Browse the repository at this point in the history
* work in progress

* More conditional checks, less errors

* Further steps onto successful compilation

* Enabled try-catch back for macOS

* reverted redundant change

* Replaced getVaList with recommended withVaList

* Update FileParser + AttributesModifierSpec.swift

fixed wrong find-replace

* added missing import of CDispatch

* enabled fatalError instead of NSException

* enabled value(forKey:) for TypesCollection type

* removed commented import

* enabled sha256 for macOS

* Enabled sha256 hashing for Linux

* disabled JavaScriptTemplate tests under Linux

* added check for vendor for tests

* disabled value(forKeyPath:) calls under Linux

* reverted redundant gem

* Fixed issue with `swift test` not finding .ejs bundle

* removed commented code

* switched to `swift test`

* enabled GH actions

* Temporary check for installed Xcodes - Update swift.yml

* Temporary checking Xcode versions - Update swift.yml

* Temporary setting Xcode version - Update swift.yml

* Temporary remove custom Ruby installation - Update swift.yml

* Removed spaces from filenames

* removed + from filenames

* Added -enable-testing for all test targets

* Try Xcode 15 beta

* trying to generate LinuxMain

* refactoring

* running a test for test of a test

* set SPM version to 5.8

* added tests to LinuxMain.swift

* removed redundantly disabled code

* fixed wrong ifdef

* Moved diffable implementation to definitions

* fixed failing UTs

* replaced os(macOS) with canImport(ObjectiveC)

* replaced more os(macOS) with canImport(ObjectiveC)

* enabled filtering for sorted arrays on linux

* eliminating API unsupported by swift-corelibs-foundation

* enabled SourceryRuntime to compile under Linux

* isEqual overrides only for Darwin platforms

* Fixed all SourceryRuntime compilation errors; more green tests

* Disabled enum test case

* moved isEqual to definitions

* fatalError when DynamicMemberLookup fails

* disabled failing test

* disabled crashing test in DryOutputSpec

* Fixed more unit tests

* Fixed typo

* Added best effort sorting filter

* added missing dynamic member lookups

* Added missing dynamic member lookup

* fixed compilation error

* Take into account 1-off linebreak issue between Linux and macOS

* Removed diffable from content generation due to new structure

* added missing dynamic member lookups

* Added missing dynamic member lookup

* moving hashing into class definitions

* Moved description and hash into class definitions

* Added DynamicMemberLookup definition for SourceryRuntime

* Added comment why import Stencil is needed

* Added missing dynamic member lookup

* Removed redundant imports

* Fixed failing tests

* Adjusted test expectation for Linux

* Fixed SourcerySpec template combining test

* Temporary commit for CI verification

* Adjusted SwiftTemplateSpecs tests for Linux

* reverted redundant change

* enable more linux tests for CI verification

* Adjusted CodableContextTests for Linux

* Added more tests that are green

* enabled all tests except 3

* Remove verbosity from CI build

* Removed redundant steps from CI

* Reverted redundant change

* Testing job cancellation

* Added new dynamic member lookup to generated sources [no ci]

* Added different TypesCollection definition for Linux

* Make TypesCollection conform to DynamicMemberLookup only on Linux

* Moved TypesCollection to separate generated source file

* Moved Type to separate file for Linux

* Split GitHub actions

* removed common GH action

* added separate file for Variable on linux

* removed DynamicMemberLookup conformance on macOS

* removed @objc conditions on Linux

* Temporary commit to fix build error

* moved NSException workaround to separate file

* Fixed compiler warning

* moved Types to a separate file

* moved generated Types to a separate file

* split Enum.swift into separate files

* removed redundant imports

* added missing import

* Removed redundant import

* Split Method into separate files

* Added DynamicMemberLookup to Method on Linux [no ci]

* removed redundant override

* added badges for GH Actions

* Fixed failing test on macOS

* Split Tuple into separate files for Linux

* Split EnumCase into separate file for DynamicMemberLookup on Linux

* Enabled GeneratorSpec tests

* Added missing lookup member

* Fixed SourcerySpecTests

* enabled SourcerySpec tests

* Added missing lookup member

* call runCLI on Linux

* Disabled codegen for Sourcery

* Added missing member lookup

* Added missing members lookup

* renamed Linux to include experimental

* Added missing member lookups

* Added missing import

* Adjusted padding [no ci]

* Added missing member lookups

* Adjusted padding [no ci]

* Disabled Codable tests on Linux

* enabled all tests classes under Linux

* Added AssociatedValue for Linux

* Added missing member lookups

* Changed resource copy path in TemplatesTests for Linux

* Updated CHANGELOG

* Added LINUX.md

* Added references to README and LINUX

* Updated content.generated files

* Fixed a typo [no ci]

* Changed wording related to @objc attribute

* Use currentTimestamp() instead of Date().timeIntervalSince1970

* Returned guard statements; removed default values from EJSTemplate
  • Loading branch information
art-divin authored Sep 7, 2023
1 parent 3bdaccd commit ba63cd6
Show file tree
Hide file tree
Showing 105 changed files with 17,451 additions and 4,941 deletions.
28 changes: 7 additions & 21 deletions .github/workflows/swift.yml → .github/workflows/Ubuntu.yml
Original file line number Diff line number Diff line change
@@ -1,17 +1,20 @@
# This workflow will build a Swift project
# For more information see: https://docs.github.com/en/actions/automating-builds-and-tests/building-and-testing-swift

name: Swift
name: Ubuntu (Experimental)

on:
push:
branches: [ "master" ]
pull_request:
branches: [ "master" ]

concurrency:
group: ${{ github.workflow }}-${{ github.ref }}
cancel-in-progress: ${{ github.ref != 'refs/heads/master' }}

jobs:
linux_build:
if: ${{ false }}
runs-on: ubuntu-latest
steps:
- name: Setup Swift
Expand All @@ -36,23 +39,6 @@ jobs:
- name: Bundle Install
run: bundle install
- name: Swift Build
run: swift build -v
run: swift build
- name: Run tests
run: swift test -v
macos_build:
if: ${{ false }}
runs-on: macos-latest
steps:
- uses: actions/checkout@v3
- name: Setup Ruby
uses: ruby/setup-ruby@ec02537da5712d66d4d50a0f33b7eb52773b5ed1
with:
ruby-version: '3.1'
- name: Bundle Install
run: bundle install
- name: Swift Build
run: swift build -v
- name: Run tests
run: swift test -v


run: swift test
34 changes: 34 additions & 0 deletions .github/workflows/macOS.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
# This workflow will build a Swift project
# For more information see: https://docs.github.com/en/actions/automating-builds-and-tests/building-and-testing-swift

name: macOS

on:
push:
branches: [ "master" ]
pull_request:
branches: [ "master" ]

concurrency:
group: ${{ github.workflow }}-${{ github.ref }}
cancel-in-progress: ${{ github.ref != 'refs/heads/master' }}

jobs:
macos_build:
runs-on: macos-13
steps:
- name: Set Xcode 14.3.1
run: sudo xcode-select -s /Applications/Xcode_14.3.1.app/Contents/Developer
#- name: Set Xcode 15.0 Beta
# run: sudo xcode-select -s /Applications/Xcode_15.0.app/Contents/Developer
- name: Print Current Xcode
run: xcode-select -p
- uses: actions/checkout@v3
- name: Bundle Install
run: bundle install
- name: Swift Build
run: swift build
- name: Run tests
run: swift test


12 changes: 6 additions & 6 deletions .sourcery.yml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
sources:
- SourceryRuntime/Sources
templates:
- Sourcery/Templates
output:
SourceryRuntime/Sources/Generated
#sources:
# - SourceryRuntime/Sources
#templates:
# - Sourcery/Templates
#output:
# SourceryRuntime/Sources/Generated
28 changes: 28 additions & 0 deletions .vscode/launch.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
{
"configurations": [
{
"type": "lldb",
"request": "launch",
"sourceLanguages": [
"swift"
],
"name": "Debug sourcery",
"program": "${workspaceFolder:Sourcery}/.build/debug/sourcery",
"args": [],
"cwd": "${workspaceFolder:Sourcery}",
"preLaunchTask": "swift: Build Debug sourcery"
},
{
"type": "lldb",
"request": "launch",
"sourceLanguages": [
"swift"
],
"name": "Release sourcery",
"program": "${workspaceFolder:Sourcery}/.build/release/sourcery",
"args": [],
"cwd": "${workspaceFolder:Sourcery}",
"preLaunchTask": "swift: Build Release sourcery"
}
]
}
1 change: 1 addition & 0 deletions .vscode/settings.json
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
{}
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
- Add support to any keyword for function parameter type to AutoMockable.stencil ([#1169](https://github.com/krzysztofzablocki/Sourcery/pull/1169))
- Add support to any keyword for function return type to AutoMockable.stencil([#1186](https://github.com/krzysztofzablocki/Sourcery/pull/1186))
- Add support for protocol compositions in EJS templates. ([#1192](https://github.com/krzysztofzablocki/Sourcery/pull/1192))
- Linux Support (experimental) ([#1188](https://github.com/krzysztofzablocki/Sourcery/pull/1188))

## 2.0.3
## Internal Changes
Expand Down
3 changes: 3 additions & 0 deletions Gemfile.lock
Original file line number Diff line number Diff line change
Expand Up @@ -135,6 +135,8 @@ GEM
nap (1.1.0)
netrc (0.11.0)
no_proxy_fix (0.1.2)
nokogiri (1.13.3-aarch64-linux)
racc (~> 1.4)
nokogiri (1.13.3-arm64-darwin)
racc (~> 1.4)
octokit (4.22.0)
Expand Down Expand Up @@ -183,6 +185,7 @@ GEM
rouge (~> 2.0.7)

PLATFORMS
aarch64-linux
arm64-darwin-21
arm64-darwin-23

Expand Down
56 changes: 56 additions & 0 deletions LINUX.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
## Linux Support

Currently (as per 2.1.0 release), Linux Support is **experimental**. This means the following:

1. Running `sourcery` in the root folder of Sourcery project was generating `Equatable.generated.swift` and other autogenerated files with extensions of classes used by `SourceryRuntime`, but they were moved to class definitions due to the abscense of `@objc` attribute on non-Darwin platforms. Thus, `.sourcery.yaml` file was disabled for the moment, until #1198 is resolved.
2. Some unit tests were disabled with `#if canImport(ObjectiveC)`, that is some due to Swift compiler crashes, some due to abscence of `JavaScriptCore`.
3. `FileWatcher` needs to be re-implemented (see [this comment](https://github.com/krzysztofzablocki/Sourcery/pull/1188#issue-1828038476) for a possible fix)


All issues related to Linux will be mentioned in #1198

## Using Sourcery under Linux

Simply add package dependency of Sourcery as described in the [README](README.md).

## Contributing
### Installation of Linux Environment

I have installed ubuntu VM through [tart](https://github.com/cirruslabs/tart/issues/62#issuecomment-1225956540) and updated to 22.04 according to [this guide](https://www.linuxtechi.com/upgrade-ubuntu-20-04-to-ubuntu-22-04/).

I had to run the following commands prior to being able to run `bundle install` in Sourcery:

1. `sudo apt install libffi-dev`
2. `sudo apt install build-essential`
3. `sudo apt install libsqlite3-dev`
4. `sudo apt-get install libncurses5-dev`

Then, `swiftly` needs to be installed to easily manage Swift installation under Linux. How to install Swiftly is described [in this README](https://github.com/swift-server/swiftly).

### Running Tests Under Linux

To run tests, you can use either Visual Studio Code distribution, or simply `swift test` in Sourcery root directory.

#### Visual Studio Code

To install VS Code, you can follow [the official guide](https://code.visualstudio.com/docs/setup/linux), which mentions the following commands:

```bash
sudo apt-get install wget gpg
wget -qO- https://packages.microsoft.com/keys/microsoft.asc | gpg --dearmor > packages.microsoft.gpg
sudo install -D -o root -g root -m 644 packages.microsoft.gpg /etc/apt/keyrings/packages.microsoft.gpg
sudo sh -c 'echo "deb [arch=amd64,arm64,armhf signed-by=/etc/apt/keyrings/packages.microsoft.gpg] https://packages.microsoft.com/repos/code stable main" > /etc/apt/sources.list.d/vscode.list'
rm -f packages.microsoft.gpg

# Then update the package cache and install the package using:

sudo apt install apt-transport-https
sudo apt update
sudo apt install code # or code-insiders
```

### Test Discovery Under Linux

Due to a missing feature in Swift Package Manager, tests under Linux are not discovered if the root class, from which tests are inherited, is located "in another Package/Module". Details regarding this [can be found here](https://github.com/apple/swift-package-manager/issues/5573).

And so, if a new `Spec` needs to be added, that Spec file needs to be put into `LinuxMain.swift` similarly to what is there already, mentioning the new class name accordingly.
82 changes: 82 additions & 0 deletions LinuxMain.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,82 @@
import XCTest
import Quick

@testable import SourceryLibTests
@testable import TemplatesTests
@testable import CodableContextTests

@main struct Main {
static func main() {
Quick.QCKMain([
ActorSpec.self,
AnnotationsParserSpec.self,
ClassSpec.self,
ConfigurationSpec.self,
DiffableSpec.self,
DryOutputSpec.self,
EnumSpec.self,
FileParserAssociatedTypeSpec.self,
FileParserAttributesSpec.self,
FileParserMethodsSpec.self,
FileParserProtocolCompositionSpec.self,
FileParserSpec.self,
FileParserSubscriptsSpec.self,
FileParserVariableSpec.self,
GeneratorSpec.self,
MethodSpec.self,
ParserComposerSpec.self,
ProtocolSpec.self,
SourcerySpecTests.self,
StencilTemplateSpec.self,
StringViewSpec.self,
StructSpec.self,
SwiftTemplateTests.self,
TemplateAnnotationsParserSpec.self,
TemplatesAnnotationParserPassInlineCodeSpec.self,
TypeNameSpec.self,
TypeSpec.self,
TypealiasSpec.self,
TypedSpec.self,
VariableSpec.self,
VerifierSpec.self,
CodableContextTests.self,
TemplatesTests.self
],
configurations: [],
testCases: [
testCase(ActorSpec.allTests),
testCase(AnnotationsParserSpec.allTests),
testCase(ClassSpec.allTests),
testCase(ConfigurationSpec.allTests),
testCase(DiffableSpec.allTests),
testCase(DryOutputSpec.allTests),
testCase(EnumSpec.allTests),
testCase(FileParserAssociatedTypeSpec.allTests),
testCase(FileParserAttributesSpec.allTests),
testCase(FileParserMethodsSpec.allTests),
testCase(FileParserProtocolCompositionSpec.allTests),
testCase(FileParserSpec.allTests),
testCase(FileParserSubscriptsSpec.allTests),
testCase(FileParserVariableSpec.allTests),
testCase(GeneratorSpec.allTests),
testCase(MethodSpec.allTests),
testCase(ParserComposerSpec.allTests),
testCase(ProtocolSpec.allTests),
testCase(SourcerySpecTests.allTests),
testCase(StencilTemplateSpec.allTests),
testCase(StringViewSpec.allTests),
testCase(StructSpec.allTests),
testCase(SwiftTemplateTests.allTests),
testCase(TemplateAnnotationsParserSpec.allTests),
testCase(TemplatesAnnotationParserPassInlineCodeSpec.allTests),
testCase(TypeNameSpec.allTests),
testCase(TypeSpec.allTests),
testCase(TypealiasSpec.allTests),
testCase(TypedSpec.allTests),
testCase(VariableSpec.allTests),
testCase(VerifierSpec.allTests),
testCase(CodableContextTests.allTests),
testCase(TemplatesTests.allTests)
])
}
}
18 changes: 0 additions & 18 deletions Package.resolved
Original file line number Diff line number Diff line change
Expand Up @@ -18,24 +18,6 @@
"version" : "0.9.1"
}
},
{
"identity" : "cwlcatchexception",
"kind" : "remoteSourceControl",
"location" : "https://github.com/mattgallagher/CwlCatchException.git",
"state" : {
"revision" : "f809deb30dc5c9d9b78c872e553261a61177721a",
"version" : "2.0.0"
}
},
{
"identity" : "cwlpreconditiontesting",
"kind" : "remoteSourceControl",
"location" : "https://github.com/mattgallagher/CwlPreconditionTesting.git",
"state" : {
"revision" : "02b7a39a99c4da27abe03cab2053a9034379639f",
"version" : "2.0.0"
}
},
{
"identity" : "komondor",
"kind" : "remoteSourceControl",
Expand Down
Loading

0 comments on commit ba63cd6

Please sign in to comment.