-
Notifications
You must be signed in to change notification settings - Fork 23
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
libtokenizers.a path should not depend on build source directory #4
Conversation
By relatively locating the library, one can just drop the pre-built library in their own project to make it work.
When I imported the module and dropped the prebuilt library at the root of my project, I had the following error: $ go run main.go
# command-line-arguments
/usr/lib/go/pkg/tool/linux_amd64/link: running gcc failed: exit status 1
/usr/bin/ld: cannot find /home/user/go/pkg/mod/github.com/daulet/tokenizers@v0.5.0/libtokenizers.a: No such file or directory
collect2: error: ld returned 1 exit status With the change in this commit, it just works. |
Yes, it will work if you just have one package, but if your repo has multiple packages that use tokenizers, they will all look for the binary in the root of each package. So making the path relative to the module source decouples it from user's repo structure. |
Fine. Maybe a better way would be to make the library built during the installation by using the |
If you could make it work, sure.
isn't that always under $GOPATH/pkg/mod, unless you vendor. |
Nop, as you can see in the error above, the library should land in I mean that's not so bad but that's definitely a barrier that we can get rid of to increase adoption of the project in my opinion. I'll try the |
As I mentioned, under proposed solution once your project has two packages using this module you'd have to copy the lib to two places . |
I think this proposed change is an improvement, as we build our application via docker CI/CD, and have a complex, version dependent, pre-setup step of having to initialize a full path (/home/user/go/pkg/mod/github.com/daulet/tokenizers@v0.5.0/) in order to drop in libtokenizers.a before compiling our app. At least with this change we can just place libtokenizers.a in the root of our app before compiling. Alternative is to actually commit this file to the repo, so it will be there without the copy (though committing artifacts is a bit nasty)? |
I tried the |
|
Artifacts are platform (OS/CPU) dependent so there is no single artifact to satisfy all. |
You'd need to copy it to the directory of each module that uses this dependency, which means N copies, while making it source agnostic allows a single copy. Does that make sense? |
@daulet for us at least that is not an issue, as we use it in a single module, and the docker build becomes much more simple/reliable than having to determine the current tokenizer version, generating a deeply nested folder and copying the lib to that path. The main issue is having the version number in the path, in reality it can be placed anywhere, as long as the version number isnt part of the path. Edit: I see you now have an example dockerfile, which helps makes this simpler for people new to the project. |
I bet you can write a script to extract the version from |
Yes it's definitely possible and no big issue, just might be easier for future users if it can be an argument, something like how it is done in this project https://github.com/yalue/onnxruntime_go |
Ok one additional issue with the lib being in the go path - it prevents you from using the docker run target feature in goland/intellij. This feature dynamically compiles and runs your dev code in an existing docker image. But it fails to compile as go mod sees that the tokenizer folder exists in the image, and assumes the go code for the dependency has already been fetched. So I would need to also copy the tokenizer go code in my Docker build process, which is very messy. |
Thanks for suggestion, was interesting read. They have a different problem where the lib they are trying to load is outside of their control and named differently on different platforms. So they end up loading the library at runtime, which brings its own complications with packaging and releasing. This library produces static build that is self sufficient. |
Hello, in understanding cgo a little better I perhaps have a simple solution to this discussion. I see that you can switch cgo directives using build tags. This means that if you replace the directive statement with something like
Then using |
@RJKeevil that's cool, want to send a PR? I think we should the directive something like |
The thing is, the go module cache is read-only by design... long story short- this shouldn't be there, and it's probably should be configurable.... |
I think #18 allows for the modularity that is being described here. |
I believe #18 solves everyone's use cases. |
By relatively locating the library, one can just drop the pre-built library in their own project to make it work.