Go to file
Lucendio fd65a61e87 Fix builds filter ro re-enable darwin builds
I was not able to find any evidences of darwin builds being disabled intentionally. Considering
the [documentation](https://goreleaser.com/customization/build/) I suspect that this was by
mistake. Currently, each list item is applied individually (OR). If I'm wrong, please discard this
PR and share your reasoning.
2020-12-12 23:49:31 +01:00
.github/workflows add action to build binaries with goreleaser 2020-08-08 18:31:51 +02:00
ast Anonymous Import Locations 2020-09-08 17:27:47 +02:00
astgen Release 0.17.0 2020-11-22 15:45:52 +01:00
bazel Release 0.17.0 2020-11-22 15:45:52 +01:00
builtin-benchmarks Support for array comparison 2020-10-30 20:42:46 +01:00
c-bindings Add format APIs to C bindings 2020-11-26 19:23:49 +01:00
c-bindings-tests Add format APIs to C bindings 2020-11-26 19:23:49 +01:00
cmd Anonymous Import Locations 2020-09-08 17:27:47 +02:00
cpp-jsonnet@ed11b012a4 Release 0.17.0 2020-11-22 15:45:52 +01:00
formatter feat(api): expose formatter 2020-03-31 20:43:25 +02:00
internal Fix missing stack trace entry for assertions. 2020-11-21 18:31:58 +01:00
linter Linter 2020-08-13 21:06:34 +02:00
python Release GIL in Python bindings. 2020-11-21 18:00:35 +01:00
testdata Fix missing stack trace entry for assertions. 2020-11-21 18:31:58 +01:00
toolutils feat(parser): export parser.Children (#327) 2019-10-06 22:38:37 +02:00
.gitignore Linter 2020-08-13 21:06:34 +02:00
.gitmodules Add C++-Jsonnet submodule for tests (#202) 2018-03-06 13:05:00 -05:00
.golangci.yml Linter 2020-08-13 21:06:34 +02:00
.goreleaser.yml Fix builds filter ro re-enable darwin builds 2020-12-12 23:49:31 +01:00
.tool-versions feat: add asdf integration for bazel 2020-01-25 07:45:07 +01:00
.travis.yml Change CI settings to use the latest release, but not the tip. 2020-10-05 20:39:32 +02:00
benchmark.sh feat: Improve performance of substr by 84.44% 2020-01-26 09:20:58 +01:00
BUILD.bazel Support for array comparison 2020-10-30 20:42:46 +01:00
builtins_benchmark_test.go Support for array comparison 2020-10-30 20:42:46 +01:00
builtins.go Better handling of stack traces. 2020-11-21 15:36:05 +01:00
CONTRIBUTING Add CONTRIBUTING, add newline to end of other files 2016-02-19 17:36:19 -05:00
doc.go Remove go:generate causing errors 2017-09-29 12:36:04 -04:00
error_formatter.go Make golangci-lint happy 2020-03-05 14:54:27 +01:00
go.mod Add native golang formatter (#388) 2020-03-10 22:19:49 +00:00
go.sum Add native golang formatter (#388) 2020-03-10 22:19:49 +00:00
imports.go Better handling of stack traces. 2020-11-21 15:36:05 +01:00
interpreter_test.go First end-to-end test (addition of numbers) 2016-03-08 01:17:44 -05:00
interpreter.go Better handling of stack traces. 2020-11-21 15:36:05 +01:00
jsonnet_test.go Anonymous Import Locations 2020-09-08 17:27:47 +02:00
LICENSE Add CONTRIBUTING, add newline to end of other files 2016-02-19 17:36:19 -05:00
main_test.go Anonymous Import Locations 2020-09-08 17:27:47 +02:00
Makefile perf(stdlib): ️ implement manifestJsonEx as native Go 2020-06-13 19:53:42 +02:00
MANIFEST.in Release v0.16.0 2020-05-22 19:13:53 +02:00
README.md Add a short script for updating cpp-jsonnet. 2020-11-21 15:26:25 +01:00
runtime_error.go Unexport a bunch of symbols 2019-09-09 16:11:00 +02:00
setup.py Replace setup.py test with pytest command (#380) 2020-02-20 10:37:39 +01:00
tests.sh Better handling of stack traces. 2020-11-21 15:36:05 +01:00
thunks.go Better handling of stack traces. 2020-11-21 15:36:05 +01:00
travisBazel.sh Remove depreacted Bazel option for CI 2020-04-15 14:29:41 +02:00
travisBuild.sh Enforce no golangci-lint warnings in CI 2020-03-05 14:54:27 +01:00
update_cpp_jsonnet.sh Add a short script for updating cpp-jsonnet. 2020-11-21 15:26:25 +01:00
util.go Support for array comparison 2020-10-30 20:42:46 +01:00
value.go Better handling of stack traces. 2020-11-21 15:36:05 +01:00
vm.go Release 0.17.0 2020-11-22 15:45:52 +01:00
WORKSPACE Allow use of Bazel repository externally 2019-07-04 13:09:47 +02:00

go-jsonnet

GoDoc Widget Travis Widget Coverage Status Widget

This an implementation of Jsonnet in pure Go. It is a feature complete, production-ready implementation. It is compatible with the original Jsonnet C++ implementation. Bindings to C and Python are available (but not battle-tested yet).

This code is known to work on Go 1.11 and above. We recommend always using the newest stable release of Go.

Installation instructions

go get github.com/google/go-jsonnet/cmd/jsonnet

It's also available on Homebrew:

brew install go-jsonnet

Build instructions (go 1.11+)

git clone git@github.com:google/go-jsonnet.git
cd go-jsonnet
go build ./cmd/jsonnet
go build ./cmd/jsonnetfmt
go build ./cmd/jsonnet-deps

To build with Bazel instead:

git clone git@github.com:google/go-jsonnet.git
cd go-jsonnet
git submodule init
git submodule update
bazel build //cmd/jsonnet
bazel build //cmd/jsonnetfmt
bazel build //cmd/jsonnet-deps

The resulting jsonnet program will then be available at a platform-specific path, such as bazel-bin/cmd/jsonnet/darwin_amd64_stripped/jsonnet for macOS.

Bazel also accommodates cross-compiling the program. To build the jsonnet program for various popular platforms, run the following commands:

Target platform Build command
Current host bazel build //cmd/jsonnet
Linux bazel build --platforms=@io_bazel_rules_go//go/toolchain:linux_amd64 //cmd/jsonnet
macOS bazel build --platforms=@io_bazel_rules_go//go/toolchain:darwin_amd64 //cmd/jsonnet
Windows bazel build --platforms=@io_bazel_rules_go//go/toolchain:windows_amd64 //cmd/jsonnet

For additional target platform names, see the per-Go release definitions here in the rules_go Bazel package.

Additionally if any files were moved around, see the section Keeping the Bazel files up to date.

Running tests

./tests.sh  # Also runs `go test ./...`

Running Benchmarks

Method 1

go get golang.org/x/tools/cmd/benchcmp
  1. Make sure you build a jsonnet binary prior to making changes.
go build -o jsonnet-old ./cmd/jsonnet
  1. Make changes (iterate as needed), and rebuild new binary
go build ./cmd/jsonnet
  1. Run benchmark:
# e.g. ./benchmark.sh Builtin
./benchmark.sh <TestNameFilter>

Method 2

  1. get benchcmp
go get golang.org/x/tools/cmd/benchcmp
  1. Make sure you build a jsonnet binary prior to making changes.
make build-old
  1. iterate with (which will also automatically rebuild the new binary ./jsonnet)

replace the FILTER with the name of the test you are working on

FILTER=Builtin_manifestJsonEx make benchmark

Implementation Notes

We are generating some helper classes on types by using http://clipperhouse.github.io/gen/. Do the following to regenerate these if necessary:

go get github.com/clipperhouse/gen
go get github.com/clipperhouse/set
export PATH=$PATH:$GOPATH/bin  # If you haven't already
go generate

Update cpp-jsonnet sub-repo

This repo depends on the original Jsonnet repo. Shared parts include the standard library, headers files for C API and some tests.

You can update the submodule and regenerate dependent files with one command:

./update_cpp_jsonnet.sh

Note: It needs to be run from repo root.

Updating and modifying the standard library

Standard library source code is kept in cpp-jsonnet submodule, because it is shared with Jsonnet C++ implementation.

For performance reasons we perform preprocessing on the standard library, so for the changes to be visible, regeneration is necessary:

go run cmd/dumpstdlibast/dumpstdlibast.go cpp-jsonnet/stdlib/std.jsonnet > astgen/stdast.go

**The

The above command creates the astgen/stdast.go file which puts the desugared standard library into the right data structures, which lets us avoid the parsing overhead during execution. Note that this step is not necessary to perform manually when building with Bazel; the Bazel target regenerates the astgen/stdast.go (writing it into Bazel's build sandbox directory tree) file when necessary.

Keeping the Bazel files up to date

Note that we maintain the Go-related Bazel targets with the Gazelle tool. The Go module (go.mod in the root directory) remains the primary source of truth. Gazelle analyzes both that file and the rest of the Go files in the repository to create and adjust appropriate Bazel targets for building Go packages and executable programs.

After changing any dependencies within the files covered by this Go module, it is helpful to run go mod tidy to ensure that the module declarations match the state of the Go source code. In order to synchronize the Bazel rules with material changes to the Go module, run the following command to invoke Gazelle's update-repos command:

bazel run //:gazelle -- update-repos -from_file=go.mod -to_macro=bazel/deps.bzl%jsonnet_go_dependencies

Similarly, after adding or removing Go source files, it may be necessary to synchronize the Bazel rules by running the following command:

bazel run //:gazelle