codeql/swift
Nora Dimitrijević 8b332778e3 Swift: update `@security-severity` 2022-11-17 18:08:06 +01:00
..
actions Swift: print unextracted entities 2022-11-08 15:38:53 +01:00
codegen Swift: avoid wrongly using `doc` instead of `desc` for properties 2022-11-10 09:29:02 +01:00
extractor Swift: fix printing of unextracted entities 2022-11-10 16:49:32 +01:00
integration-tests Swift integration-test runner: use --additional-packs 2022-10-28 16:07:38 +01:00
ql Swift: update `@security-severity` 2022-11-17 18:08:06 +01:00
third_party Swift: remove an `assert` from swift headers 2022-11-08 11:47:12 +01:00
tools Update qltest.sh 2022-11-04 13:04:24 +01:00
xcode-autobuilder Swift: make xcode-autobuilder tester work with several tests 2022-10-19 16:20:32 +02:00
.clang-format
.gitignore Swift: cmake generator for better IDE support 2022-10-13 15:25:24 +02: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: move libraries from `tools` to `third_party` 2022-10-26 07:05:56 +02:00
CMakeLists.txt Swift: enable VSCode to build extractor via CMake 2022-11-03 11:16:48 +01:00
README.md Swift: remove unneeded trailing `/` in `README.md` 2022-10-31 09:55:03 +01:00
codeql-extractor.yml
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: remove imposible nodes from schema 2022-11-10 15:26:55 +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.

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