Originally meant to be `array.concat_n`, but this name is better as the behavior of this function differs from `array.concat` — namely that `array.flatten` accepts any type of valued in the input array. Only arrays are however flattened, and the rest are appended directly to the flattened output. Note that this function only flattens at the topmost level of the input array — not recursively! A cursory look at a few other languages suggest a single level is the common case. But if others feel we should flstten more, I'm happy to make an update. The C code for a Wasm implementstion here is cowboy coded, and I did not manage to run the tests on my machine due to some `docker` <-> `container` differences. I mostly just imitated the existing code in the array category. I doubt it'll work on the first try, but only CI can judge me. Also: - Remove `opa fmt` step from the Rego CI step, as this is done by Regal anyway a little later in the list of tasks. - Replace some hard-coded `docker` names in the `Makefile` with `$(DOCKER)` - Added name of built-in function missing to the unsupportedBuiltinErr error, as it has happened a few times now that I've used `:=` in a query, and had no clue what built-in it referred to. Fixes #8226 Signed-off-by: Anders Eknert <anders.eknert@apple.com>
OPA-WASM
This directory contains a library that implements various low-level operations for policies compiled into WebAssembly (Wasm). Specifically, the library implements most of the built-in functions provided by OPA. See the "Wasm" tag next to each function listed in the built-in function reference for the complete list, or the builtin_metadata.json file for programmatic purposes.
This library does not make any backwards compatibility guarantees.
Documentation
See the OPA docs on Wasm for an overview of the integration, compilation options, and more.
Development
You should have Docker installed to build and test changes to the library. We
commit the output of the build (opa.wasm) into the repository, so it's
important for the build output to be reproducible.
You can build the library by running make build. This will produce WASM
executables under the _obj directory.
You can test the library by running make test. By default, the test runner
does not print messages when tests pass. If you run make test VERBOSE=1 it
will log all of the tests that were run.
You can run make hack to start a shell inside the builder image. This is
useful if you need to interact with low-level WASM tooling like
wasm-objdump, wasm2wat, etc. or LLVM itself.
You must manually push the builder image if you make changes to it (run make builder to produce a new Docker image).
Debug Builds
Set the DEBUG environment variable to 1 to enable generating binaries with
debug symbols and a less aggressive optimization level. Eg: DEBUG=1 make build.
Vendoring
If you make changes to the library, run the make generate in the parent
directory and commit the results back to the repository. The generate
target will:
- Build the OPA-WASM library
- Copy the library into the internal/compiler/wasm/opa directory.
- Run the tool to generate the internal/compiler/wasm/opa/opa.go file.