Skip to content

Commit

Permalink
feat: turn dynamic lib into static (#8)
Browse files Browse the repository at this point in the history
* replace dynamic to static lib

* add precompiled library

* add darwin arm64

* .a files

* simplify readme

* small fix

* add linux arm64

* add readme

---------

Co-authored-by: colinlyguo <[email protected]>
  • Loading branch information
noel2004 and colinlyguo authored Jun 5, 2024
1 parent d7bcb62 commit 32bfc9f
Show file tree
Hide file tree
Showing 12 changed files with 41 additions and 30 deletions.
1 change: 0 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@
*.exe
*.exe~
*.dll
*.a
*.so
*.dylib

Expand Down
2 changes: 1 addition & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -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 ./...
28 changes: 15 additions & 13 deletions README.md
Original file line number Diff line number Diff line change
@@ -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.
1 change: 0 additions & 1 deletion encoding/codecv2/codecv2.go
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
package codecv2

/*
#cgo LDFLAGS: -lm -ldl -lscroll_zstd
#include <stdint.h>
char* compress_scroll_batch_bytes(uint8_t* src, uint64_t src_size, uint8_t* output_buf, uint64_t *output_buf_size);
*/
Expand Down
Binary file added encoding/codecv2/libscroll_zstd_darwin_arm64.a
Binary file not shown.
6 changes: 6 additions & 0 deletions encoding/codecv2/libscroll_zstd_darwin_arm64.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
package codecv2

/*
#cgo LDFLAGS: ${SRCDIR}/libscroll_zstd_darwin_arm64.a
*/
import "C"
Binary file added encoding/codecv2/libscroll_zstd_linux_amd64.a
Binary file not shown.
9 changes: 9 additions & 0 deletions encoding/codecv2/libscroll_zstd_linux_amd64.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
//go:build !musl
// +build !musl

package codecv2

/*
#cgo LDFLAGS: ${SRCDIR}/libscroll_zstd_linux_amd64.a
*/
import "C"
Binary file added encoding/codecv2/libscroll_zstd_linux_arm64.a
Binary file not shown.
9 changes: 9 additions & 0 deletions encoding/codecv2/libscroll_zstd_linux_arm64.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
//go:build !musl
// +build !musl

package codecv2

/*
#cgo LDFLAGS: ${SRCDIR}/libscroll_zstd_linux_arm64.a
*/
import "C"
2 changes: 1 addition & 1 deletion libzstd/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
13 changes: 0 additions & 13 deletions run_test.sh

This file was deleted.

0 comments on commit 32bfc9f

Please sign in to comment.