Skip to content
This repository has been archived by the owner on Dec 4, 2023. It is now read-only.

Binary builds for darwin20 / macOS 11.0 Big Sur #305

Closed
lloeki opened this issue Aug 24, 2020 · 16 comments
Closed

Binary builds for darwin20 / macOS 11.0 Big Sur #305

lloeki opened this issue Aug 24, 2020 · 16 comments

Comments

@lloeki
Copy link
Contributor

lloeki commented Aug 24, 2020

There is no binary gem published (yet) for 7.3.492.27.1 and 8.4.255.0. I failed to produce one (again because of depot tools acting up).

Not to be outdone, I produced this terrible hack to work around it.

Use as follows:

./gem-install-libv8-darwin-20.sh 7.3.492.27.1
./gem-install-libv8-darwin-20.sh 8.4.255.0
./gem-install-libv8-darwin-20.sh        # defaults to 8.4.255.0
#!/bin/bash
# filename: gem-install-libv8-darwin-20.sh

set -e
set -u
set -o pipefail

libv8_version="${1:-"8.4.255.0"}"
from='19'
to='20'

gem_home="$(ruby -e 'puts Gem.dir')"
ruby_platform="$(ruby -e 'puts Gem.platforms.select { |p| Gem::Platform === p && p.os =~ /darwin/ }')"
ruby_platform_prefix="${ruby_platform%-*}"

# case "${ruby_platform}" in
#     *universal*)
#         ruby_platform_prefix="x86_64-darwin"
#         ;;
# esac

ruby_platform_from="${ruby_platform_prefix}-${from}"
ruby_platform_to="${ruby_platform_prefix}-${to}"

echo " *** detecting"

echo "${gem_home}"
echo "${ruby_platform}"
echo "${ruby_platform_prefix}"

echo "libv8 ${libv8_version}: ${ruby_platform_from} => ${ruby_platform_to}"

echo " *** downloading"

test -f "/tmp/libv8-${libv8_version}-${ruby_platform_from}.gem" \
    || curl --fail --output "/tmp/libv8-${libv8_version}-${ruby_platform_from}.gem" "https://rubygems.org/downloads/libv8-${libv8_version}-${ruby_platform_from}.gem" \
    || curl --fail --output "/tmp/libv8-${libv8_version}-${ruby_platform_from}.gem" "https://rubygems.org/downloads/libv8-${libv8_version}-${ruby_platform_prefix}${from}.gem"

echo " *** cleaning"

rm -rfv "${gem_home}/specifications/libv8-${libv8_version}-"{"${ruby_platform_from}","${ruby_platform_to}"}".gemspec"
rm -rfv "${gem_home}/doc/libv8-${libv8_version}-"{"${ruby_platform_from}","${ruby_platform_to}"}
rm -rfv "${gem_home}/gems/libv8-${libv8_version}-"{"${ruby_platform_from}","${ruby_platform_to}"}
rm -rfv "${gem_home}/cache/libv8-${libv8_version}-"{"${ruby_platform_from}","${ruby_platform_to}"}".gem"

echo " *** installing"

gem install "/tmp/libv8-${libv8_version}-${ruby_platform_from}.gem"

echo " *** patching"

mv -v "${gem_home}/specifications/libv8-${libv8_version}-"{"${ruby_platform_from}","${ruby_platform_to}"}".gemspec"
mv -v "${gem_home}/doc/libv8-${libv8_version}-"{"${ruby_platform_from}","${ruby_platform_to}"}
mv -v "${gem_home}/gems/libv8-${libv8_version}-"{"${ruby_platform_from}","${ruby_platform_to}"}
mv -v "${gem_home}/cache/libv8-${libv8_version}-"{"${ruby_platform_from}","${ruby_platform_to}"}".gem"

sed -i~ \
    -e "s/${ruby_platform_prefix}-${from}/${ruby_platform_to}/" \
    -e "s/${ruby_platform_prefix}${from}/${ruby_platform_to}/" \
    "${gem_home}/specifications/libv8-${libv8_version}-${ruby_platform_to}.gemspec"
rm "${gem_home}/specifications/libv8-${libv8_version}-${ruby_platform_to}.gemspec~"

echo " *** result"

find "${gem_home}"/*/"libv8-${libv8_version}-${ruby_platform_to}"
grep --text "${ruby_platform_to}" "${gem_home}/specifications/libv8-${libv8_version}-${ruby_platform_to}.gemspec"
@dlackty
Copy link

dlackty commented Sep 23, 2020

Confirmed this works on my laptop. Thank you!

@lloeki
Copy link
Contributor Author

lloeki commented Sep 24, 2020

This is a gross hack though, and I have encountered a couple of segfaults (still not sure why, just don’t expect this to be 100% stable) but at least it allows the ball to continue rolling.

@arianf
Copy link

arianf commented Sep 26, 2020

How has this not been fixed yet

@SamSaffron
Copy link
Contributor

will the node based builds work? also ... there is the giant arm question.

@lloeki
Copy link
Contributor Author

lloeki commented Nov 17, 2020

I pushed libv8-node darwin20 builds just yesterday. GitHub Actions secretly has a macos-11.0 CI target but it silently fell back to macos-10.15 last time I checked, so I built it locally.

https://rubygems.org/gems/libv8-node/versions/14.14.0.0.beta2-x86_64-darwin-20

Tested and working against sq_mini_racer 0.3.1.

As you can see in the artifacts, it's V8 8.4.371.19. In the future both the gems and intermediate V8 artifact static libs + headers will be available in each run's artifacts:

https://github.com/sqreen/ruby-libv8-node/actions/runs/349889868

I'm going to add arm7hf-linux and aarch64-linux at some point, it should be fairly easy with either docker buildx or manual qemu+binfmt trickery I did before. As for aarch64-darwin-20, well, I'll need some hardware (maybe I can figure out how to cross-compile but in any case I would be unsure how to test).

@ldanielw1
Copy link

Does this mean that gem install libv8 may be fixed soon on Big Sur machines, then? is there potential for an ETA on this issue?

@SamSaffron
Copy link
Contributor

@lloeki let me know what gems I should push to rubygems once you have this ready.

@lloeki
Copy link
Contributor Author

lloeki commented Nov 20, 2020

@SamSaffron You would not be able to push the libv8-node gems as is, as they're not a drop-in replacement: I wanted these to be usable in parallel of this libv8 gem, so I namespaced it as Libv8::Node. Although very close, I consider it a bit too early yet to make the switch.

But what you can do right away is take the current libv8 8.4.255.0 darwin19 gem and transform it into a darwin20 gem (basically what the above hack does) by replacing all references from one into the other, including the paths and serialised gemspec. This works because Big Sur is binary backwards compatible with Catalina.

FYI the segfaults I encountered were -entirely- unrelated to the hack.

@lloeki
Copy link
Contributor Author

lloeki commented Nov 20, 2020

Ok, someone try these 8.4.255.0 (universal is for macOS-provided Ruby, x86_64 is for the others people usually install themselves):

https://www.dropbox.com/s/8qt3o6bvx0npst0/libv8-8.4.255.0-universal-darwin-20.gem?dl=0
https://www.dropbox.com/s/wuwuqhaqcate8k5/libv8-8.4.255.0-x86_64-darwin-20.gem?dl=0

I did it by skipping the :compile dependency of rake binary (ran on darwin20), but copying the outputs of it - which are .location.yml and vendor/v8 - from the darwin19 gem.

@pmusaraj
Copy link

Is the libv8-8.4.255.0-universal-darwin-20.gem binary supposed to work both with and without Rosetta? I tried it using mini_racer, and it worked when Terminal runs with Rosetta, but it fails without it.

Without Rosetta, it gives this error:

dlopen(/Library/Ruby/Gems/2.6.0/gems/mini_racer-0.3.1/lib/mini_racer_extension.bundle, 0x0009): 
missing compatible arch in /Library/Ruby/Gems/2.6.0/gems/mini_racer-0.3.1/lib/mini_racer_extension.bundle - /Library/Ruby/Gems/2.6.0/gems/mini_racer-0.3.1/lib/mini_racer_extension.bundle (LoadError)

(Tried this on the macOS-provided Ruby.)

@lloeki
Copy link
Contributor Author

lloeki commented Nov 21, 2020

No, it's Intel only, so that's expected. I suppose it could work with Rosetta but I'm unable to test that, lacking the hardware.

@pmusaraj
Copy link

Thanks, it does work via Rosetta.

@causztic
Copy link

@SamSaffron
Copy link
Contributor

SamSaffron commented Nov 25, 2020

Gems are now pushed to rubygems! Thanks @lloeki

@lloeki
Copy link
Contributor Author

lloeki commented Nov 27, 2020

Closing this one. I will tracking Apple M1 specific progress over here: #309

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

No branches or pull requests

7 participants