Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Install and Use on Apple Silicon #109

Closed
VannaDii opened this issue Oct 16, 2022 · 9 comments
Closed

Install and Use on Apple Silicon #109

VannaDii opened this issue Oct 16, 2022 · 9 comments

Comments

@VannaDii
Copy link

Hi! Thanks for all the work you've done on this library. I spent the day trying to make sense of it on an Apple M1 chip. I thought it would be easier since the ARM architecture seems to run through it all. Unfortunately, the scripts for the toolchain installation all require an x86_64 architecture. I spent some time googling. When I didn't find much, I just jumped into creating an x86_64 development container in VS Code using docker desktop for Mac. I got pretty far but couldn't make it work out in the end. I've made the repo for this public if anyone wants to take a look.

GioCirque/harmonizers

I would appreciate any pointers, and would be willing to author an Apple Silicon Setup Guide for the readme.

@fenollp
Copy link
Collaborator

fenollp commented Oct 16, 2022

Hi! Great app idea! I'd love to help as I've been looking for an app like this.

Have you tried cross build? https://github.com/canselcik/libremarkable#building-with-cross

If you're willing to use Docker in unusual ways, maybe this can interest you: https://github.com/tonistiigi/xx#external-sdk-support

@VannaDii
Copy link
Author

The first issue is that I can't install the toolchain locally on and ARM system.

❯ ./codex-x86_64-cortexa7hf-neon-rm11x-toolchain-3.1.15.sh
Error: Incompatible SDK installer! Your host is arm64 and this SDK was built for x86_64 hosts.

Which is kinda expected, given the x86_64 in the file name. I'm curious, is there a version for arm64? Could there be a version for arm64?

Short of having an arm64 version, if I pull this repo, can I create my own arm64 version of the toolchain or is there a bunch of x86_64-specific code that won't compile, or other x86_64 specific dependencies that would then also have to be converted. It is possible to develop in an x86_64 container under QEMU, but it's pretty slow and a little flaky. Is there a concrete reason the toolchain only supports one architecture flavor?

@bkirwi
Copy link
Collaborator

bkirwi commented Oct 17, 2022

@GioCirque - the readme has two ways of building libremarkable:

  1. Using the remarkable toolchain.
  2. Using cross.

You shouldn't need the remarkable toolchain at all for 2! Mostly all you need is a functional docker setup, which ought to work fine on M1. I'll second the recommendation of cross; it should work nicely for almost all apps.

(Rebuilding the toolchain for ARM sounds like a pain in comparison; glad you shouldn't have to!)

@VannaDii
Copy link
Author

I see, I might have conflated two issues. When I look at other projects using libremarkable they have something similar to this: https://github.com/LinusCDE/retris/blob/master/.cargo/config#L21

[target.armv7-unknown-linux-gnueabihf]
linker = "/usr/local/oecore-x86_64/sysroots/x86_64-oesdk-linux/usr/bin/arm-oe-linux-gnueabi/arm-oe-linux-gnueabi-gcc"
rustflags = [
  "-C", "link-arg=-march=armv7-a",
  "-C", "link-arg=-marm",
  "-C", "link-arg=-mfpu=neon",
  "-C", "link-arg=-mfloat-abi=hard",
  "-C", "link-arg=-mcpu=cortex-a9",
  "-C", "link-arg=--sysroot=/usr/local/oecore-x86_64/sysroots/cortexa9hf-neon-oe-linux-gnueabi",
]

retris is one example. Notice the x86_64 in the toolchain path. Is there a way to not need this installed or a version that can be installed on another processor architecture?

@VannaDii
Copy link
Author

Using a fresh project with a normal cargo build results in the error below because it can't find the required compiler, which I can't seem to find for my system.

error: failed to run custom build command for `lua52-sys v0.1.2`

Caused by:
  process didn't exit successfully: `/Users/gio/Source/harmonizers/target/debug/build/lua52-sys-fe4ac66ea1032ab1/build-script-build` (exit status: 1)
  --- stdout
  cargo:rerun-if-env-changed=LUA5.2_NO_PKG_CONFIG
  cargo:rerun-if-env-changed=PKG_CONFIG_ALLOW_CROSS_armv7-unknown-linux-gnueabihf
  cargo:rerun-if-env-changed=PKG_CONFIG_ALLOW_CROSS_armv7_unknown_linux_gnueabihf
  cargo:rerun-if-env-changed=TARGET_PKG_CONFIG_ALLOW_CROSS
  cargo:rerun-if-env-changed=PKG_CONFIG_ALLOW_CROSS
  cargo:rerun-if-env-changed=PKG_CONFIG_armv7-unknown-linux-gnueabihf
  cargo:rerun-if-env-changed=PKG_CONFIG_armv7_unknown_linux_gnueabihf
  cargo:rerun-if-env-changed=TARGET_PKG_CONFIG
  cargo:rerun-if-env-changed=PKG_CONFIG
  cargo:rerun-if-env-changed=PKG_CONFIG_SYSROOT_DIR_armv7-unknown-linux-gnueabihf
  cargo:rerun-if-env-changed=PKG_CONFIG_SYSROOT_DIR_armv7_unknown_linux_gnueabihf
  cargo:rerun-if-env-changed=TARGET_PKG_CONFIG_SYSROOT_DIR
  cargo:rerun-if-env-changed=PKG_CONFIG_SYSROOT_DIR
  TARGET = Some("armv7-unknown-linux-gnueabihf")
  OPT_LEVEL = Some("0")
  HOST = Some("aarch64-apple-darwin")
  CC_armv7-unknown-linux-gnueabihf = None
  CC_armv7_unknown_linux_gnueabihf = None
  TARGET_CC = None
  CC = None
  CROSS_COMPILE = None
  CFLAGS_armv7-unknown-linux-gnueabihf = None
  CFLAGS_armv7_unknown_linux_gnueabihf = None
  TARGET_CFLAGS = None
  CFLAGS = None
  CRATE_CC_NO_DEFAULTS = None
  DEBUG = Some("true")
  CARGO_CFG_TARGET_FEATURE = None
  running: "arm-linux-gnueabihf-gcc" "-O0" "-ffunction-sections" "-fdata-sections" "-fPIC" "-g" "-fno-omit-frame-pointer" "-march=armv7-a" "-mfpu=vfpv3-d16" "-I" "lua/src" "-Wall" "-Wextra" "-DLUA_USE_LINUX" "-DLUA_COMPAT_ALL" "-o" "/Users/gio/Source/harmonizers/target/armv7-unknown-linux-gnueabihf/debug/build/lua52-sys-adc7d675b971f46d/out/lua/src/lapi.o" "-c" "lua/src/lapi.c"
  running: "arm-linux-gnueabihf-gcc" "-O0" "-ffunction-sections" "-fdata-sections" "-fPIC" "-g" "-fno-omit-frame-pointer" "-march=armv7-a" "-mfpu=vfpv3-d16" "-I" "lua/src" "-Wall" "-Wextra" "-DLUA_USE_LINUX" "-DLUA_COMPAT_ALL" "-o" "/Users/gio/Source/harmonizers/target/armv7-unknown-linux-gnueabihf/debug/build/lua52-sys-adc7d675b971f46d/out/lua/src/lcode.o" "-c" "lua/src/lcode.c"

  --- stderr


  error occurred: Failed to find tool. Is `arm-linux-gnueabihf-gcc` installed?

I think this is something that a toolchain would provide, and I assumed the libremarkable toolchain would provide it and that I can't install it because I'm not on an x86 system. It seems like y'all are telling that my assumptions are incorrect, and I hope so, but if so, then I don't know where to go next.

@fenollp
Copy link
Collaborator

fenollp commented Oct 17, 2022

cross replaces cargo and you don't need that cargo config (linker nor rustflags).

Just cargo install cross and for instance build the demo app in this repo. This is the easiest and probably only way to get up and running on arm.

@VannaDii
Copy link
Author

Then I guess this cross issue is the next one I'll investigate towards using libremarkable. When all this is finally figured out, is there an appropriate place in the readme for an Apple Silicon Usage Guide?

[cross] warning: cross does not provide a Docker image for target aarch64-apple-darwin, specify a custom image in Cross.toml.
[cross] note: Falling back to cargo on the host.

@fenollp
Copy link
Collaborator

fenollp commented Oct 18, 2022

Ah interesting. I've found cross-rs/cross#508 (comment) which mention you need to bring the macOS SDK yourself (given licensing). The xx link mentions how / where to get an SDK => https://github.com/tpoechtrager/osxcross/blob/master/tools/gen_sdk_package.sh

@VannaDii
Copy link
Author

I was able to skip those steps when I followed the earlier advice of using cross without all the cargo config. It's now building, running on rm2, and rendering basic app chrome. I need to tweak the CI of it because warnings are errors right now ... some yet unused functions. Thanks for all of your help getting it running!

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

No branches or pull requests

3 participants