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

Feature Request: Ability/Docs to Build for Target Locations Inaccessible to the Builder #2241

Closed
sempervictus opened this issue Aug 20, 2023 · 1 comment · Fixed by #2296
Closed

Comments

@sempervictus
Copy link

Attempting to use ruby-build as an alternative to the terminal Arch Linux Ruby packaging (2y out of date on a rolling distro); and denting my desk and my forehead pretty badly trying to get the options set up correctly. Targeting 3.2.2 - saw in a previous issue/PR relating to DESTDIR= that the Ruby version apparently matters here (at least 1.9/2.x behaved differently). There was a comment about replacing shebang strings in there, but there's ABI linkage as well and i'm a bit concerned that might get broken/left inconsistent if i start messing with paths post-process.

Arch PKGBUILDs generally build in a source tree and then install to a target subtree which is then compressed for decompression (installation) under /. Building Ruby using the package path target results in the full path of the build environment's package path target being written to the resulting files and breaking when run after installation under / (vs /var/abs/packagename/pkg/packagename/). Trying to build with the various RUBY_* env vars set results in a failure to build the gems because that part already expects Ruby to be in the / prefix:

build() {
  #export RUBY_PREFIX_PATH="/usr/local"
  RUBY_BUILD_BUILD_PATH="${srcdir}/build" \
  RUBY_BUILD_CACHE_PATH="${srcdir}/cache" \
  RUBY_MAKE_INSTALL_OPTS="DESTDIR=${srcdir}/ruby-$_pkgver" \
  RUBY_PREFIX_PATH="${srcdir}/ruby-$_pkgver/usr" \
  ruby-build $_pkgver /usr
}

package() {
  mv ruby-$_pkgver/* "${pkgdir}/"
  chown -R root:root "${pkgdir}/usr"
}

produces the following when built in its own Arch chroot:

Inspect or clean up the working tree at /build/packagename/src/build
Results logged to /tmp/ruby-build.20230819230130.806.log

Last 10 log lines:
                                    net-imap 0.3.4
                                    net-pop 0.1.2
                                    net-smtp 0.3.3
                                    matrix 0.4.2
                                    prime 0.1.2
                                    rbs 2.8.2
                                    typeprof 0.21.3
                                    debug 1.7.1
installing bundled gem cache:       /build/packagename/src/ruby-3.2.2/usr/local/lib/ruby/gems/3.2.0/cache
/usr/bin/ruby-build: line 1230: /usr/local/bin/ruby: No such file or directory
==> ERROR: A failure occurred in build().
    Aborting...
==> Removing chroot copy [/var/abs/chroot/packagename]...done
==> ERROR: Build failed

What is the correct way to use ruby-build by unprivileged builder-users in CI's/containers/chroots/etc to create packages which are to be installed by privileged users on target systems (with the same ABI) later?

@mislav
Copy link
Member

mislav commented Oct 14, 2023

Hi, sorry for the late reply, and thanks for the detailed question.

What is the correct way to use ruby-build by unprivileged builder-users in CI's/containers/chroots/etc to create packages which are to be installed by privileged users on target systems (with the same ABI) later?

So far you were doing everything correctly, but I'm afraid that ruby-build isn't aware of potential DESTDIR use (especially because it was injected via environment variables), and a subsequent step to invoke the just-compiled ruby interpreter step fails because ruby-build wasn't aware that make install placed ruby in a different location. Duplicate of #1415 (comment)

Most build definitions look something like this:

install_package "openssl-3.1.3" "https://..." openssl --if needs_openssl_102_300
install_package "ruby-3.2.2" "https://..." ldflags_dirs enable_shared standard verify_openssl

Notice the verify_openssl step. This activates a function where ruby is invoked to verify that openssl and other native extensions were successfully linked:

build_package_verify_openssl() {

ruby-build looks for ruby in a wrong location because it couldn't know that DESTDIR was used.

RUBY_BIN="${PREFIX_PATH}/bin/ruby"

A workaround you could use is to copy the build definition of a Ruby version you want to use and manually edit it to remove the verify_openssl step: https://github.com/rbenv/ruby-build/blob/master/share/ruby-build/3.2.2

Then, invoke ruby-build and supply it with a path to your custom definition: ruby-build /path/to/custom-3.2.2 /prefix/path.

I'm open to making ruby-build DESTDIR-compatible, but so far there wasn't a straightforward approach. If you can suggest a better approach, contribution welcome!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants