Valdi rules for Bazel
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
Building
To build a single module using the default, macOS toolchain:
bazel build //src/valdi_modules/src/valdi/jasmine
Android
To build the Android target:
bazel build //src/valdi_modules/src/valdi/jasmine --platforms=@snap_platforms//os:android_arm64
iOS
To build the iOS target:
bazel build //src/valdi_modules/src/valdi/jasmine --platforms=//bzl/platforms:ios_x64
Maintaining BUILD.bazel files
A 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.
Older Valdi projects may have a module.yaml file alongside BUILD.bazel. module.yaml is deprecated; all module configuration belongs in the valdi_module() rule. See glossary.
Testing
You can run your tests using bazel test directly. See documentation about it here: Testing.
Linting
Once implemented, users will be able to run linting for a single module using Bazel.
Rebuilding the compiler and companion
Bazel builds the compiler (compiler/compiler) and the companion (the JS/TS app in compiler/companion) from source. There are no prebuilt compiler binaries.
Rebuilding the compiler
Building Valdi modules rebuilds the compiler when its sources change. To build it on its own:
bazel build //compiler/compiler:local_valdi_compiler
The compiler is built with Bazel, so no Swift toolchain install is required.
To confirm your compiler build 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.
Using a locally built companion
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.
Known issues and limitations
- Updating proto config doesn't trigger a valdi module rebuild