mlua-rs / mlua

High level Lua 5.4/5.3/5.2/5.1 (including LuaJIT) and Roblox Luau bindings to Rust with async/await support
Other
1.69k stars 137 forks source link

Build/link fails on Termux (aarch64) #267

Closed alexmozaidze closed 1 year ago

alexmozaidze commented 1 year ago

I tried installing xplr file explorer, but it got stuck on building mlua. Here's the error:

error: failed to run custom build command for `mlua v0.8.8`

Caused by:
  process didn't exit successfully: `/data/data/com.termux/files/usr/tmp/cargo-installTqGaou/release/build/mlua-f1fd35dba130a52e/build-script-main` (exit status: 101)
  --- stdout
  cargo:rerun-if-env-changed=CC_aarch64-linux-android
  CC_aarch64-linux-android = None
  cargo:rerun-if-env-changed=CC_aarch64_linux_android
  CC_aarch64_linux_android = None
  cargo:rerun-if-env-changed=HOST_CC
  HOST_CC = None
  cargo:rerun-if-env-changed=CC
  CC = None
  cargo:rerun-if-env-changed=CFLAGS_aarch64-linux-android
  CFLAGS_aarch64-linux-android = None
  cargo:rerun-if-env-changed=CFLAGS_aarch64_linux_android
  CFLAGS_aarch64_linux_android = None
  cargo:rerun-if-env-changed=HOST_CFLAGS
  HOST_CFLAGS = None
  cargo:rerun-if-env-changed=CFLAGS
  CFLAGS = None
  cargo:rerun-if-env-changed=CRATE_CC_NO_DEFAULTS
  CRATE_CC_NO_DEFAULTS = None
  DEBUG = Some("false")
  CARGO_CFG_TARGET_FEATURE = Some("neon")
  running cd "/data/data/com.termux/files/usr/tmp/cargo-installTqGaou/release/build/mlua-e23a2e37ba73b142/out/luajit-build/build/src" && BUILDMODE="static" CROSS="aarch64-linux-android-" XCFLAGS="-fPIC" "make" "-e"
  CC        lj_init.o
  HOSTCC    host/minilua.o
  HOSTLINK  host/minilua
  DYNASM    host/buildvm_arch.h
  HOSTCC    host/buildvm.o
  HOSTCC    host/buildvm_asm.o
  HOSTCC    host/buildvm_peobj.o
  HOSTCC    host/buildvm_lib.o
  HOSTCC    host/buildvm_fold.o
  HOSTLINK  host/buildvm
  BUILDVM   lj_vm.S
  ASM       lj_vm.o
  CC        lj_assert.o
  CC        lj_gc.o
  BUILDVM   lj_ffdef.h
  CC        lj_err.o
  CC        lj_char.o
  BUILDVM   lj_bcdef.h
  CC        lj_bc.o
  CC        lj_obj.o
  CC        lj_buf.o
  CC        lj_str.o
  CC        lj_tab.o
  CC        lj_func.o
  CC        lj_udata.o
  CC        lj_meta.o
  CC        lj_debug.o
  CC        lj_prng.o
  CC        lj_state.o
  CC        lj_dispatch.o
  CC        lj_vmevent.o
  CC        lj_vmmath.o
  CC        lj_strscan.o
  CC        lj_strfmt.o
  CC        lj_strfmt_num.o
  CC        lj_serialize.o
  CC        lj_api.o
  CC        lj_profile.o
  CC        lj_lex.o
  CC        lj_parse.o
  CC        lj_bcread.o
  CC        lj_bcwrite.o
  CC        lj_load.o
  CC        lj_ir.o
  CC        lj_opt_mem.o
  BUILDVM   lj_folddef.h
  CC        lj_opt_fold.o
  CC        lj_opt_narrow.o
  CC        lj_opt_dce.o
  CC        lj_opt_loop.o
  CC        lj_opt_split.o
  CC        lj_opt_sink.o
  CC        lj_mcode.o
  CC        lj_snap.o
  CC        lj_record.o
  CC        lj_crecord.o
  BUILDVM   lj_recdef.h
  CC        lj_ffrecord.o
  CC        lj_asm.o
  CC        lj_trace.o
  CC        lj_gdbjit.o
  CC        lj_ctype.o
  CC        lj_cdata.o
  CC        lj_cconv.o
  CC        lj_ccall.o
  CC        lj_ccallback.o
  CC        lj_carith.o
  CC        lj_clib.o
  CC        lj_cparse.o
  CC        lj_lib.o
  CC        lj_alloc.o
  CC        lib_aux.o
  BUILDVM   lj_libdef.h
  CC        lib_base.o
  CC        lib_math.o
  CC        lib_bit.o
  CC        lib_string.o
  CC        lib_table.o
  CC        lib_io.o
  CC        lib_os.o
  CC        lib_package.o
  CC        lib_debug.o
  CC        lib_jit.o
  CC        lib_ffi.o
  CC        lib_buffer.o
  CC        lib_init.o
  CC        lj_str_hash.o
  AR        libluajit.a

  --- stderr
  make: *** [Makefile:731: libluajit.a] Error 127
  thread 'main' panicked at '
  Error building LuaJIT:
      Command: cd "/data/data/com.termux/files/usr/tmp/cargo-installTqGaou/release/build/mlua-e23a2e37ba73b142/out/luajit-build/build/src" && BUILDMODE="static" CROSS="aarch64-linux-android-" XCFLAGS="-fPIC" "make" "-e"
      Exit status: exit status: 2
      ', /data/data/com.termux/files/home/.cargo/registry/src/github.com-1ecc6299db9ec823/luajit-src-210.4.5+resty2cf5186/src/lib.rs:200:13
  note: run with `RUST_BACKTRACE=1` environment variable to display a backtrace
error: failed to compile `xplr v0.21.1`, intermediate artifacts can be found at `/data/data/com.termux/files/usr/tmp/cargo-installTqGaou`
khvzak commented 1 year ago

@sayanarijit @alexmozaidze

Could you try again (after running cargo update)? I published new luajit-src version.

PS Please make sure you have gcc/binutils/make installed

alexmozaidze commented 1 year ago

This time around, it errors while compiling mlua-sys:

error: failed to run custom build command for `mlua-sys v0.2.1`

Caused by:
  process didn't exit successfully: `/data/data/com.termux/files/home/projects/xplr/target/debug/build/mlua-sys-82f0cb4243bf512f/build-script-main` (exit status: 101)
  --- stdout
  cargo:rerun-if-env-changed=CC_aarch64-linux-android
  CC_aarch64-linux-android = None
  cargo:rerun-if-env-changed=CC_aarch64_linux_android
  CC_aarch64_linux_android = None
  cargo:rerun-if-env-changed=HOST_CC
  HOST_CC = None
  cargo:rerun-if-env-changed=CC
  CC = None
  cargo:rerun-if-env-changed=CFLAGS_aarch64-linux-android
  CFLAGS_aarch64-linux-android = None
  cargo:rerun-if-env-changed=CFLAGS_aarch64_linux_android
  CFLAGS_aarch64_linux_android = None
  cargo:rerun-if-env-changed=HOST_CFLAGS
  HOST_CFLAGS = None
  cargo:rerun-if-env-changed=CFLAGS
  CFLAGS = None
  cargo:rerun-if-env-changed=CRATE_CC_NO_DEFAULTS
  CRATE_CC_NO_DEFAULTS = None
  DEBUG = Some("true")
  CARGO_CFG_TARGET_FEATURE = Some("neon")

  --- stderr
  thread 'main' panicked at 'cannot find aarch64-linux-android-ar', /data/data/com.termux/files/home/.cargo/registry/src/index.crates.io-6f17d22bba15001f/luajit-src-210.4.6+resty2cf5186/src/lib.rs:167:17
  note: run with `RUST_BACKTRACE=1` environment variable to display a backtrace
warning: build failed, waiting for other jobs to finish...
khvzak commented 1 year ago

Do you have binutils installed?

alexmozaidze commented 1 year ago

Yikes, I had not.

There seems to be no problems compiling mlua now, however, xplr's codebase is not ready for the new API yet.

khvzak commented 1 year ago

The old one should also work too.

alexmozaidze commented 1 year ago

Hm, most of the errors seem to come from ui.rs, so I'm pretty sure that some UI lib doesn't follow semver properly.

sayanarijit commented 1 year ago

@alexmozaidze I guess you're talking about ratatui update. Try with --locked.

Btw, @khvzak thank you for fixing the bug.

sayanarijit commented 1 year ago

@alexmozaidze not sure how you were able to compile it, but I failed. The problem is that the latest version of termux (from fossdroid) is strictly clang. It even symlinks gcc to clang. And while I was able to install gcc8 from other sources, it didn't work because of missing libraries. @khvzak is there any way to make luajit compile with clang? Else, I guess I'll have drop support for Android, until there comes a friendlier alternative to termux.

error: linking with `aarch64-linux-android-clang` failed: exit status: 1
  |
  = note: LC_ALL="C" PATH="/data/data/com.termux/files/usr/lib/rustlib/aarch64-linux-android/bin:/data/data/com.termux/files/usr/bin" VSLANG="1033" "aarch64-linux-android-clang" "/data/data/com.termux/files/usr/tmp/rustcE6QDM9/symbols.o" "/data/data/com.termux/files/home/xplr/target/release/deps/xplr-7023db21a3091fcb.xplr.6ba5a12f-cgu.0.rcgu.o" "-Wl,--as-needed" "-L" "/data/data/com.termux/files/home/xplr/target/release/deps" "-L" "/data/data/com.termux/files/home/xplr/target/release/build/mlua-d6984c6b5706f9ba/out/luajit-build/lib" "-L" "/data/data/com.termux/files/usr/lib/rustlib/aarch64-linux-android/lib" "-Wl,-Bstatic" "/data/data/com.termux/files/usr/tmp/rustcE6QDM9/libmlua-0fcc934e005c5239.rlib" "/data/data/com.termux/files/usr/lib/rustlib/aarch64-linux-android/lib/libcompiler_builtins-135f0ea21e1a3847.rlib" "-Wl,-Bdynamic" "-ldl" "-llog" "-lunwind" "-ldl" "-lm" "-lc" "-Wl,--eh-frame-hdr" "-Wl,-z,noexecstack" "-L" "/data/data/com.termux/files/usr/lib/rustlib/aarch64-linux-android/lib" "-o" "/data/data/com.termux/files/home/xplr/target/release/deps/xplr-7023db21a3091fcb" "-Wl,--gc-sections" "-pie" "-Wl,-z,relro,-z,now" "-Wl,-O1" "-Wl,--strip-all" "-nodefaultlibs" "-rdynamic"
  = note: ld.lld: error: undefined symbol: __clear_cache
          >>> referenced by lj_mcode.c:49
          >>>               lj_mcode.o:(lj_mcode_sync) in archive /data/data/com.termux/files/usr/tmp/rustcE6QDM9/libmlua-0fcc934e005c5239.rlib
          clang-16: error: linker command failed with exit code 1 (use -v to see invocation)

error: could not compile `xplr` (bin "xplr") due to previous error
error: failed to compile `xplr v0.21.2 (/data/data/com.termux/files/home/xplr)`, intermediate artifacts can be found at `/data/data/com.termux/files/home/xplr/target`
alexmozaidze commented 1 year ago

I just used --locked and get the same error message. I found gcc-9 (and other versions) on Termux User Repository (TUR), but I've yet to figure out a way to make cargo use gcc for building.

As a side note, Termux devs dropped support for gcc after Android did, making it harder to maintain. There are no plans to officially support gcc. See https://github.com/termux/termux-packages/issues/407 for more info on that.

alexmozaidze commented 1 year ago

Yep, doesn't work with gcc. I guess all is left is to make it work with clang.

khvzak commented 1 year ago

Unfortunately I don't have any android device and can test only on emulator (android studio).

I can confirm that xplr (commit) can be build and works fine on the x86_64 android 14 with latest termmux installed from f-droid store.

@sayanarijit gcc is definitely not needed for luajit, it can be compiled using clang (I even did not install gcc).

I need to test somehow using aarch64

sayanarijit commented 1 year ago

Wow cool. I haven't tried in x86_64. Mine is aarch64. Looks like the issue is limited to aarch64 Android then.

khvzak commented 1 year ago

I found what causes the linking issue.

@sayanarijit in xplr in .cargo/config the following section needed:

[target.aarch64-linux-android]
rustflags = ["-C", "linker=aarch64-linux-android-clang", "-C", "link-args=-rdynamic", "-C", "default-linker-libraries"]

you currently don't pass -C default-linker-libraries option.

CompeyDev commented 1 year ago

Was facing the same issue, trying to rebuild with these linker arguments now.