Skip to content

Commit

Permalink
build: Add CMakePresets.json
Browse files Browse the repository at this point in the history
  • Loading branch information
ltoenning committed Jul 7, 2024
1 parent 39c2c4a commit 89c4907
Show file tree
Hide file tree
Showing 4 changed files with 84 additions and 36 deletions.
20 changes: 8 additions & 12 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -144,19 +144,18 @@ jobs:
cat >vatsim.json <<EOF
{ "vatsim": { "id": "$VATSIM_ID", "key": "$VATSIM_KEY" } }
EOF
echo "vatsim_key_file=vatsim.json" >>$GITHUB_ENV
env:
VATSIM_ID: ${{ secrets.VATSIM_ID }}
VATSIM_KEY: ${{ secrets.VATSIM_KEY }}
- uses: Trass3r/setup-cpp@1b63900ecf3f0b7c60ee53aa7be122f2c4fe7a2c
- name: Build swift (without symbols)
if: ${{ env.do_symbols != 'true' }}
run: |
python3 -u scripts/build.py -w 64 -t gcc -c "-DVATSIM_KEY_JSON=$vatsim_key_file"
python3 -u scripts/build.py -w 64 -t gcc
- name: Build swift (with symbols)
if: ${{ env.do_symbols == 'true' }}
run: |
python3 -u scripts/build.py -w 64 -t gcc -c "-DVATSIM_KEY_JSON=$vatsim_key_file" --upload-symbols
python3 -u scripts/build.py -w 64 -t gcc --upload-symbols
- name: Upload installer
uses: actions/upload-artifact@v4
with:
Expand Down Expand Up @@ -242,19 +241,18 @@ jobs:
echo >vatsim.json @"
{ "vatsim": { "id": "$env:VATSIM_ID", "key": "$env:VATSIM_KEY" } }
"@
echo "vatsim_key_file=vatsim.json" >>$env:GITHUB_ENV
env:
VATSIM_ID: ${{ secrets.VATSIM_ID }}
VATSIM_KEY: ${{ secrets.VATSIM_KEY }}
- uses: Trass3r/setup-cpp@1b63900ecf3f0b7c60ee53aa7be122f2c4fe7a2c
- name: Build swift (without symbols)
if: ${{ env.do_symbols != 'true' }}
run: |
python -u scripts/build.py -w 64 -t msvc -c "-DVATSIM_KEY_JSON=$env:vatsim_key_file"
python -u scripts/build.py -w 64 -t msvc
- name: Build swift (with symbols)
if: ${{ env.do_symbols == 'true' }}
run: |
python -u scripts/build.py -w 64 -t msvc -c "-DVATSIM_KEY_JSON=$env:vatsim_key_file" --upload-symbols
python -u scripts/build.py -w 64 -t msvc --upload-symbols
- name: Upload installer
uses: actions/upload-artifact@v4
with:
Expand Down Expand Up @@ -340,19 +338,18 @@ jobs:
echo >vatsim.json @"
{ "vatsim": { "id": "$env:VATSIM_ID", "key": "$env:VATSIM_KEY" } }
"@
echo "vatsim_key_file=vatsim.json" >>$env:GITHUB_ENV
env:
VATSIM_ID: ${{ secrets.VATSIM_ID }}
VATSIM_KEY: ${{ secrets.VATSIM_KEY }}
- uses: Trass3r/setup-cpp@1b63900ecf3f0b7c60ee53aa7be122f2c4fe7a2c
- name: Build swift (without symbols)
if: ${{ env.do_symbols != 'true' }}
run: |
python -u scripts/build.py -w 32 -t msvc -c "-DVATSIM_KEY_JSON=$env:vatsim_key_file"
python -u scripts/build.py -w 32 -t msvc
- name: Build swift (with symbols)
if: ${{ env.do_symbols == 'true' }}
run: |
python -u scripts/build.py -w 32 -t msvc -c "-DVATSIM_KEY_JSON=$env:vatsim_key_file" --upload-symbols
python -u scripts/build.py -w 32 -t msvc --upload-symbols
- name: Upload installer
uses: actions/upload-artifact@v4
with:
Expand Down Expand Up @@ -428,19 +425,18 @@ jobs:
cat >vatsim.json <<EOF
{ "vatsim": { "id": "$VATSIM_ID", "key": "$VATSIM_KEY" } }
EOF
echo "vatsim_key_file=vatsim.json" >>$GITHUB_ENV
env:
VATSIM_ID: ${{ secrets.VATSIM_ID }}
VATSIM_KEY: ${{ secrets.VATSIM_KEY }}
- uses: Trass3r/setup-cpp@1b63900ecf3f0b7c60ee53aa7be122f2c4fe7a2c
- name: Build swift (without symbols)
if: ${{ env.do_symbols != 'true' }}
run: |
python3 -u scripts/build.py -w 64 -t clang -c "-DVATSIM_KEY_JSON=$vatsim_key_file"
python3 -u scripts/build.py -w 64 -t clang
- name: Build swift (with symbols)
if: ${{ env.do_symbols == 'true' }}
run: |
python3 -u scripts/build.py -w 64 -t clang -c "-DVATSIM_KEY_JSON=$vatsim_key_file" --upload-symbols
python3 -u scripts/build.py -w 64 -t clang --upload-symbols
- name: Upload installer
uses: actions/upload-artifact@v4
with:
Expand Down
2 changes: 1 addition & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -50,4 +50,4 @@ cmake-build-*/
# Install folders
/out/
/dist/
CMakePresets.json
CMakeUserPresets.json
69 changes: 69 additions & 0 deletions CMakePresets.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,69 @@
{
"version": 6,
"configurePresets": [
{
"name": "ci-base",
"hidden": true,
"cacheVariables": {
"CMAKE_BUILD_TYPE": "RelWithDebInfo",
"SWIFT_MINIFY_DEBUG_SYMBOLS": "ON",
"SWIFT_USE_CRASHPAD": "ON",
"VATSIM_KEY_JSON": "vatsim.json",
"CMAKE_INSTALL_PREFIX": "${sourceDir}/dist"
}
},
{
"name": "ci-build-windows",
"displayName": "CI Build Windows",
"inherits": "ci-base",
"generator": "Ninja",
"condition": {
"type": "equals",
"lhs": "${hostSystemName}",
"rhs": "Windows"
},
"cacheVariables": {
"SWIFT_USE_CRASHPAD": "ON"
}
},
{
"name": "ci-build-macos",
"displayName": "CI Build macOS",
"inherits": "ci-base",
"generator": "Unix Makefiles",
"condition": {
"type": "equals",
"lhs": "${hostSystemName}",
"rhs": "Darwin"
},
"cacheVariables": {
"SWIFT_USE_CRASHPAD": "ON"
}
},
{
"name": "ci-build-linux",
"displayName": "CI Build Linux",
"inherits": "ci-base",
"generator": "Ninja",
"condition": {
"type": "equals",
"lhs": "${hostSystemName}",
"rhs": "Linux"
},
"cacheVariables": {
"SWIFT_USE_CRASHPAD": "OFF"
}
},
{
"name": "dev-debug",
"displayName": "Development Debug",
"description": "Base preset that can either be used directly or can be customized through a CMakeUserPresets.json",
"cacheVariables": {
"CMAKE_BUILD_TYPE": "Debug",
"SWIFT_USE_CRASHPAD": "OFF",
"SWIFT_VATSIM_SUPPORT": "OFF",
"SWIFT_MINIFY_DEBUG_SYMBOLS": "OFF"
}
}
]
}
29 changes: 6 additions & 23 deletions scripts/build.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ def prepare(self):
shared_path = os.path.abspath(os.path.join(source_path, 'resources', 'share'))
datastore.update_shared(host, datastore_version, shared_path)

def build(self, cmake_args):
def build(self):
"""
Run the build itself
"""
Expand All @@ -43,15 +43,9 @@ def build(self, cmake_args):
os.makedirs(build_path)
os.chdir(build_path)

use_crashpad = "ON" if platform.system() == 'Darwin' or platform.system() == 'Windows' else "OFF"

cmake_call = ['cmake',
'..',
'-G {}'.format(self._get_generator()),
'-DCMAKE_BUILD_TYPE=RelWithDebInfo',
'-DSWIFT_MINIFY_DEBUG_SYMBOLS=ON',
'-DCMAKE_INSTALL_PREFIX=../dist',
'-DSWIFT_USE_CRASHPAD={}'.format(use_crashpad)] + cmake_args
f'--preset=ci-build-{self.os_map[platform.system()]}']
subprocess.check_call(cmake_call, env=dict(os.environ))

# Workaround while using Make for macOS to pass number of jobs
Expand All @@ -77,11 +71,10 @@ def checks(self):
def create_installer(self):
bitrock_builder_bin = os.environ["BITROCK_BUILDER"]
os.chdir(utils.get_swift_source_path())
os_map = {'Linux': 'linux', 'Darwin': 'macos', 'Windows': 'windows'}
installer_platform_map = {'Linux': 'linux-x{}'.format(self.word_size), 'Darwin': 'osx', 'Windows': 'windows'}
extension_map = {'Linux': 'run', 'Darwin': 'app', 'Windows': 'exe'}
extension = extension_map[platform.system()]
os_name = os_map[platform.system()]
os_name = self.os_map[platform.system()]
version_full = utils.get_swift_version_base()
version_rev = utils.get_rev_count()
windows64 = 1 if os_name == 'windows' and int(self.word_size) == 64 else 0
Expand Down Expand Up @@ -119,12 +112,11 @@ def install(self):

def publish(self):
if self._should_publish():
os_map = {'Linux': 'linux', 'Darwin': 'macos', 'Windows': 'windows'}
extension_map = {'Linux': 'run', 'Darwin': 'dmg', 'Windows': 'exe'}
version_segments = self.version.split('.')
last_segment = version_segments.pop()
version_without_timestamp = '.'.join(version_segments)
installer_name_old = '-'.join(['swiftinstaller', os_map[platform.system()], self.word_size, version_without_timestamp])
installer_name_old = '-'.join(['swiftinstaller', self.os_map[platform.system()], self.word_size, version_without_timestamp])
installer_name_new = '.'.join([installer_name_old, last_segment])
installer_name_old = installer_name_old + '.' + extension_map[platform.system()]
installer_name_new = installer_name_new + '.' + extension_map[platform.system()]
Expand Down Expand Up @@ -216,9 +208,6 @@ def _specific_prepare(self):
def _get_platform_name(self) -> str:
raise NotImplementedError()

def _get_generator(self) -> str:
raise NotImplementedError()

def _should_run_checks(self) -> bool:
return True

Expand All @@ -235,6 +224,7 @@ def _strip_debug(self):
raise NotImplementedError()

def __init__(self, word_size):
self.os_map = {'Linux': 'linux', 'Darwin': 'macos', 'Windows': 'windows'}
self.__build_path = path.abspath(path.join(utils.get_swift_source_path(), 'build'))

files = os.listdir(utils.get_swift_source_path())
Expand Down Expand Up @@ -304,9 +294,6 @@ def _specific_prepare(self):
def _get_platform_name(self) -> str:
return 'linux-g++'

def _get_generator(self) -> str:
return 'Ninja'

def _strip_debug(self):
files = [
"bin/swiftcore",
Expand Down Expand Up @@ -347,9 +334,6 @@ def _specific_prepare(self):
def _get_platform_name(self) -> str:
return 'macx-clang'

def _get_generator(self) -> str:
return 'Unix Makefiles'

def _should_create_symbols(self) -> bool:
return True

Expand Down Expand Up @@ -410,14 +394,13 @@ def main():
parser.add_argument("-w", "--wordsize", choices=supported_wordsizes, required=True, help='Wordsize for the build')
parser.add_argument("-t", "--toolchain", choices=supported_toolchains, required=True, help='Toolchain for the build')
parser.add_argument("-u", "--upload-symbols", action='store_true', help='Upload the symbols')
parser.add_argument("-c", "--cmake-args", action='extend', nargs="+", type=str, help='Arguments to pass to CMake')

args = parser.parse_args()

builder = builders[platform.system()][args.toolchain](args.wordsize)

builder.prepare()
builder.build(args.cmake_args)
builder.build()
builder.bundle_csl2xsb()
builder.checks()
builder.install()
Expand Down

0 comments on commit 89c4907

Please sign in to comment.