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

bat is not working on the Raspberry Pi Zero #952

Closed
HattDroid opened this issue Apr 26, 2020 · 7 comments
Closed

bat is not working on the Raspberry Pi Zero #952

HattDroid opened this issue Apr 26, 2020 · 7 comments

Comments

@HattDroid
Copy link

Hi,

First thank you for your tool, it's been serving me very well since 2018.

I have been using on x86_64 for years now and got used to it. I saw you distribute ARM binaries and decided to give it a go.

Trying both packages

bat-v0.15.0-arm-unknown-linux-gnueabihf.tar.gz
bat_0.15.0_armhf.deb

It every time gives me the following error when trying to launch bat binary:

Illegal instruction

A quick 'file' on the binary shows nothing unusual for the Pi Zero:

bat: ELF 32-bit LSB shared object, ARM, EABI5 version 1 (SYSV), dynamically linked, interpreter /lib/ld-linux-armhf.so.3, for GNU/Linux 3.2.0, BuildID[sha1]=5545ace89bb1ef2c3b0e80caf53964cdb762ca36, stripped

Would you know what is wrong with the release? Are you assuming a specific instruction set (or extension) when cross-compiling?

Thanks.

@sharkdp
Copy link
Owner

sharkdp commented Apr 26, 2020

I'm not an expert on the difference between various ARM architectures, but it seems that the Pi Zero with its ARMv6 architecture is not compatible with the arm-unknown-linux-gnueabihf target triple, which is compatible with ARMv7 and upwards [1].

aarch64 is certainly not compatible as the RPi Zero has a 32bit architecture.

Cross compiling for ARMv6 seems nontrivial. This project provides Docker images, if you want to do this locally.

And you could always try to compile it on the Pi via cargo install bat.

[1] https://www.reddit.com/r/rust/comments/9io0z8/run_crosscompiled_code_on_rpi_0/e6l9hmc?utm_source=share&utm_medium=web2x

@sharkdp
Copy link
Owner

sharkdp commented Apr 26, 2020

Yes, it is non-trivial 😄

Even with the cross-compilation Docker images, it doesn't work out of the box due to #650.

We can create a custom docker which includes libclang:

FROM rustembedded/cross:armv5te-unknown-linux-musleabi

RUN apt-get update && \
    apt-get install -y clang libclang-dev libc6-dev-i386

Next, build the Docker image:

docker build --tag arm-cc:v1 path/to/folder/with/dockerfile

and create a Cross.toml file with this content:

[target.armv5te-unknown-linux-musleabi]
image = "arm-cc:v1"

and then build with

cross build --target armv5te-unknown-linux-musleabi --release

Unfortunately, this currently fails with some illegal instruction errors during the compilation of libgit2_sys:

  = note: /target/armv5te-unknown-linux-musleabi/debug/deps/liblibgit2_sys-51cb7b6fa168cf79.rlib(odb.o): In function `git_atomic_inc':
          /cargo/registry/src/github.jparrowsec.cn-1ecc6299db9ec823/libgit2-sys-0.12.4+1.0.0/libgit2/src/thread-utils.h:71: undefined reference to `__sync_add_and_fetch_4'
          /target/armv5te-unknown-linux-musleabi/debug/deps/liblibgit2_sys-51cb7b6fa168cf79.rlib(odb.o): In function `git_atomic_dec':

I managed to strip out the --diff functionality of bat v0.15 ...

diff --git a/Cargo.toml b/Cargo.toml
index d449df6..0e5b442 100644
--- a/Cargo.toml
+++ b/Cargo.toml
@@ -23,7 +23,7 @@ application = [
     "atty",
     "clap",
     "dirs",
-    "git",
+    # "git",
     "lazy_static",
     "liquid",
     "paging",
diff --git a/src/bin/bat/app.rs b/src/bin/bat/app.rs
index d5751f7..b0a4fad 100644
--- a/src/bin/bat/app.rs
+++ b/src/bin/bat/app.rs
@@ -198,14 +198,7 @@ impl App {
                     }
                 })
                 .unwrap_or_else(|| String::from(HighlightingAssets::default_theme())),
-            visible_lines: if self.matches.is_present("diff") {
-                VisibleLines::DiffContext(
-                    self.matches
-                        .value_of("diff-context")
-                        .and_then(|t| t.parse().ok())
-                        .unwrap_or(2),
-                )
-            } else {
+            visible_lines: 
                 VisibleLines::Ranges(
                     self.matches
                         .values_of("line-range")
@@ -214,7 +207,7 @@ impl App {
                         .map(LineRanges::from)
                         .unwrap_or_default(),
                 )
-            },
+            ,
             style_components,
             syntax_mapping,
             pager: self.matches.value_of("pager"),

... and build a version without Git support for ARMv5, which I have attached: bat-armv5.zip

@sharkdp sharkdp changed the title [ISSUE] Bat is not working on the Raspberry Pi Zero bat is not working on the Raspberry Pi Zero Apr 26, 2020
@sharkdp
Copy link
Owner

sharkdp commented Apr 26, 2020

With armv5te-unknown-linux-gnueabi, libgit2-sys compiles, but them I'm running into rust-lang/rust#48625

@HattDroid
Copy link
Author

Tanks a lot for the stripped down version of bat. Just tried it and it works!

This seems to be an issue with the toolchain itself, I've encountered other projects in which compiling towards the Zero target was also an issue.

Hopefully it'll get solved by the Rust team in the future. I'll keep using your custom binary in the meantime.

Thanks again for the efforts and support, that's really helpful. 👍👍👍

@sharkdp
Copy link
Owner

sharkdp commented Apr 27, 2020

Glad it works. Thank you for the feedback 😄

@sharkdp sharkdp closed this as completed Apr 27, 2020
@sharkdp
Copy link
Owner

sharkdp commented May 16, 2020

There are some new developments on this issue:

@sharkdp
Copy link
Owner

sharkdp commented May 24, 2020

With #650 now closed and #997 merged, we can now easily cross-compile bat for armv5te:

cross build \
  --target armv5te-unknown-linux-musleabi \
  --release \
  --no-default-features \
  --features=atty,clap,dirs,lazy_static,liquid,paging,wild,regex-onig

Note that we use the feature flags to disable git support.

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

No branches or pull requests

2 participants