diff --git a/.gitignore b/.gitignore index 3a8cb4c..45a05cd 100644 --- a/.gitignore +++ b/.gitignore @@ -5,7 +5,6 @@ *.exe *.exe~ *.dll -*.a *.so *.dylib diff --git a/Makefile b/Makefile index 6eb5c69..fe40ce5 100644 --- a/Makefile +++ b/Makefile @@ -9,4 +9,4 @@ fmt: gofumpt -l -w . test: - ./run_test.sh + go test -v -race -gcflags="-l" -ldflags="-s=false" -coverprofile=coverage.txt -covermode=atomic ./... diff --git a/README.md b/README.md index 38d97a2..b3d71c6 100644 --- a/README.md +++ b/README.md @@ -1,20 +1,22 @@ # da-codec +Scroll's DA encoding/decoding libraries. + ## Running unit tests ``` -# Prepare dev-container -docker pull scrolltech/go-rust-builder:go-1.21-rust-nightly-2023-12-03 --platform linux/amd64 -docker run -it --rm -v "$(PWD):/workspace" -w /workspace scrolltech/go-rust-builder:go-1.21-rust-nightly-2023-12-03 +go test -v -race ./... +``` -# Compile libzstd -cd libzstd && make libzstd && cd .. -mkdir -p /scroll/lib/ -cp -f $(pwd)/libzstd/target/release/libscroll_zstd.so /scroll/lib/ +## FAQ -# Set the environment variable -export LD_LIBRARY_PATH=$LD_LIBRARY_PATH:/scroll/lib/ -export CGO_LDFLAGS="-L/scroll/lib/ -Wl,-rpath,/scroll/lib/" +**Q: Why the repo contains `libscroll_zstd*.a` binary files?** -# Run unit tests -go test -v -race ./... -``` +A: This simplifies package installation with `go get` without the need to perform additional steps for building the `libscroll_zstd*.a`. + +**Q: Which platforms/architectures are supported?** + +A: `linux/amd64`, `linux/arm64`, `darwin/arm64`. Pull requests for other platforms/architectures are accepted. + +**Q: I don't trust `libscroll_zstd*.a` binary files from the repo or these files don't work on my OS/ARCH. How to rebuild them?** + +A: Just run `cd libzstd && make libzstd` if your OS/ARCH is supported. diff --git a/encoding/codecv2/codecv2.go b/encoding/codecv2/codecv2.go index 218d9e9..719b88a 100644 --- a/encoding/codecv2/codecv2.go +++ b/encoding/codecv2/codecv2.go @@ -1,7 +1,6 @@ package codecv2 /* -#cgo LDFLAGS: -lm -ldl -lscroll_zstd #include char* compress_scroll_batch_bytes(uint8_t* src, uint64_t src_size, uint8_t* output_buf, uint64_t *output_buf_size); */ diff --git a/encoding/codecv2/libscroll_zstd_darwin_arm64.a b/encoding/codecv2/libscroll_zstd_darwin_arm64.a new file mode 100644 index 0000000..7180e1c Binary files /dev/null and b/encoding/codecv2/libscroll_zstd_darwin_arm64.a differ diff --git a/encoding/codecv2/libscroll_zstd_darwin_arm64.go b/encoding/codecv2/libscroll_zstd_darwin_arm64.go new file mode 100644 index 0000000..8ace74c --- /dev/null +++ b/encoding/codecv2/libscroll_zstd_darwin_arm64.go @@ -0,0 +1,6 @@ +package codecv2 + +/* +#cgo LDFLAGS: ${SRCDIR}/libscroll_zstd_darwin_arm64.a +*/ +import "C" diff --git a/encoding/codecv2/libscroll_zstd_linux_amd64.a b/encoding/codecv2/libscroll_zstd_linux_amd64.a new file mode 100644 index 0000000..b2e6040 Binary files /dev/null and b/encoding/codecv2/libscroll_zstd_linux_amd64.a differ diff --git a/encoding/codecv2/libscroll_zstd_linux_amd64.go b/encoding/codecv2/libscroll_zstd_linux_amd64.go new file mode 100644 index 0000000..0b22575 --- /dev/null +++ b/encoding/codecv2/libscroll_zstd_linux_amd64.go @@ -0,0 +1,9 @@ +//go:build !musl +// +build !musl + +package codecv2 + +/* +#cgo LDFLAGS: ${SRCDIR}/libscroll_zstd_linux_amd64.a +*/ +import "C" diff --git a/encoding/codecv2/libscroll_zstd_linux_arm64.a b/encoding/codecv2/libscroll_zstd_linux_arm64.a new file mode 100644 index 0000000..999dcd5 Binary files /dev/null and b/encoding/codecv2/libscroll_zstd_linux_arm64.a differ diff --git a/encoding/codecv2/libscroll_zstd_linux_arm64.go b/encoding/codecv2/libscroll_zstd_linux_arm64.go new file mode 100644 index 0000000..ebf3943 --- /dev/null +++ b/encoding/codecv2/libscroll_zstd_linux_arm64.go @@ -0,0 +1,9 @@ +//go:build !musl +// +build !musl + +package codecv2 + +/* +#cgo LDFLAGS: ${SRCDIR}/libscroll_zstd_linux_arm64.a +*/ +import "C" diff --git a/libzstd/Cargo.toml b/libzstd/Cargo.toml index e734163..0298b15 100644 --- a/libzstd/Cargo.toml +++ b/libzstd/Cargo.toml @@ -9,7 +9,7 @@ version = "0.1.0" edition = "2021" [lib] -crate-type = ["cdylib"] +crate-type = ["staticlib"] # See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html diff --git a/run_test.sh b/run_test.sh deleted file mode 100755 index e7e7b65..0000000 --- a/run_test.sh +++ /dev/null @@ -1,13 +0,0 @@ -#!/bin/bash - -# Compile libzstd -cd libzstd && make libzstd && cd .. -sudo mkdir -p /scroll/lib/ -sudo cp -f $(pwd)/libzstd/target/release/libscroll_zstd.so /scroll/lib/ - -# Set the environment variable -export LD_LIBRARY_PATH=$LD_LIBRARY_PATH:/scroll/lib/ -export CGO_LDFLAGS="-L/scroll/lib/ -Wl,-rpath,/scroll/lib/" - -# Run unit tests -go test -v -race -gcflags="-l" -ldflags="-s=false" -coverprofile=coverage.txt -covermode=atomic ./...