Currently (as per 2.1.0 release), Linux Support is experimental. This means the following:
- Running
sourcery
in the root folder of Sourcery project was generatingEquatable.generated.swift
and other autogenerated files with extensions of classes used bySourceryRuntime
, 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. - Some unit tests were disabled with
#if canImport(ObjectiveC)
, that is some due to Swift compiler crashes, some due to abscence ofJavaScriptCore
. FileWatcher
needs to be re-implemented (see this comment for a possible fix)
All issues related to Linux will be mentioned in #1198
Simply add package dependency of Sourcery as described in the README.
You can build Docker container with Sourcery installed using this command:
docker build -t sourcery-image .
Then you can run this Docker image passing the arguments you'd like:
docker run sourcery-image sourcery --help
I have installed ubuntu VM through tart and updated to 22.04 according to this guide.
I had to run the following commands prior to being able to run bundle install
in Sourcery:
sudo apt install libffi-dev
sudo apt install build-essential
sudo apt install libsqlite3-dev
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.
To run tests, you can use either Visual Studio Code distribution, or simply swift test
in Sourcery root directory.
To install VS Code, you can follow the official guide, which mentions the following commands:
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
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.
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.