ruby-install
ruby-install copied to clipboard
Detect when --with-jemalloc is specified and install jemalloc
Detect when --with-jemalloc
is given as an additional configuration option (ex: ruby-install ruby 2.6 -- --with-jemalloc
), and automatically append the appropriate jemalloc package name (based on the $package_manager
) to list of package dependencies.
This would be very useful, even more so on newer Homebrew installs which no longer reside in /usr/local
but in /opt/homebrew
and therefore requires quite a bit more yada yada:
# Homebrew in /usr/local
ruby-install -s ~/.rubies_src ruby 3 -- --with-jemalloc
# Homebrew in /opt/homebrew
ruby-install -s ~/.rubies_src ruby 3 -- --with-jemalloc CPPFLAGS="-I$HOMEBREW_PREFIX/opt/jemalloc/include" LDFLAGS="-L$HOMEBREW_PREFIX/opt/jemalloc/lib"
This would be extremely helpful. I almost gave up trying to install ruby 2.7 with jemalloc support before stumbling upon this issue with detailed guide on what needs to be set in the command line to install it properly (thanks @svoop!).
I recently stumbled over this same issue with Ruby 3.2.0 on Ubuntu 22.04 (jammy) in a docker container.
Very similar fix to what @svoop mentioned, just obviously slightly changed for Ubuntu:
LDFLAGS="-Wl,--no-as-needed" CPPFLAGS="-I/usr/include/jemalloc" ruby-install --system ruby 3.2.0
If I didn't pass in the both LDFLAGS and CPPFLAGS, enabling jemalloc with the LD_PRELOAD
environment variable would segfault every single time. Effectively I couldn't use jemalloc at all. See https://bugs.ruby-lang.org/issues/18409 for a similar bug report.
I think this is the best read to highlight what's actually going on: https://github.com/grpc/grpc/issues/25450#issuecomment-910806034
I'm not well-versed in the general chain/Ruby compilation/OS-library-picking workflow, just figured I'd note that it's both still a problem in 3.2.0 and very unintuitive to fix.
Is this something ruby-install should fix? Honestly, no idea, but hopefully other lost souls will be able to look at all these links and understand why jemalloc isn't working with the flag.
Here's a 'slim' version of my Dockerfile:
FROM ubuntu:jammy
RUN apt-get -y clean && apt-get update
RUN apt-get install -y --no-install-recommends apt-utils build-essential bzip2 coreutils curl git gzip libc-dev tar xz-utils \
autoconf bison patch build-essential rustc libssl-dev libyaml-dev libreadline6-dev zlib1g-dev libgmp-dev libncurses5-dev libffi-dev libgdbm6 libgdbm-dev libdb-dev uuid-dev libjemalloc-dev
ENV MAKE_OPTS="-j 4"
ENV RUBY_CFLAGS="-O3"
ENV RUBY_CONFIGURE_OPTS="--enable-yjit --disable-install-doc --with-jemalloc"
RUN curl -s -L https://github.com/postmodern/ruby-install/archive/v0.8.5.tar.gz --output ./ruby-install-0.8.5.tar.gz
RUN tar -xzvf ./ruby-install-0.8.5.tar.gz
RUN cd ruby-install-0.8.5 && make install
RUN LDFLAGS="-Wl,--no-as-needed" CPPFLAGS="-I/usr/include/jemalloc" ruby-install --system ruby 3.2.0
RUN rm -rf ./ruby-install*
RUN apt-get -y autoremove && apt-get -y clean
How would people feel about an explicit --enable jemalloc
or --feature jemalloc
option?
ruby-install --enable jemalloc ruby
ruby-install --feature jemalloc ruby
Or do people prefer that ruby-install
auto-detect when you specify --with-jemalloc
as an additional configuration option?
ruby-install ruby -- --with-jemalloc
@postmodern I'd prefer the latter I guess: There might be other features in the future which require dependencies as well, the same detection could be used then without the need to touch the ruby-install CLI.
@postmodern I think I disagree with @svoop here, as long as --feature jemalloc
is well documented in the README (or where ever you want to put documentation). I don't like shadowing build flags, so --with-jemalloc
feels like it should be left alone.
I'm also scratching my head even more since all of the Ruby patches and comments seem to indicate this should be fixed in 3.1+.. like I mentioned above, I'm not even sure if this is a ruby-install
issue or if this is a fundamental Ruby compilation problem.
Let me know if you need any of my build logs to look at configuration options, linker args, etc @postmodern
January is Ruby upping month, so I revisit this issue. With some time gone by, I now second @nscott, --feature jemalloc
would be a great extension to ruby-install
. Happy new year! :wink:
For the Mac users who are impatient and want to be able to use this feature today, I built a paid product called Ruby on Mac that does this for you. You would run it like this:
rom install ruby 3.1.4 --with-jemalloc
What's neat about Ruby on Mac, the Ultimate version specifically, is that it supports all the popular version managers, and you can easily switch from one to another. For example: rom config set manager chruby
. It also supports Ruby versions as old as 1.9.3.
Happy New Year!
@monfresh you don't seem to be previously involved in this conversation. Please refrain from using ruby-install issues to advertise Ruby on Mac, as this isn't the appropriate place for advertising. Thanks.
Sorry about that! It won't happen again.
I presume this is about compiling jemalloc into Ruby rather than using it at runtime via an LD_PRELOAD flag?
If so, I have no opinion on how to tell ruby-install "yes please, I would like jemalloc". But it would be great to have!