Skip to content

Commit 7b74f5c

Browse files
build: add an initial CMake based build system for DocC (#818)
* build: add an initial CMake based build system for DocC This allows us to cross-compile DocC and reduce the size of the binary by sharing the toolchain artifacts. * Update CONTRIBUTING.md Co-authored-by: David Rönnqvist <ronnqvist@apple.com> --------- Co-authored-by: David Rönnqvist <ronnqvist@apple.com>
1 parent 15dde00 commit 7b74f5c

File tree

6 files changed

+651
-1
lines changed

6 files changed

+651
-1
lines changed

CMakeLists.txt

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
#[[
2+
This source file is part of the Swift open source project
3+
4+
Copyright © 2014 - 2025 Apple Inc. and the Swift project authors
5+
Licensed under Apache License v2.0 with Runtime Library Exception
6+
7+
See https://swift.org/LICENSE.txt for license information
8+
#]]
9+
10+
cmake_minimum_required(VERSION 3.24)
11+
12+
project(SwiftDocC
13+
LANGUAGES Swift)
14+
15+
set(CMAKE_ARCHIVE_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/lib)
16+
set(CMAKE_LIBRARY_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/lib)
17+
set(CMAKE_RUNTIME_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/bin)
18+
19+
set(CMAKE_Swift_MODULE_DIRECTORY ${CMAKE_BINARY_DIR}/swift)
20+
set(CMAKE_Swift_COMPILE_OPTIONS_MSVC_RUNTIME_LIBRARY MultiThreadedDLL)
21+
set(CMAKE_Swift_LANGUAGE_VERSION 5)
22+
23+
enable_language(C)
24+
include(GNUInstallDirs)
25+
26+
# NOTE(compnerd) workaround CMake issues
27+
add_compile_options("$<$<COMPILE_LANGUAGE:Swift>:SHELL:-swift-version 5>")
28+
add_compile_options("$<$<COMPILE_LANGUAGE:Swift>:SHELL:-enable-upcoming-feature ConciseMagicFile>")
29+
add_compile_options("$<$<COMPILE_LANGUAGE:Swift>:SHELL:-enable-upcoming-feature ExistentialAny>")
30+
add_compile_options("$<$<COMPILE_LANGUAGE:Swift>:SHELL:-enable-upcoming-feature InternalImportsByDefault>")
31+
32+
find_package(ArgumentParser)
33+
find_package(SwiftASN1)
34+
find_package(SwiftCrypto)
35+
find_package(SwiftMarkdown)
36+
find_package(LMDB)
37+
find_package(SymbolKit)
38+
find_package(cmark-gfm)
39+
40+
add_compile_options("$<$<COMPILE_LANGUAGE:Swift>:-package-name;SwiftDocC>")
41+
42+
add_subdirectory(Sources)

CONTRIBUTING.md

Lines changed: 26 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -350,7 +350,32 @@ by running the test suite in a Docker environment that simulates Swift on Linux.
350350
cd swift-docc
351351
swift run docc
352352
```
353-
353+
354+
## Updating Build Rules
355+
356+
In order to build DocC as part of the Windows toolchain distribution uniformly,
357+
a parallel CMake based build exists. Note that this is **not** supported for
358+
development purposes (you cannot execute the test suite with this build).
359+
360+
CMake requires that the full file list is kept up-to-date. When adding or
361+
removing files in a given module, the `CMakeLists.txt` list must be updated to
362+
the file list.
363+
364+
The 1-line script below lists all the Swift files in the current directory tree.
365+
You can use the script's output to replace the list of files in the CMakeLists.txt file for each target that you added files to or removed files from.
366+
367+
```bash
368+
python -c "print('\n'.join((f'{chr(34)}{path}{chr(34)}' if ' ' in path else path) for path in sorted(str(path) for path in __import__('pathlib').Path('.').rglob('*.swift'))))"
369+
```
370+
371+
This should provide the listing of files in the module that can be used to
372+
update the `CMakeLists.txt` associated with the target.
373+
374+
In the case that a new target is added to the project, the new directory would
375+
need to add the new library or executable target (`add_library` and
376+
`add_executable` respectively) and the new target subdirectory must be listed in
377+
the `Sources/CMakeLists.txt` (via `add_subdirectory`).
378+
354379
## Continuous Integration
355380

356381
Swift-DocC uses [swift-ci](https://ci.swift.org) infrastructure for its continuous integration

Sources/CMakeLists.txt

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
#[[
2+
This source file is part of the Swift open source project
3+
4+
Copyright © 2014 - 2025 Apple Inc. and the Swift project authors
5+
Licensed under Apache License v2.0 with Runtime Library Exception
6+
7+
See https://swift.org/LICENSE.txt for license information
8+
#]]
9+
10+
add_subdirectory(SwiftDocC)
11+
add_subdirectory(SwiftDocCUtilities)
12+
add_subdirectory(docc)

0 commit comments

Comments
 (0)