Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add tokenizers_srcdir_relative build tag to allow static library path #15

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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/tokenizers@v0.6.1/), 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/tokenizers@v0.6.0/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++
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

why are you picking /usr/lib/libtokenizers.a over package relative libtokenizers.a?

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I mentioned that in my comment, by making the build flag name "tokenizers_srcdir_relative" as you suggest, package relative therefore becomes the non-default option. If you prefer to keep the current default behaviour we need to change that flag name to something like "tokenizers_srcdir_static"? Do you have a preferred name?

#include <stdlib.h>
#include "tokenizers.h"
*/
Expand Down
Loading