Combining all these features gives Xcode and Xcode Server the ability to handle the continuous integration and delivery for both macOS and Linux (via Docker) so that we don’t have to use an intermediary build server like Jenkins.
Build a Swift package in Linux and have the build errors appear in Xcode.
Building and testing your Swift code in Xcode on the macOS is one thing. But, then you have to fire up Docker and make sure that there aren’t any library differences or unimplemented language features on the Linux side of things. It’s kind of a pain. XcodeHelper eases these pains with the Linux side of cross-platform Swift development.
xchelper build SOURCE_CODE_PATH [OPTIONS]
Option
Description
build or env var BUILD_CONFIGURATION
Build a Swift package in Linux and have the build errors appear in Xcode. SOURCE_CODE_PATH is the root of your package to call ‘swift build’ in.
-c, --build-configuration or env var BUILD_CONFIGURATION
debug or release mode
-i, --image-name or env var BUILD_DOCKER_IMAGE_NAME
The Docker image name to run the commands in. Defaults to saltzmanjoelh/swiftubuntu
You can add a new Run Script Build Phase to your target
Or add a separate External Build target and manually switch between macOS build and Linux build
Create a new External Build target in Xcode.
Arguments are /path/to/xchelper build $(PROJECT_DIR)
Update the package dependencies via swift package update. SOURCE_CODE_PATH is the root of your package to call swift package update in.
-l, ----linux-packages or env var UPDATE_PACKAGES_LINUX_PACKAGES
Some packages have Linux specific dependencies. Use this option to update the Linux version of the packages. Linux packages may not be compatible with the macOS dependencies. swift build --clean is performed before they are updated. Defaults to: false
-i, --image-name or env var UPDATE_PACKAGES_DOCKER_IMAGE_NAME
The Docker image name to run the commands in. Defaults to saltzmanjoelh/swiftubuntu.
symlink-dependencies
xchelper symlink-dependencies SOURCE_CODE_PATH
Option
Description
symlink-dependencies, or env var SYMLINK_DEPENDENCIES
Create symbolic links to your dependencies and it will update your Xcode Project to use those symlinks instead of the directories with version number suffixes.
Archive files with tar. ARCHIVE_PATH the full path and filename for the archive to be created. FILES is a space separated list of full paths to the files you want to archive.
-f, --flat-list, or env var CREATE_ARCHIVE_FLAT_LIST
Put all the files in a flat list instead of maintaining directory structure. Defaults to: true.
The upload-archive command will download any updates to your dependencies via swift package updateSOURCE_CODE_PATH is the root of your package to call swift package update in.
Option
Description
-l, ----linux-packages or env var UPDATE_PACKAGES_LINUX_PACKAGES
Some packages have Linux specific dependencies. Use this option to update the Linux version of the packages. Linux packages may not be compatible with the macOS dependencies. swift build --clean is performed before they are updated. Defaults to: false
-i, --image-name or env var UPDATE_PACKAGES_DOCKER_IMAGE_NAME
The Docker image name to run the commands in. Defaults to saltzmanjoelh/swiftubuntu.
Examples
There is an example project available to see the full configuration.
Build and run tests on Linux through Docker
Here is an example of all of the xchelper build options
Keep your “Dependencies” group in Xcode referencing the correct paths
When you need to update your package dependencies, you have to call swift package update. This breaks your project and now you have to call swift package generate-xcodeproj again or update your references in your project. Use update-packages and symlink-dependencies to help with this process.
Here is an example of updating your packages, creating/updating your symlinks to those packages and having Xcode updated to use those symlinks.
Please note the use of xcrun. You can use this if you get any errors like cannot load underlying module for 'Darwin' or did you forget to set an SDK using -sdk or SDKROOT?
Tar and upload your binary to AWS S3 buckets.
Use create-archive and upload-archive to help get your files to an S3 bucket. You might use this if you are using CodeDeploy or something similar to monitor an S3 bucket for continuous integration.
XcodeHelperCli
XcodeHelperCli keeps you in Xcode and off the command line. It’s built from XcodeHelperKit.
Combining all these features gives Xcode and Xcode Server the ability to handle the continuous integration and delivery for both macOS and Linux (via Docker) so that we don’t have to use an intermediary build server like Jenkins.
Commands
build
Build a Swift package in Linux and have the build errors appear in Xcode.
Building and testing your Swift code in Xcode on the macOS is one thing. But, then you have to fire up Docker and make sure that there aren’t any library differences or unimplemented language features on the Linux side of things. It’s kind of a pain. XcodeHelper eases these pains with the Linux side of cross-platform Swift development.
build
or env varBUILD_CONFIGURATION
-c
,--build-configuration
or env varBUILD_CONFIGURATION
-i
,--image-name
or env varBUILD_DOCKER_IMAGE_NAME
You can add a new Run Script Build Phase to your target
Or add a separate External Build target and manually switch between macOS build and Linux build
/path/to/xchelper build $(PROJECT_DIR)
update-packages
update-packages
, or env varUPDATE_PACKAGES
swift package update
. SOURCE_CODE_PATH is the root of your package to callswift package update
in.-l
,----linux-packages
or env varUPDATE_PACKAGES_LINUX_PACKAGES
swift build --clean
is performed before they are updated. Defaults to: false-i
,--image-name
or env varUPDATE_PACKAGES_DOCKER_IMAGE_NAME
symlink-dependencies
symlink-dependencies
, or env varSYMLINK_DEPENDENCIES
create-archive
create-archive
, or env varCREATE_ARCHIVE
ARCHIVE_PATH
the full path and filename for the archive to be created. FILES is a space separated list of full paths to the files you want to archive.-f
,--flat-list
, or env varCREATE_ARCHIVE_FLAT_LIST
upload-archive
The
upload-archive
command will download any updates to your dependencies viaswift package update
SOURCE_CODE_PATH
is the root of your package to callswift package update
in.-l
,----linux-packages
or env varUPDATE_PACKAGES_LINUX_PACKAGES
swift build --clean
is performed before they are updated. Defaults to: false-i
,--image-name
or env varUPDATE_PACKAGES_DOCKER_IMAGE_NAME
Examples
There is an example project available to see the full configuration.
Build and run tests on Linux through Docker
Here is an example of all of the
xchelper build
optionsKeep your “Dependencies” group in Xcode referencing the correct paths
When you need to update your package dependencies, you have to call
swift package update
. This breaks your project and now you have to callswift package generate-xcodeproj
again or update your references in your project. Useupdate-packages
andsymlink-dependencies
to help with this process.Here is an example of updating your packages, creating/updating your symlinks to those packages and having Xcode updated to use those symlinks.
Please note the use of
xcrun
. You can use this if you get any errors likecannot load underlying module for 'Darwin'
ordid you forget to set an SDK using -sdk or SDKROOT?
Tar and upload your binary to AWS S3 buckets.
Use
create-archive
andupload-archive
to help get your files to an S3 bucket. You might use this if you are using CodeDeploy or something similar to monitor an S3 bucket for continuous integration.[2]: //dnrops/xcodehelperclikit/tree/master/ https:/swift.org”Swift”