codeql/swift
Tom Hvitved 9f798902bd Data flow: Add consistency check for `DataFlowCall::getEnclosingCallable` 2023-03-16 08:40:53 +01:00
..
actions Merge pull request #12319 from github/redsun82/swift-codegen 2023-02-27 14:06:20 +01:00
codegen Codegen: update `README.md` files 2023-02-27 10:01:50 +01:00
downgrades Swift: make `AnyGenericType::getDecl`'s type more specific 2023-03-14 11:49:07 +01:00
extractor Swift: add missing include 2023-03-14 11:23:33 +01:00
integration-tests Swift: make deduplication test cross-platform 2023-03-14 11:24:03 +01:00
ql Data flow: Add consistency check for `DataFlowCall::getEnclosingCallable` 2023-03-16 08:40:53 +01:00
third_party Swift: update to 5.7.3 2023-02-17 10:03:52 +01:00
tools Swift: ignore sandbox-exec 2023-01-30 15:10:30 +01:00
xcode-autobuilder Swift: make xcode-autobuilder tester work with several tests 2022-10-19 16:20:32 +02:00
.clang-format Swift: first skeleton extractor 2022-04-12 12:40:59 +02:00
.gitignore Swift: generate raw helpers in synthesized stubs 2023-02-16 10:49:21 +01:00
.pep8 Swift: implement python schema 2022-09-21 15:53:09 +02:00
.python-version Swift: bump actions/setup-python from 3 to 4 2022-10-19 18:10:42 +02:00
BUILD.bazel Swift: make C++ code generation language agnostic 2023-02-27 09:46:48 +01:00
CMakeLists.txt Swift: enable VSCode to build extractor via CMake 2022-11-03 11:16:48 +01:00
README.md Move `swift/codegen` to `misc/codegen` 2023-02-27 09:46:48 +01:00
codegen.conf Move `swift/codegen` to `misc/codegen` 2023-02-27 09:46:48 +01:00
codeql-extractor.yml Specify language names in extractor packs 2022-12-23 13:15:04 +00:00
create_extractor_pack.py Swift: add `qltest.sh` tests 2022-10-21 12:54:09 +02:00
prefix.dbscheme Swift: implement python schema 2022-09-21 15:53:09 +02:00
rules.bzl Swift: enable VSCode to build extractor via CMake 2022-11-03 11:16:48 +01:00
schema.py Swift: make `AnyGenericType::getDecl`'s type more specific 2023-03-14 11:49:07 +01:00
schema_documentation.md Swift: tweaks to the schema doc documentation 2023-02-10 08:58:07 +01:00

README.md

Swift on CodeQL

Warning

The Swift CodeQL package is an experimental and unsupported work in progress.

Building the Swift extractor

First ensure you have Bazel installed, for example with

brew install bazelisk

then from the ql directory run

bazel run //swift:create-extractor-pack    # --cpu=darwin_x86_64 # Uncomment on Arm-based Macs

which will install swift/extractor-pack.

Notice you can run bazel run :create-extractor-pack if you already are in the swift directory.

Using codeql ... --search-path=swift/extractor-pack will then pick up the Swift extractor. You can also use --search-path=., as the extractor pack is mentioned in the root codeql-workspace.yml. Alternatively, you can set up the search path in the per-user CodeQL configuration file .

Code generation

Run

bazel run //swift/codegen

to update generated files. This can be shortened to bazel run codegen if you are in the swift directory.

You can also run ../misc/codegen/codegen.py, as long as you are beneath the swift directory.

IDE setup

CLion and the native bazel plugin

You can use CLion with the official IntelliJ Bazel plugin, creating the project from scratch with default options. This is known to have issues on non-Linux platforms.

CMake project

The CMakeLists.txt file allows to load the Swift extractor as a CMake project, which allows integration into a wider variety of IDEs. Building with CMake also creates a compile_commands.json compilation database that can be picked up by even more IDEs. In particular, opening the swift directory in VSCode should work.

Debugging codeql database creation

If you want to debug a specific run of the extractor within an integration test or a complex codeql database create invocation, you can do so using gdbserver or lldb-server.

For example with gdbserver, you can

export CODEQL_EXTRACTOR_SWIFT_RUN_UNDER="gdbserver :1234"
export CODEQL_EXTRACTOR_SWIFT_RUN_UNDER_FILTER="SomeSwiftSource\.swift"  # can be any regex matching extractor args

before starting the database extraction, and when that source is encountered the extractor will be run under a gdbserver instance listening on port 1234. You can then attach to the running debugging server from gdb or your IDE. Please refer to your IDE's instructions for how to set up remote debugging.

In particular for breakpoints to work you might need to setup the following remote path mapping:

Remote Local
swift /absolute/path/to/codeql/swift
bazel-out /absolute/path/to/codeql/bazel-out