realm / realm-js

Realm is a mobile database: an alternative to SQLite & key-value stores
https://realm.io
Apache License 2.0
5.8k stars 577 forks source link

Building on Linux ARM64 / AARCH64 #4130

Open kaeferfreund opened 2 years ago

kaeferfreund commented 2 years ago

How frequently does the bug occur?

All the time

Description

I am trying to build realm-js from source according to the guide in this repo. I tried building on my local macbook pro 14 inch with apple silicon m1 pro first. This worked without any problem at all.

When I tried to build on an Ampere A1 in the Oracle Cloud with Ubuntu 20.04 I always get the same error

npm ERR! 173 | void Dictionary::insert(Context& ctx, StringData key, T&& value, CreatePolicy policy) npm ERR! | ^~~~~~~~~~ npm ERR! /usr/bin/ld.gold: error: ../../vendor/realm-core/openssl/lib/libssl.a(methods.o): incompatible target npm ERR! /usr/bin/ld.gold: error: ../../vendor/realm-core/openssl/lib/libssl.a(ssl_cert.o): incompatible target npm ERR! /usr/bin/ld.gold: error: ../../vendor/realm-core/openssl/lib/libssl.a(ssl_lib.o): incompatible target npm ERR! /usr/bin/ld.gold: error: ../../vendor/realm-core/openssl/lib/libssl.a(ssl_rsa.o): incompatible target npm ERR! /usr/bin/ld.gold: error: ../../vendor/realm-core/openssl/lib/libcrypto.a(bio_lib.o): incompatible target npm ERR! /usr/bin/ld.gold: error: ../../vendor/realm-core/openssl/lib/libcrypto.a(bio_meth.o): incompatible target npm ERR! /usr/bin/ld.gold: error: ../../vendor/realm-core/openssl/lib/libcrypto.a(bss_mem.o): incompatible target npm ERR! /usr/bin/ld.gold: error: ../../vendor/realm-core/openssl/lib/libcrypto.a(err.o): incompatible target npm ERR! /usr/bin/ld.gold: error: ../../vendor/realm-core/openssl/lib/libcrypto.a(digest.o): incompatible target npm ERR! /usr/bin/ld.gold: error: ../../vendor/realm-core/openssl/lib/libcrypto.a(e_aes.o): incompatible target npm ERR! /usr/bin/ld.gold: error: ../../vendor/realm-core/openssl/lib/libcrypto.a(evp_enc.o): incompatible target npm ERR! /usr/bin/ld.gold: error: ../../vendor/realm-core/openssl/lib/libcrypto.a(m_sha1.o): incompatible target npm ERR! /usr/bin/ld.gold: error: ../../vendor/realm-core/openssl/lib/libcrypto.a(p_lib.o): incompatible target npm ERR! /usr/bin/ld.gold: error: ../../vendor/realm-core/openssl/lib/libcrypto.a(pem_x509.o): incompatible target npm ERR! /usr/bin/ld.gold: error: ../../vendor/realm-core/openssl/lib/libcrypto.a(sha256.o): incompatible target npm ERR! /usr/bin/ld.gold: error: ../../vendor/realm-core/openssl/lib/libcrypto.a(x509_cmp.o): incompatible target npm ERR! /usr/bin/ld.gold: error: ../../vendor/realm-core/openssl/lib/libcrypto.a(x509_vfy.o): incompatible target npm ERR! /usr/bin/ld.gold: error: ../../vendor/realm-core/openssl/lib/libcrypto.a(x509_vpm.o): incompatible target npm ERR! /usr/bin/ld.gold: error: ../../vendor/realm-core/openssl/lib/libcrypto.a(x_all.o): incompatible target npm ERR! /usr/bin/ld.gold: error: ../../vendor/realm-core/openssl/lib/libcrypto.a(x_x509.o): incompatible target npm ERR! collect2: error: ld returned 1 exit status npm ERR! make[2]: *** [src/node/CMakeFiles/realm-js.dir/build.make:107: Release/realm.node] Error 1 npm ERR! make[1]: *** [CMakeFiles/Makefile2:549: src/node/CMakeFiles/realm-js.dir/all] Error 2 npm ERR! make: *** [Makefile:130: all] Error 2 npm ERR! ERR! OMG Process terminated: 2

When I build the openssl from source an replace the libcrypto.a and libssl.a I can compile successfully.

Anybody an idea where the problem is located exactly? For some reason the openssl dependency is compiled for the wrong architecture?

Stacktrace & log output

No response

Can you reproduce the bug?

Yes, always

Reproduction Steps

Build react-js with npm run build on Ubuntu 20.04 on an Ampire A1 in an Oracle VM

Version

10.10.1

What SDK flavour are you using?

MongoDB Realm (i.e. Sync, auth, functions)

Are you using encryption?

Yes, using encryption

Platform OS and version(s)

Linux

Build environment

Building on Ubuntu 20.04 on an Oracle Ampire A1 VM

kaeferfreund commented 2 years ago

3687

kaeferfreund commented 2 years ago

Currently we assume that Linux means x86_64, and we use a prebuilt binary: https://github.com/realm/realm-core/blob/master/CMakeLists.txt#L211

that is the problem. Should we change this?

kneth commented 2 years ago

Currently we only support Raspberry Pi (32 bit ARM) and x86_64 for Linux.

As we only prebuilt OpenSSL for x86_64 Linux, and you get the observed error message for this reason.

We are following the adoption of 64 bit ARM for Linux, but we can't give an ETA for when we will support it. I will leave the issue open since it would be a good enhancement in the future.

kneth commented 2 years ago

@kaeferfreund I have added a guide on how to build for ARM/Linux in https://github.com/realm/realm-js/pull/4935