Each valdi module contains a BUILD.bazel file which has a single call to valdi_module macros. The macro setups a few targets and aliases to build the module from source using the Valdi Toolchain.
The list of targets created by the valdi_module macro includes:
module_name:module_nametarget which builds just the.valdimodulefile. It is the default target and can be referenced asmodule_namefor example//src/valdi_modules/src/valdi/jasmine.module_name:module_name_kttarget which builds theandroid_libraryand packages the Valdi generated Kotlin code, if any. It depends on the Valdi module target above and adds the.valdimoduleand other resources to thedataattribute.module_name:module_name_objctarget which builds theobjc_libraryand packages the Valdi generated Objective-C code, if any. It depends on the Valdi module target above and adds the.valdimoduleand other resources to thedataattribute.module_name:module_name_objc_apitarget which builds theobjc_libraryand wraps the generated Objective-C API code, if any. It also depends on themodule_name_objctarget above.module_name:{ModuleName}an alias pointing atmodule_name:module_name_objcto keep the compatibility with iOSmodule_name:{ModuleName}Typesan alias pointing atmodule_name:module_name_objc_apito keep the compatibility with iOS
To build a single module using the default, macOS toolchain:
bazel build //src/valdi_modules/src/valdi/jasmineTo build the Android target:
bazel build //src/valdi_modules/src/valdi/jasmine --platforms=@snap_platforms//os:android_arm64To build the iOS target:
bazel build //src/valdi_modules/src/valdi/jasmine --platforms=//bzl/platforms:ios_x64A Valdi module is configured entirely through the valdi_module(...) call in its BUILD.bazel. Edit that file directly to change module configuration.
To add a new dependency, add the module's Bazel label to the deps attribute of the valdi_module() call in BUILD.bazel. For example:
valdi_module(
name = "my_module",
srcs = glob(["src/**/*.ts", "src/**/*.tsx"]),
deps = [
"@valdi//src/valdi_modules/src/valdi/valdi_core",
"//src/valdi_modules/src/valdi/some_other_valdi_module",
],
)See Core Module for the full list of valdi_module() attributes.
Note: Older Valdi projects may have a
module.yamlfile alongsideBUILD.bazel.module.yamlis deprecated; all module configuration belongs in thevaldi_module()rule. See glossary.
You can run your tests using bazel test directly. See documentation about it here: Testing.
Once implemented, users will be able to run linting for a single module using Bazel.
By default, Bazel uses the prebuilt compiler and builds the companion from source (the companion is the JS/TS app in compiler/companion). To use your own builds so they are not overwritten by prebuilts:
-
Build the Valdi compiler and place the binary where the toolchain can find it:
compiler/compiler/scripts/update_compiler_bazel.sh -o compiler/compiler/out
This produces
compiler/compiler/out/macos/valdi_compiler(orout/linux/valdi_compileron Linux). The compiler is built with Bazel (//compiler/compiler:local_valdi_compiler), so no Swift toolchain install is required. The script works in both the mirrored public repo and the mobile monorepo. -
Build Valdi modules with the local compiler:
bazel build //src/valdi_modules/src/valdi/jasmine --//bzl/valdi:use_local_compiler=true
The out/ directory is gitignored so your local binary is never committed.
Tip
To confirm the local binary is being picked up, check the Bazel worker log after the first build:
cat "$(ls ~/.cache/bazel/*/bazel-workers/worker-*-ValdiCompile.log 2>/dev/null | head -1)"The first line should read [local-compiler] valdi compiler (local build) starting (or whatever marker you added). The worker log path is also printed by Bazel when --worker_verbose is passed.
The toolchain already uses the source-built companion by default (use_prebuilt_companion is false), so the companion is built from compiler/companion (e.g. webpack output). To avoid Bazel overwriting your npm-built companion output:
-
Build the companion in dev mode (writes to
dist_dev/instead ofdist/):cd compiler/companion && npm run build-dev
-
Build or run Valdi with the dev-mode companion:
bazel build //src/valdi_modules/src/valdi/jasmine --//compiler/companion:dev_mode=true
Bazel will use dist_dev/bundle.js and will not overwrite your dist/ folder.
- Updating proto config doesn't trigger a valdi module rebuild