Skip to content

2. Create a project

A project is a folder with three things:

  • stitch.toml: where the library source is, and build and fuzzing settings
  • Dockerfile: builds or installs the library
  • harness/: your stubs

Run this from examples/:

stitch setup --lang python
stitch init kv --lang python --path python-demo/lib
cd kv
stitch setup --lang cpp
stitch init kv --path cpp-demo/lib
cd kv
stitch setup --lang javascript
stitch init kv --lang javascript --path javascript-demo/lib
cd kv
stitch setup --lang java
stitch init kv --lang java --path java-demo/lib
cd kv
stitch setup --lang go
stitch init kv --lang go --path go-demo/lib
cd kv
stitch setup --lang rust
stitch init kv --lang rust --path rust-demo/lib
cd kv
stitch setup --lang ruby
stitch init kv --lang ruby --path ruby-demo/lib
cd kv
stitch setup --lang swift
stitch init kv --lang swift --path swift-demo/lib
cd kv
stitch setup --lang objc
stitch init kv --lang objc --path objc-demo/lib
cd kv

--path points at a local folder. For a library in a git repository, use --git URL --rev REV instead.

The Dockerfile starts from the STITCH++ image for your language. The library source is copied to /src. Edit the two files so that they build the store:

Dockerfile (unchanged from init):

ARG STITCH_BASE
FROM ${STITCH_BASE}
COPY --from=source . /src
RUN pip install --no-cache-dir /src

stitch.toml: set include to the library’s import name. Only these modules get coverage and comparison tracing.

[python]
include = ["kvlib"]

Dockerfile: build a static library with $CC, which adds coverage and sanitizer instrumentation.

ARG STITCH_BASE
FROM ${STITCH_BASE}
COPY --from=source . /src
WORKDIR /src
RUN make libkv.a CC="$CC"

stitch.toml: tell the harness where the headers and the library are.

[build]
cflags = ["-I/src"]
ldflags = ["/src/libkv.a"]
sanitizers = ["address"]

Dockerfile: install the package into /opt.

ARG STITCH_BASE
FROM ${STITCH_BASE}
COPY --from=source . /src
RUN cd /opt && npm install /src

stitch.toml: set include to the package name. Only this package gets coverage and comparison tracing.

[javascript]
include = ["kvjs"]

Dockerfile: compile the library and put the jar in /deps.

ARG STITCH_BASE
FROM ${STITCH_BASE}
COPY --from=source . /src
RUN cd /src && javac -g -d /tmp/kv $(find . -name '*.java') && jar cf /deps/kv.jar -C /tmp/kv .

stitch.toml: set include to the library’s package, and sources to its source folder (for coverage reports).

[java]
include = ["demo.kv"]
sources = ["/src"]

Dockerfile (unchanged from init):

ARG STITCH_BASE
FROM ${STITCH_BASE}
COPY --from=source . /src
RUN cd /src && go mod download

stitch.toml: init reads the module path from go.mod.

[go]
module = "example.com/kvgo"

Dockerfile (unchanged from init):

ARG STITCH_BASE
FROM ${STITCH_BASE}
COPY --from=source . /src

stitch.toml: name the dependency after the library’s crate.

[rust.dependencies]
kvrs = { path = "/src" }

Dockerfile: build and install the gem.

ARG STITCH_BASE
FROM ${STITCH_BASE}
COPY --from=source . /src
RUN cd /src && gem build kvrb.gemspec && gem install --local ./kvrb-*.gem

stitch.toml: set include to the gem name. Only this gem gets coverage and comparison tracing.

[ruby]
include = ["kvrb"]

Dockerfile (unchanged from init):

ARG STITCH_BASE
FROM ${STITCH_BASE}
COPY --from=source . /src

stitch.toml: init reads the package and its products from Package.swift.

[swift]
dependencies = ['.package(path: "/src")']
products = ['.product(name: "KVSwift", package: "src")']

Dockerfile: build a static library with $CC, which adds coverage and sanitizer instrumentation.

ARG STITCH_BASE
FROM ${STITCH_BASE}
COPY --from=source . /src
WORKDIR /src
RUN $CC -fobjc-arc -c KVStore.m -o KVStore.o && ar rcs libkvstore.a KVStore.o

stitch.toml: tell the harness where the headers and the library are.

[build]
cflags = ["-I/src"]
ldflags = ["/src/libkvstore.a"]
sanitizers = ["address"]

Build the image:

stitch build --image-only

If the build fails, the error and the path of the full log are printed. stitch shell opens a shell in the image, which helps when you are working out build commands.

Next, write the stubs.