Skip to content

Commit

Permalink
Add tokenizers_srcdir_relative build tag to allow static library path
Browse files Browse the repository at this point in the history
  • Loading branch information
RJKeevil committed Nov 20, 2023
1 parent 4fd5a66 commit fd5820d
Show file tree
Hide file tree
Showing 4 changed files with 11 additions and 4 deletions.
2 changes: 1 addition & 1 deletion Makefile
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
build:
@cargo build --release
@cp target/release/libtokenizers.a .
@go build .
@go build -tags tokenizers_srcdir_relative .

build-example:
@docker build -f ./example/Dockerfile . -t tokenizers-example
Expand Down
6 changes: 6 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,12 @@ Go bindings for the [HuggingFace Tokenizers](https://github.com/huggingface/toke

`make build` to build `libtokenizers.a` that you need to run your application that uses bindings.

To use `libtokenizers.a` in your go application, either:
* Place `libtokenizers.a` in /usr/lib/, and compile your app as usual with `go build`.
* Place `libtokenizers.a` in the go source directory of the tokenizer module
(e.g. /home/user/go/pkg/mod/github.com/daulet/[email protected]/), and compile with
`go build -tags tokenizers_srcdir_relative`.

### Using pre-built binaries

Build your Go application using pre-built native binaries: `docker build --platform=linux/amd64 -f example/Dockerfile .`
Expand Down
4 changes: 2 additions & 2 deletions release/Dockerfile
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# syntax=docker/dockerfile:1.3

FROM rust:1.71 as builder-rust
FROM rust:1.74 as builder-rust
ARG TARGETPLATFORM
WORKDIR /workspace
COPY ./src ./src
Expand All @@ -16,5 +16,5 @@ COPY ./test/data ./test/data
RUN go mod download
COPY --from=builder-rust \
/workspace/target/release/libtokenizers.a \
/go/pkg/mod/github.com/daulet/[email protected]/libtokenizers.a
/usr/lib/libtokenizers.a
RUN go run main.go
3 changes: 2 additions & 1 deletion tokenizer.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,8 @@ package tokenizers
// TODO packaging: how do we build the rust lib for distribution?

/*
#cgo LDFLAGS: ${SRCDIR}/libtokenizers.a -ldl -lm -lstdc++
#cgo tokenizers_srcdir_relative LDFLAGS: ${SRCDIR}/libtokenizers.a -ldl -lm -lstdc++
#cgo !tokenizers_srcdir_relative LDFLAGS: /usr/lib/libtokenizers.a -ldl -lm -lstdc++
#include <stdlib.h>
#include "tokenizers.h"
*/
Expand Down

0 comments on commit fd5820d

Please sign in to comment.