• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1---
2layout: default
3title: Integrating a Swift project
4parent: Setting up a new project
5grand_parent: Getting started
6nav_order: 1
7permalink: /getting-started/new-project-guide/swift/
8---
9
10# Integrating a Swift project
11{: .no_toc}
12
13- TOC
14{:toc}
15---
16
17The process of integrating a project written in Swift with OSS-Fuzz is very similar
18to the general
19[Setting up a new project]({{ site.baseurl }}/getting-started/new-project-guide/)
20process. The key specifics of integrating a Swift project are outlined below.
21
22## Project files
23
24First, you need to write a Swift fuzz target that accepts a stream of bytes and
25calls the program API with that. This fuzz target should reside in your project
26repository.
27
28The structure of the project directory in OSS-Fuzz repository doesn't differ for
29projects written in Swift. The project files have the following Swift specific
30aspects.
31
32### project.yaml
33
34The `language` attribute must be specified.
35
36```yaml
37language: swift
38```
39
40The only supported fuzzing engine is `libfuzzer`
41
42The supported sanitizers are and `address`, `thread`
43
44[Example](https://github.com/google/oss-fuzz/blob/2a15c3c88b21f4f1be2a7ff115f72bd7a08e34ac/projects/swift-nio/project.yaml#L9):
45
46```yaml
47fuzzing_engines:
48  - libfuzzer
49sanitizers:
50  - address
51  - thread
52```
53
54### Dockerfile
55
56The Dockerfile should start by `FROM gcr.io/oss-fuzz-base/base-builder-swift`
57instead of using the simple base-builder
58
59### build.sh
60
61A `precompile_swift` generates an environment variable `SWIFTFLAGS`
62This can then be used in the building command such as `swift build -c release $SWIFTFLAGS`
63
64
65A usage example from swift-protobuf project is
66
67```sh
68. precompile_swift
69# build project
70cd FuzzTesting
71swift build -c debug $SWIFTFLAGS
72
73(
74cd .build/debug/
75find . -maxdepth 1 -type f -name "*Fuzzer" -executable | while read i; do cp $i $OUT/"$i"-debug; done
76)
77
78```
79