2. Create a project
A project is a folder with three things:
stitch.toml: where the library source is, and build and fuzzing settingsDockerfile: builds or installs the libraryharness/: your stubs
Initialize
Section titled “Initialize”Run this from examples/:
stitch setup --lang pythonstitch init kv --lang python --path python-demo/libcd kvstitch setup --lang cppstitch init kv --path cpp-demo/libcd kvstitch setup --lang javascriptstitch init kv --lang javascript --path javascript-demo/libcd kvstitch setup --lang javastitch init kv --lang java --path java-demo/libcd kvstitch setup --lang gostitch init kv --lang go --path go-demo/libcd kvstitch setup --lang ruststitch init kv --lang rust --path rust-demo/libcd kvstitch setup --lang rubystitch init kv --lang ruby --path ruby-demo/libcd kvstitch setup --lang swiftstitch init kv --lang swift --path swift-demo/libcd kvstitch setup --lang objcstitch init kv --lang objc --path objc-demo/libcd kv--path points at a local folder. For a library in a git repository, use
--git URL --rev REV instead.
Build the library
Section titled “Build the library”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_BASEFROM ${STITCH_BASE}COPY --from=source . /srcRUN pip install --no-cache-dir /srcstitch.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_BASEFROM ${STITCH_BASE}COPY --from=source . /srcWORKDIR /srcRUN 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_BASEFROM ${STITCH_BASE}COPY --from=source . /srcRUN cd /opt && npm install /srcstitch.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_BASEFROM ${STITCH_BASE}COPY --from=source . /srcRUN 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_BASEFROM ${STITCH_BASE}COPY --from=source . /srcRUN cd /src && go mod downloadstitch.toml: init reads the module path from go.mod.
[go]module = "example.com/kvgo"Dockerfile (unchanged from init):
ARG STITCH_BASEFROM ${STITCH_BASE}COPY --from=source . /srcstitch.toml: name the dependency after the library’s crate.
[rust.dependencies]kvrs = { path = "/src" }Dockerfile: build and install the gem.
ARG STITCH_BASEFROM ${STITCH_BASE}COPY --from=source . /srcRUN cd /src && gem build kvrb.gemspec && gem install --local ./kvrb-*.gemstitch.toml: set include to the gem name. Only this gem gets coverage and comparison tracing.
[ruby]include = ["kvrb"]Dockerfile (unchanged from init):
ARG STITCH_BASEFROM ${STITCH_BASE}COPY --from=source . /srcstitch.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_BASEFROM ${STITCH_BASE}COPY --from=source . /srcWORKDIR /srcRUN $CC -fobjc-arc -c KVStore.m -o KVStore.o && ar rcs libkvstore.a KVStore.ostitch.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-onlyIf 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.