-
-
Notifications
You must be signed in to change notification settings - Fork 1.6k
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
Shipping libevent.a and libpcre.a with the linux binary packages #9285
Comments
This would potentially be quite a mess once you try to move it across
distros...
…On Wed, May 13, 2020, 12:10 AM Heng Li ***@***.***> wrote:
It seems that the crystal compiler requires libevent and pcre. If either
library is absent, the linker will throw an error like
/usr/bin/ld: cannot find -levent (this usually means you need to install the development package for libevent)
Unfortunately, libevent and pcre are often missing from a system and
installing/compiling them without root/sudo is non-trivial for
inexperienced users.
A simple solution to this problem is to compile the two libraries as
static libevent.a and libpcre.a on older Linux and put them in
crystal-0.34-1/lib/crystal/lib along with libgc.a. This way, we can
compile without system libevent and pcre. Furthermore, the resulting binary
is not dynamically linked to libevent.so or libpcre.so – it is more
portable.
PCRE and libevent don't have additional dependencies. They can be easily
compiled as static libraries with ./configure --disable-shared. On my
system, the compiled libraries can be found in .libs/lib{event,pcre}.a. I
have tried this approach. It is working well for me.
—
You are receiving this because you are subscribed to this thread.
Reply to this email directly, view it on GitHub
<#9285>, or unsubscribe
<https://github.com/notifications/unsubscribe-auth/AAM4YSJPSRRHDF6L5Z5YMVDRRITVVANCNFSM4M7NKHGQ>
.
|
@lh3 how are you installing Crystal? |
This seems like an issue for https://github.com/crystal-lang/distribution-scripts I hope with 1.0 more distros will accept us into their repositories and this will become less of an issue. I'm happy to be on a distro where there's an official package already, so I don't have to rely on the big workaround that the above linked scripts essentially are :D |
Installing many things without root access is tricky. I don't think crystal is special in this regard - or even has particularly unusual dependencies. I'd rather use system libraries where at all appropriate, since it vastly reduces incompatibilities on systems with versioned glibc symbols. |
@asterite I am using a distributed binary. More exactly: file crystal-0.34.0-1-linux-x86_64.tar.gz from the release page. @jhass I am not familiar with distribution-scripts. My end goal is to be able to download a self-contained binary package such that my users and myself don't have to install additional libraries to use crystal. >90% of my users don't have root privilege on the machines they run tools and they don't know how to install libevent or pcre by themselves. @RX14 and @refi64 I understand glibc is tricky. A common practice is to compile binaries on CentOS6, which is one of the oldest but still maintained distros. Then the compiled binary will work on recent systems. I haven't seen exceptions so far, though maybe I haven't used enough distros. Building on CentOS6 is essentially how anaconda ships portable binaries. You can find precompiled static libraries for libevent and pcre on my FTP site: |
@lh3 the releases page is just there for package managers and others to be able to build distributions. To install crystal you should use your OS distribution system. For example in mac if you use homebrew everything works out of the box. |
@asterite On mac, everything is simple. The problem is linux. Most of my users don't use linuxbrew. I can't force them to install linuxbrew just for crystal. |
He means based on their actual OS. See https://crystal-lang.org/install/, which should cover the majority. |
@Blacksmoke16 Could you elaborate? I said my users don't have root privilege (PS: I don't have sudo permission, either) – this is common among computing environments in academia. They are unable to install packages by themselves. |
More so meant this part. I.e. if on
I imagine they would need an admin to install it then? or maybe build from source (although would prob run into the same problem when trying to install |
@Blacksmoke16 In an academia setting, admin is often non-responsive. That is why conda is becoming popular. I have already given a solution above which conda uses to some extent. I have experiences in dealing with the issue. I am reasonably certain it will work. You can try that.
I can install crystal using the binary package from the release page. If someone can add the two |
We used to release crystal binaries using omnibus. Those packages contains Maybe someone can enlighten the conversation by providing references to where the decision to change was made, so the reasons are not exposed here all over again. I agree with that change anyway but probably there is still space for omnibus generated packages for some users. The package didn't contain actual linker and system libraries, so a build environment is still required. |
@waj Thank you for the information. I appreciate. I will add one minor note. The binary package on the release page ships libgc.a because it is essential to crystal. libevent.a and libpcre.a are actually also essential in that we can't compile a "hello world" program without them. |
Maybe educating your users to use a non-root package manager/distribution form such as linuxbrew, nix, stow, toast, junest, 0install, pkgbrew, zpkg, AppImage, Flatpak etc. could prove useful outside this single instance, solving this problem more generically? Rather than reintroducing Omnibus (it was quite the pain to maintain I think), I would look into making Flatpak and/or AppImage official distribution methods. |
Julia? 🤔🙂
|
@jhass I understand your concerns. If it is indeed tricky to add these two files, I will probably provide my users with my own binary crystal package with the files. Another less-ideal (to me) @waj Oh, sorry. It is a typo. I am playing around several newer languages to see what to recommend to non-CS researchers (I can't tolerate the performance of python). So far crystal is the top on my list. I think it has a better and cleaner design than Nim and Julia. Libevent.a/libpcre.a is the last bit that has been stopping me. |
Ah, I didn't realize Anaconda is essentially a package manager, it's frontpage tells me nothing about what it really does :D To me that sounds like a good solution, we should just have Crystal packages for everything :) But of course that's impossible to do by the core team and we need the help of respective communities to maintain such packages. I see our responsibility as making that possible and easy. Maintaining a Crystal package in the AUR was essentially one of my first contributions to Crystal and it lead to Archlinux to be one of the first (if not the first) distribution shipping Crystal in its repositories :) |
Ok. I will explore how to add a crystal package to conda. I need to seek help from the conda community as I am not that familiar with the conda build system, either. This will take time. Meanwhile, I still hope you may consider to add necessary static libraries to the x64-linux tar.gz. Doing this will benefit more users. I really appreciate that you build a statically linked |
@RX14 do you recall the rational behind dropping those libraries in distribution-scripts with respect what was done in the omnibus originally? |
Because gc isn't packaged - or new enough - in every distro. We got actual errors from users when they were using the distro I agree the solution is conda or similar. If people don't have root, they need a user-mode package manager. conda, nix and linuxbrew fill that role. |
@RX14 Thanks for the explanation. I respect your decision. Just curious: have libevent.a and libpcre.a caused troubles when they were shipped with the binary tar.gz? |
I don't think the reason they were dropped is that they caused trouble, but they're simply non-essential. It's better not to drag that baggage in the core project when it's not necessary. |
But they are not baggage. They are essential to every crystal program. That's the reason why we distributed them statically. I didn't know that changed. Sure, libyaml is required if you use yaml, same goes for libgmp for BigInt and such, and maybe we should include those. |
They are baggage because they're more things we need to maintain. There's a fairly rare usecase (not having root access) where this is a problem, so I wouldn't rush to change this. |
@asterite I don't mean the libraries themselves are baggage but maintining their distribution with crystal requires a lot of additional work. Of course, if we can get a full batteries-included distribution package without much effort, I'm all in. Even not having root access is not really a problem. You can get the libraries without root. There are specific non-root package managers. Or you can just download it. |
But aren't these libraries already available for download? We would just need one step in the build process which is to download them and put them in the tar.gz |
Probably >90% users in the field of bioinformatics don't have root access. I am reasonably certain that quite a few other fields in academia have the same problem.
You can compile the two libraries once and copy them to future binary packages. You may only upgrade them occasionally.
The purpose of providing statically linked |
And we have to track them for security issues and make sure we keep them fairly well up to date. libpcre especially is a CVE quagmire as it JITs code. If someone else in the core team wants to maintain this then it's on them, but I think the risk is fairly high and the benefits are low. So I'll duck out of this conversation. |
The crystal compiler is mostly written in crystal. When you compile the static crystal binary, you need to keep track of the security issues in crystal dependencies anyway. I am trying to promote crystal in my field. I just think having the suggested change will make me much easier to recommend crystal. Anyway, thank you for your time. I appreciate. |
Due to the way crystal is distributed, I don't think I have a chance to persuade devs in my field to use crystal, so I am providing portable binaries through my repository for now. I will talk to people who are familiar with conda. It will take time. Also, distribution through conda is not ideal, either, because all compiled executables will be dynamically linked to libevent and libpcre. This will complicate binary distributions of developers' tools. I can't tell users: "you have to install crystal, libevent and pcre to use my tool". This will push 90% of my users to other tools. Again, for users, the best solution is to include static libraries in tar.gz. You need to keep these libraries updated anyway to compile the statically linked |
That would be terrific @winni2k. As someone working in the field of this use case, you probably have a better angle than most other contributors. |
The conda solution is not ideal for two reasons. First, not everyone is using conda. Second, binaries compiled with dynamic libevent and libpcre require endusers to have the two libraries installed. This hurts binary distribution. The best solution is still on the crystal end: put libevent.a and libpcre.a in the binary distribution package. You already have the two libraries compiled as you need them to link the |
For what it's worth, I tried building a conda package from both the 1.0.0 and 0.32.0 tar files on a CentOS/7 VM that does not have pcre installed. In both cases, I got segmentation faults when trying to compile a hello world example file through the test suite of Update |
Just notice that crystal is providing pcre and libevent as static libraries on mac. If you can do the same to the Linux binary package, it would be great. You already have the mechanism. |
The distribution workflows for macOS and linux are completely different, so there's not really something to re-use. And the macOS ecosystem is simpler. Basically we already have the static libraries in the linux build process because they're necessary for linking the compiler. |
Thanks for the explanation. This makes sense.
I am not an expert, but I believe the answer is yes. libevent.a and libpcre.a are as essential as libgc.a to crystal. Lacking the two libraries make the linux binary package non-functional. |
To provide insight: The historical reason the packages have included One reason I have been reluctant to support packaging I understand that in data science, untrusted inputs aren't as much of a problem, and I do want to work to find a solution, but we have to be careful not to degrade security of those using the linux tarball to compile other types of applications. |
IIRC the only reason we distribute |
A good solution might be to provide two different packages. A minimal one with bare minimum of libraries ( |
On CentOS,
This sounds good to me. |
I think two packages is the best solution, as long as they're documented and have the necessary warnings |
Just hit this recently because I was trying to get Crystal to work on Compiler Explorer. PCRE reached end-of-life about a week ago, so if we distribute Crystal with PCRE 8.45 then it is always "up-to-date". Obviously it's a different story if we migrate to PCRE2 though. If we build PCRE ourselves we also always get JIT support (#3852) regardless of the system library version. |
development doesn't mean no security bugfixes i think. it is a positive though. |
The
|
As the documentations says
For that purpose, the documentation recommends using
As an example replace the local build:
with
Since you are cross-compiling from a docker container, it would be wiser to ensure to provide the correct cross compilation flags. Find your platform with So change from
to
Finally, check your binary is fully static:
|
@noraj Pretty sure this issue was related to using Crystal itself and not statically building some library/application. I.e. the case where you're installing Crystal via https://crystal-lang.org/install/from_targz/ and are unable to use a package manager or the ability to build the necessary libs from source. |
@Blacksmoke16 doesn't seem like it... what makes you think that? |
@Sija Because the OP mentions |
@Blacksmoke16 Ah, it seems I misread the last comments. Somehow I thought they're referring to the documentation and not OP's issue, thank you for correcting me 🙏 |
@Blacksmoke16 Hum 🤔 because I encountered the same issue as the author only when statically building (libevent and libpcre) while I had no issue when dynamically building and at runtime (with crystal both from archlinux system and asdf). Those libraries are also missing from archlinux and even when you are root and have |
@noraj Right, this issue is NOT related to building your application statically, but instead using Crystal itself from the pre-built Crystal binaries provided via the In your case, you probably installed Crystal via your package manager which installed all the runtime deps, such as pcre, along with Crystal itself. This explains why you are able to run your applications just fine. However, your comment is correct when you want to go and build a static binary for something you wrote when Crystal is already installed. |
I said that I tried with ASDF as well (https://crystal-lang.org/install/from_asdf/) which which is on a user local level too. This is because asdf-crystal doesn't use the bundled tarball. |
Okay, but is the issue that when you do like I'm not so sure ASDF can use the bundled tarball since the pre-built static libs included in it would prob only work on linux? EDIT: If you're running into an issue, the forums or one of that chat rooms might be a good place to get help. |
In my case
It's possible to make an
I don't need help, I found the solution with the Alpine docker container, since Crystal supports static build only on Alpine. But as it's not trivial to find the answer in the official document on the exact way to do it I thought it would be nice from me to share the solution. Update: But yeah I understand the original issue is a bit different and it's maybe not the perfect place to share this solution but it's not off topic either as it has the same cause and the docker solution could be helpful for user local level too. |
Okay yea, that's a separate issue than what this issue is about and is somewhat expected as, as you already pointed out, Alpine docker container is the easiest way to create a static binary of an application. EDIT: Worth pointing out, it's not only supported on Alpine linux. It just so happens to be the easiest. My understanding is you can do it on any* system where you have access to that static *At least for Linux static builds as I know Mac is a bit diff/not supported at all.
https://crystal-lang.org/reference/1.7/guides/static_linking.html spells this all out quite well. If there's something there that you found missing or confusing, opening an issue on the book's repo https://github.com/crystal-lang/crystal-book would be more helpful. |
It seems that the crystal compiler requires libevent and pcre. If either library is absent, the linker will throw an error like
Unfortunately, libevent and pcre are often missing from a system and installing/compiling them without root/sudo is non-trivial for inexperienced users.
A simple solution to this problem is to compile the two libraries as static
libevent.a
andlibpcre.a
on older Linux and put them incrystal-0.34-1/lib/crystal/lib
along withlibgc.a
. This way, we can compile without system libevent and pcre. Furthermore, the resulting binary is not dynamically linked to libevent.so or libpcre.so – it is more portable.PCRE and libevent don't have additional dependencies. They can be easily compiled as static libraries with
./configure --disable-shared
. On my system, the compiled libraries can be found in.libs/lib{event,pcre}.a
. I have tried this approach. It is working well for me.The text was updated successfully, but these errors were encountered: