TaKO8Ki / frum

A little bit fast and modern Ruby version manager written in Rust
MIT License
628 stars 15 forks source link

frum fails on new Macbook Air M2; tried all solutions #121

Open blakeperdue opened 1 year ago

blakeperdue commented 1 year ago

I've googled this issue for hours now and give up. I've tried all the solutions I could find online yet I am unable to use frum to install any Ruby versions. A log is below.

My setup: Macbook Air M2 frum v0.1.2

> arch -arm64 frum install 2.7.5
==> Downloading https://cache.ruby-lang.org/pub/ruby/2.7/ruby-2.7.5.tar.xz
==> Extracting ruby-2.7.5.tar.xz
        ==> Building Ruby 2.7.5
error: Can't build Ruby: make failed: . ./vm_opts.h
In file included from cont.c:16:
./mjit.h:131:17: warning: cast to smaller integer type 'enum rb_mjit_iseq_func' from 'mjit_func_t' (aka 'unsigned long (*)(struct rb_execution_context_struct *, struct rb_control_frame_struct *)') [-Wpointer-to-enum-cast]
        switch ((enum rb_mjit_iseq_func)func) {
                ^~~~~~~~~~~~~~~~~~~~~~~~~~~~
1 warning generated.
In file included from eval.c:20:
./mjit.h:131:17: warning: cast to smaller integer type 'enum rb_mjit_iseq_func' from 'mjit_func_t' (aka 'unsigned long (*)(struct rb_execution_context_struct *, struct rb_control_frame_struct *)') [-Wpointer-to-enum-cast]
        switch ((enum rb_mjit_iseq_func)func) {
                ^~~~~~~~~~~~~~~~~~~~~~~~~~~~
In file included from gc.c:41:
./mjit.h:131:17: warning: cast to smaller integer type 'enum rb_mjit_iseq_func' from 'mjit_func_t' (aka 'unsigned long (*)(struct rb_execution_context_struct *, struct rb_control_frame_struct *)') [-Wpointer-to-enum-cast]
        switch ((enum rb_mjit_iseq_func)func) {
                ^~~~~~~~~~~~~~~~~~~~~~~~~~~~
1 warning generated.
In file included from iseq.c:30:
./mjit.h:131:17: warning: cast to smaller integer type 'enum rb_mjit_iseq_func' from 'mjit_func_t' (aka 'unsigned long (*)(struct rb_execution_context_struct *, struct rb_control_frame_struct *)') [-Wpointer-to-enum-cast]
        switch ((enum rb_mjit_iseq_func)func) {
                ^~~~~~~~~~~~~~~~~~~~~~~~~~~~
In file included from mjit_compile.c:19:
./mjit.h:131:17: warning: cast to smaller integer type 'enum rb_mjit_iseq_func' from 'mjit_func_t' (aka 'unsigned long (*)(struct rb_execution_context_struct *, struct rb_control_frame_struct *)') [-Wpointer-to-enum-cast]
        switch ((enum rb_mjit_iseq_func)func) {
                ^~~~~~~~~~~~~~~~~~~~~~~~~~~~
1 warning generated.
1 warning generated.
1 warning generated.
In file included from ruby.c:55:
./mjit.h:131:17: warning: cast to smaller integer type 'enum rb_mjit_iseq_func' from 'mjit_func_t' (aka 'unsigned long (*)(struct rb_execution_context_struct *, struct rb_control_frame_struct *)') [-Wpointer-to-enum-cast]
        switch ((enum rb_mjit_iseq_func)func) {
                ^~~~~~~~~~~~~~~~~~~~~~~~~~~~
1 warning generated.
In file included from thread.c:77:
./mjit.h:131:17: warning: cast to smaller integer type 'enum rb_mjit_iseq_func' from 'mjit_func_t' (aka 'unsigned long (*)(struct rb_execution_context_struct *, struct rb_control_frame_struct *)') [-Wpointer-to-enum-cast]
        switch ((enum rb_mjit_iseq_func)func) {
                ^~~~~~~~~~~~~~~~~~~~~~~~~~~~
In file included from vm.c:341:
./mjit.h:131:17: warning: cast to smaller integer type 'enum rb_mjit_iseq_func' from 'mjit_func_t' (aka 'unsigned long (*)(struct rb_execution_context_struct *, struct rb_control_frame_struct *)') [-Wpointer-to-enum-cast]
        switch ((enum rb_mjit_iseq_func)func) {
                ^~~~~~~~~~~~~~~~~~~~~~~~~~~~
In file included from vm.c:350:
./vm_method.c:291:32: warning: cast to smaller integer type 'enum method_optimized_type' from 'void *' [-Wvoid-pointer-to-enum-cast]
            def->body.optimize_type = (enum method_optimized_type)opts;
                                      ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
In file included from vm_trace.c:28:
./mjit.h:131:17: warning: cast to smaller integer type 'enum rb_mjit_iseq_func' from 'mjit_func_t' (aka 'unsigned long (*)(struct rb_execution_context_struct *, struct rb_control_frame_struct *)') [-Wpointer-to-enum-cast]
        switch ((enum rb_mjit_iseq_func)func) {
                ^~~~~~~~~~~~~~~~~~~~~~~~~~~~
1 warning generated.
1 warning generated.
array.c:290:17: warning: expression result unused [-Wunused-value]
                RB_OBJ_WRITE(buff_owner_ary, &ptr[i+beg], argv[i]);
                ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
./internal.h:2711:34: note: expanded from macro 'RB_OBJ_WRITE'
#define RB_OBJ_WRITE(a, slot, b) UNALIGNED_MEMBER_ACCESS(rb_obj_write((VALUE)(a), (VALUE *)(slot), (VALUE)(b), __FILE__, __LINE__))
                                 ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
./internal.h:2703:5: note: expanded from macro 'UNALIGNED_MEMBER_ACCESS'
    unaligned_member_access_result; \
    ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
./include/ruby/ruby.h:1087:5: note: expanded from macro 'RARRAY_PTR_USE_TRANSIENT'
    expr; \
    ^~~~
In file included from mjit.c:18:
In file included from ./mjit_worker.c:76:
./mjit.h:131:17: warning: cast to smaller integer type 'enum rb_mjit_iseq_func' from 'mjit_func_t' (aka 'unsigned long (*)(struct rb_execution_context_struct *, struct rb_control_frame_struct *)') [-Wpointer-to-enum-cast]
        switch ((enum rb_mjit_iseq_func)func) {
                ^~~~~~~~~~~~~~~~~~~~~~~~~~~~
array.c:1200:2: warning: expression result unused [-Wunused-value]
        RB_OBJ_WRITE(target_ary, &ptr[idx], item);
        ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
./internal.h:2711:34: note: expanded from macro 'RB_OBJ_WRITE'
#define RB_OBJ_WRITE(a, slot, b) UNALIGNED_MEMBER_ACCESS(rb_obj_write((VALUE)(a), (VALUE *)(slot), (VALUE)(b), __FILE__, __LINE__))
                                 ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
./internal.h:2703:5: note: expanded from macro 'UNALIGNED_MEMBER_ACCESS'
    unaligned_member_access_result; \
    ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
./include/ruby/ruby.h:1087:5: note: expanded from macro 'RARRAY_PTR_USE_TRANSIENT'
    expr; \
    ^~~~
1 warning generated.
In file included from version.c:15:
./mjit.h:131:17: warning: cast to smaller integer type 'enum rb_mjit_iseq_func' from 'mjit_func_t' (aka 'unsigned long (*)(struct rb_execution_context_struct *, struct rb_control_frame_struct *)') [-Wpointer-to-enum-cast]
        switch ((enum rb_mjit_iseq_func)func) {
                ^~~~~~~~~~~~~~~~~~~~~~~~~~~~
1 warning generated.
2 warnings generated.
2 warnings generated.
ln -sf ../../../.ext/include/arm64-darwin21/rb_mjit_min_header-2.7.5.h include/ruby-2.7.0/arm64-darwin21/rb_mjit_min_header-2.7.5.h
Undefined symbols for architecture arm64:
  "_rb_enc_set_base", referenced from:
      _Init_encdb in encdb.o
  "_rb_enc_set_dummy", referenced from:
      _Init_encdb in encdb.o
  "_rb_encdb_alias", referenced from:
      _Init_encdb in encdb.o
  "_rb_encdb_declare", referenced from:
      _Init_encdb in encdb.o
  "_rb_encdb_dummy", referenced from:
      _Init_encdb in encdb.o
  "_rb_encdb_replicate", referenced from:
      _Init_encdb in encdb.o
  "_rb_encdb_set_unicode", referenced from:
      _Init_encdb in encdb.o
ld: symbol(s) not found for architecture arm64
clang: error: linker command failed with exit code 1 (use -v to see invocation)
make[1]: *** [.ext/arm64-darwin21/enc/encdb.bundle] Error 1
make: *** [enc] Error 2
make: *** Waiting for unfinished jobs....
Undefined symbols for architecture arm64:
  "_rb_declare_transcoder", referenced from:
      _Init_transdb in transdb.o
ld: symbol(s) not found for architecture arm64
clang: error: linker command failed with exit code 1 (use -v to see invocation)
make[1]: *** [.ext/arm64-darwin21/enc/trans/transdb.bundle] Error 1
make[1]: *** Waiting for unfinished jobs....
Undefined symbols for architecture arm64:
  "_rb_register_transcoder", referenced from:
      _Init_big5 in big5.o
ld: symbol(s) not found for architecture arm64
clang: error: linker command failed with exit code 1 (use -v to see invocation)
make[1]: *** [.ext/arm64-darwin21/enc/trans/big5.bundle] Error 1
Undefined symbols for architecture arm64:
  "_rb_register_transcoder", referenced from:
      _Init_cesu_8 in cesu_8.o
ld: symbol(s) not found for architecture arm64
clang: error: linker command failed with exit code 1 (use -v to see invocation)
make[1]: *** [.ext/arm64-darwin21/enc/trans/cesu_8.bundle] Error 1
make: *** [trans] Error 2
libffi_version: 3.4.0
eddieantonio commented 1 year ago

I was also having difficulty building Ruby. I'm using:

frum version 0.1.2 macOS Monterey 12.6 (M1 Macbook/Apple Silicon)

My errors output similar to this:

Undefined symbols for architecture arm64:
  "_rb_enc_set_base", referenced from:
      _Init_encdb in encdb.o
  "_rb_enc_set_dummy", referenced from:
      _Init_encdb in encdb.o
  "_rb_encdb_alias", referenced from:
      _Init_encdb in encdb.o
  "_rb_encdb_declare", referenced from:
      _Init_encdb in encdb.o
  "_rb_encdb_dummy", referenced from:
      _Init_encdb in encdb.o
  "_rb_encdb_replicate", referenced from:
      _Init_encdb in encdb.o
  "_rb_encdb_set_unicode", referenced from:
      _Init_encdb in encdb.o
ld: symbol(s) not found for architecture arm64

I solved this for myself by looking at Homebrew's ./configure options for Ruby:

https://github.com/Homebrew/homebrew-core/blob/db82d67243e0a9829335e08ba12274f5dce62dea/Formula/ruby.rb#L67-L81

And I used this command:

frum install 3.1.2 --enable-shared --disable-silent-rules --without-gmp

And it worked! 🎉

I wish I understood why that works -- given there's linker errors, I think --enable-shared might be doing the trick ¯\_(ツ)_/¯

Christophorus3 commented 1 year ago

Thanks a lot! I had the same issue, tried your solution and it worked! 🙌

gilsoncav commented 1 year ago

Same here. it worked! Many thanks @eddieantonio 😀

monfresh commented 1 year ago

@eddieantonio and others who might wonder why --enable-shared is required, it's due to an incompatibility between version 14.x of Apple's command line tools and Ruby. Ruby fixed the issue in 3.1.3 and 2.7.7, but they haven't been released yet. Once they are released, the --enable-shared flag would not be needed anymore. I've written about this in detail here:

https://www.rubyonmac.dev/how-to-install-ruby-on-macos-12-6-apple-silicon

As for the other flags from Homebrew, --disable-silent-rules doesn't do anything because it's not recognized by Ruby. And although --without-gmp is a Ruby configuration option, it won't make a difference.

eddieantonio commented 1 year ago

@monfresh Thanks! That's a write-up!