ruby / prism

Prism Ruby parser
https://ruby.github.io/prism/
MIT License
790 stars 134 forks source link

Installation in devcontainer fails on Apple Silicon #2868

Open unikitty37 opened 1 month ago

unikitty37 commented 1 month ago

I cannot install the gem in a VSCode devcontainer running on an Apple M1 machine; it complains that some vital component is missing.

The README says I need a C99 compiler and GNU make, but there's not really much of a clue on how to set this up in devcontainers. Adding the llvm and make features doesn't help (and Ruby is already installed and working).

Would it be possible for the README to list the features that need to be installed for devcontainer users? (Even better: would it be possible to have pre-compiled binaries available for Apple Silicon, thus saving a lot of time when rebuilding the container? :)

devcontainer.json

{
  "name": "Ruby on Rails & Postgres",
  "dockerComposeFile": "docker-compose.yml",
  "service": "app",
  "workspaceFolder": "/workspaces/${localWorkspaceFolderBasename}",

  "features": {
    "ghcr.io/itsmechlark/features/redis-server:1": {},
    "ghcr.io/jungaretti/features/make:1": {},
    "ghcr.io/devcontainers-community/features/llvm:3": {}
  },

  "forwardPorts": [],

  "postCreateCommand": "bundle install && rake db:setup",

  "remoteUser": "vscode"
}

Output log

Gem::Ext::BuildError: ERROR: Failed to build gem native extension.

    current directory: /usr/local/rvm/gems/default/gems/prism-0.29.0/ext/prism
/usr/local/bin/ruby extconf.rb
checking for prism.h in /usr/local/rvm/gems/default/gems/prism-0.29.0/include...
yes
checking for prism/extension.h in
/usr/local/rvm/gems/default/gems/prism-0.29.0/ext... yes
checking for whether -fvisibility=hidden is accepted as CFLAGS... yes
Running make build/libprism.a with {"SOEXT"=>"so", "MAKEDIRS"=>"/bin/mkdir -p",
"RMALL"=>"rm -fr"}
compiling build/static/diagnostic.o
compiling build/static/encoding.o
compiling build/static/node.o
compiling build/static/options.o
compiling build/static/pack.o
compiling build/static/prettyprint.o
compiling build/static/prism.o
Assembler messages:
Fatal error: can't create build/static/prism.o: No such file or directory
make: *** [Makefile:58: build/static/prism.o] Error 1
*** extconf.rb failed ***
Could not create Makefile due to some reason, probably lack of necessary
libraries and/or headers.  Check the mkmf.log file for more details.  You may
need configuration options.

Provided configuration options:
        --with-opt-dir
        --without-opt-dir
        --with-opt-include=${opt-dir}/include
        --without-opt-include
        --with-opt-lib=${opt-dir}/lib
        --without-opt-lib
        --with-make-prog
        --without-make-prog
        --srcdir=.
        --curdir
        --ruby=/usr/local/bin/$(RUBY_BASE_NAME)
        --enable-build-debug
        --disable-build-debug
        --enable-build-minimal
        --disable-build-minimal
extconf.rb:51:in `system': Command failed with exit 2: make (RuntimeError)
        from extconf.rb:51:in `block in make'
        from extconf.rb:50:in `chdir'
        from extconf.rb:50:in `make'
        from extconf.rb:136:in `<main>'

To see why this extension failed to compile, please check the mkmf.log which can
be found here:

/usr/local/rvm/gems/default/extensions/aarch64-linux/3.3.0/prism-0.29.0/mkmf.log

extconf failed, exit code 1

Gem files will remain installed in /usr/local/rvm/gems/default/gems/prism-0.29.0
for inspection.
Results logged to
/usr/local/rvm/gems/default/extensions/aarch64-linux/3.3.0/prism-0.29.0/gem_make.out

  /usr/local/lib/ruby/3.3.0/rubygems/ext/builder.rb:125:in `run'
  /usr/local/lib/ruby/3.3.0/rubygems/ext/ext_conf_builder.rb:28:in `build'
  /usr/local/lib/ruby/3.3.0/rubygems/ext/builder.rb:193:in `build_extension'
/usr/local/lib/ruby/3.3.0/rubygems/ext/builder.rb:227:in `block in
build_extensions'
  /usr/local/lib/ruby/3.3.0/rubygems/ext/builder.rb:224:in `each'
  /usr/local/lib/ruby/3.3.0/rubygems/ext/builder.rb:224:in `build_extensions'
  /usr/local/lib/ruby/3.3.0/rubygems/installer.rb:852:in `build_extensions'
/usr/local/lib/ruby/3.3.0/bundler/rubygems_gem_installer.rb:76:in
`build_extensions'
  /usr/local/lib/ruby/3.3.0/bundler/rubygems_gem_installer.rb:28:in `install'
  /usr/local/lib/ruby/3.3.0/bundler/source/rubygems.rb:205:in `install'
  /usr/local/lib/ruby/3.3.0/bundler/installer/gem_installer.rb:54:in `install'
/usr/local/lib/ruby/3.3.0/bundler/installer/gem_installer.rb:16:in
`install_from_spec'
/usr/local/lib/ruby/3.3.0/bundler/installer/parallel_installer.rb:132:in
`do_install'
/usr/local/lib/ruby/3.3.0/bundler/installer/parallel_installer.rb:123:in
`block in worker_pool'
  /usr/local/lib/ruby/3.3.0/bundler/worker.rb:62:in `apply_func'
  /usr/local/lib/ruby/3.3.0/bundler/worker.rb:57:in `block in process_queue'
  <internal:kernel>:187:in `loop'
  /usr/local/lib/ruby/3.3.0/bundler/worker.rb:54:in `process_queue'
/usr/local/lib/ruby/3.3.0/bundler/worker.rb:90:in `block (2 levels) in
create_threads'

An error occurred while installing prism (0.29.0), and Bundler cannot
continue.

In Gemfile:
  ruby-lsp-rails was resolved to 0.3.7, which depends on
    ruby-lsp was resolved to 0.17.1, which depends on
      prism
[22385 ms] postCreateCommand failed with exit code 5. Skipping any further user-provided commands.
kddnewton commented 1 month ago

Hey @unikitty37 — I think this might be an issue where prism it being installed twice at the same time. It's being installed once with bundle and then another time while ruby-lsp is installing it. This is creating a conflict in the gem installation directory. We'll look into some solutions here.

kddnewton commented 2 weeks ago

I opened an issue for this upstream in rubygems (https://github.com/rubygems/rubygems/issues/7786). In the meantime I'll see if there's a way we can look at handling this in prism specifically.