Skip to contentSkip to conversation

package/bat: new package

PATCH New David Pierret 3 participants 4 messages Mar 27, 2020 – Jul 27, 2020

lore
Share & tools
lore
#0 lore raw

PATCH v2 1/1 package/bat: new package

bat is a cat(1) clone with syntax highlighting and Git integration.

This package need rust version 1.37.0 or later

----
bat supports syntax highlighting for a large number of programming and markup languages. He can communicates with git to show modifications with respect to the index.
For conveignance use, bat can pipe its own output to less if the output is too large for one screen.

v1 -> v2
Add selection of less out of busybox for command line option compatibility

---
 DEVELOPERS            |  3 +++
 package/Config.in     |  1 +
 package/bat/Config.in | 13 +++++++++++++
 package/bat/bat.hash  |  4 ++++
 package/bat/bat.mk    | 39 +++++++++++++++++++++++++++++++++++++++
 5 files changed, 60 insertions(+)
 create mode 100644 package/bat/Config.in
 create mode 100644 package/bat/bat.hash
 create mode 100644 package/bat/bat.mk
DEVELOPERS +3 -0
index 7cb61e2b98..3afa45fc7f 100644
@@ -688,6 +688,9 @@ F:	linux/linux-ext-ev3dev-linux-drivers.mk
 F:	package/brickd/
 F:	package/ev3dev-linux-drivers/
 
+N:	David Pierret <[email protected]>
+F:	package/bat/
+
 N:	Davide Viti <[email protected]>
 F:	package/flann/
 F:	package/python-paho-mqtt/
package/Config.in +1 -0
index 7b73198d50..e0fc92c347 100644
@@ -2385,6 +2385,7 @@ menu "System tools"
 endmenu
 
 menu "Text editors and viewers"
+	source "package/bat/Config.in"
 	source "package/ed/Config.in"
 	source "package/joe/Config.in"
 	source "package/less/Config.in"
package/bat/Config.in new file +13 -0
new file mode 100644
index 0000000000..33a33673a8
@@ -0,0 +1,13 @@
+config BR2_PACKAGE_BAT
+	bool "bat"
+	depends on BR2_PACKAGE_HOST_RUSTC_TARGET_ARCH_SUPPORTS
+	select BR2_PACKAGE_HOST_RUSTC
+	# we need a full version of less
+	select BR2_PACKAGE_BUSYBOX_SHOW_OTHERS
+	# less needs ncurses
+	select BR2_PACKAGE_NCURSES
+	select BR2_PACKAGE_LESS
+	help
+	  A cat(1) clone with syntax highlighting and Git integration.
+
+	  https://github.com/sharkdp/bat
package/bat/bat.hash new file +4 -0
new file mode 100644
index 0000000000..14438b8a6f
@@ -0,0 +1,4 @@
+# Locally generated
+sha256 f4aee370013e2a3bc84c405738ed0ab6e334d3a9f22c18031a7ea008cd5abd2a  bat-0.13.0.tar.gz
+sha256 c71d239df91726fc519c6eb72d318ec65820627232b2f796219e87dcf35d0ab4  LICENSE-APACHE
+sha256 dc931b3f4376dc2b12486ded9f51487719099074587d757ea6125bb59deeb221  LICENSE-MIT
package/bat/bat.mk new file +39 -0
new file mode 100644
index 0000000000..89711ac33b
@@ -0,0 +1,39 @@
+################################################################################
+#
+# bat
+#
+################################################################################
+
+BAT_VERSION = 0.13.0
+BAT_SITE = $(call github,sharkdp,bat,v$(BAT_VERSION))
+BAT_LICENSE = Apache-2.0 or MIT
+BAT_LICENSE_FILES = LICENSE-APACHE LICENSE-MIT
+BAT_DEPENDENCIES = host-rustc
+
+BAT_CFLAGS = $(TARGET_CFLAGS)
+
+BAT_CARGO_ENV = CARGO_HOME=$(HOST_DIR)/share/cargo
+BAT_CARGO_MODE = $(if $(BR2_ENABLE_DEBUG),debug,release)
+
+BAT_BIN_DIR = target/$(RUSTC_TARGET_NAME)/$(BAT_CARGO_MODE)
+
+BAT_CARGO_OPTS = \
+		 --bins \
+		 --$(BAT_CARGO_MODE) \
+		 --target=$(RUSTC_TARGET_NAME) \
+		 --manifest-path=$(@D)/Cargo.toml
+
+define BAT_BUILD_CMDS
+	# we need to use the 'env' command to set the CC_<target> variable since
+	# the rustc_target_name contain minus characters not allowed in bash.
+	env $(TARGET_MAKE_ENV) $(BAT_CARGO_ENV) \
+	CC_$(RUSTC_TARGET_NAME)=$(TARGET_CC) \
+		cargo build $(BAT_CARGO_OPTS)
+endef
+
+define BAT_INSTALL_TARGET_CMDS
+	$(INSTALL) -D -m 0755 $(@D)/$(BAT_BIN_DIR)/bat \
+		$(TARGET_DIR)/usr/bin/bat
+endef
+
+$(eval $(generic-package))
Signature · 1 line
2.17.1
#1 lore raw

PATCH v2 1/1 package/bat: new package

David,

Le 27/03/2020 ? 18:40, David Pierret a ?crit?:

Quoted 17 lines

bat is a cat(1) clone with syntax highlighting and Git integration.

This package need rust version 1.37.0 or later

----
bat supports syntax highlighting for a large number of programming and markup languages. He can communicates with git to show modifications with respect to the index.
For conveignance use, bat can pipe its own output to less if the output is too large for one screen.

v1 -> v2
Add selection of less out of busybox for command line option compatibility
---

[...]

package/bat/Config.in line 7

Quoted 9 lines

+++ b/package/bat/Config.in

package/bat/Config.in new file +7 -0
@@ -0,0 +1,13 @@
+config BR2_PACKAGE_BAT
+	bool "bat"
+	depends on BR2_PACKAGE_HOST_RUSTC_TARGET_ARCH_SUPPORTS
+	select BR2_PACKAGE_HOST_RUSTC
+	# we need a full version of less
+	select BR2_PACKAGE_BUSYBOX_SHOW_OTHERS
+	# less needs ncurses

This comment is useless.

package/bat/Config.in line 9

Quoted 2 lines
package/bat/Config.in new file +2 -0
+	select BR2_PACKAGE_NCURSES
+	select BR2_PACKAGE_LESS

Add a comment "# Runtime dependency" for each.

Quoted 42 lines
package/bat/Config.in new file +4 -0
+	help
+	  A cat(1) clone with syntax highlighting and Git integration.
+
+	  https://github.com/sharkdp/bat
package/bat/bat.hash new file +4 -0
new file mode 100644
index 0000000000..14438b8a6f
@@ -0,0 +1,4 @@
+# Locally generated
+sha256 f4aee370013e2a3bc84c405738ed0ab6e334d3a9f22c18031a7ea008cd5abd2a  bat-0.13.0.tar.gz
+sha256 c71d239df91726fc519c6eb72d318ec65820627232b2f796219e87dcf35d0ab4  LICENSE-APACHE
+sha256 dc931b3f4376dc2b12486ded9f51487719099074587d757ea6125bb59deeb221  LICENSE-MIT
package/bat/bat.mk new file +22 -0
new file mode 100644
index 0000000000..89711ac33b
@@ -0,0 +1,39 @@
+################################################################################
+#
+# bat
+#
+################################################################################
+
+BAT_VERSION = 0.13.0
+BAT_SITE = $(call github,sharkdp,bat,v$(BAT_VERSION))
+BAT_LICENSE = Apache-2.0 or MIT
+BAT_LICENSE_FILES = LICENSE-APACHE LICENSE-MIT
+BAT_DEPENDENCIES = host-rustc
+
+BAT_CFLAGS = $(TARGET_CFLAGS)
+
+BAT_CARGO_ENV = CARGO_HOME=$(HOST_DIR)/share/cargo
+BAT_CARGO_MODE = $(if $(BR2_ENABLE_DEBUG),debug,release)
+
+BAT_BIN_DIR = target/$(RUSTC_TARGET_NAME)/$(BAT_CARGO_MODE)
+
+BAT_CARGO_OPTS = \
+		 --bins \
+		 --$(BAT_CARGO_MODE) \

package/bat/bat.mk line 32

Quoted 10 lines
package/bat/bat.mk new file +10 -0
+		 --target=$(RUSTC_TARGET_NAME) \
+		 --manifest-path=$(@D)/Cargo.toml
+
+define BAT_BUILD_CMDS
+	# we need to use the 'env' command to set the CC_<target> variable since
+	# the rustc_target_name contain minus characters not allowed in bash.
+	env $(TARGET_MAKE_ENV) $(BAT_CARGO_ENV) \
+	CC_$(RUSTC_TARGET_NAME)=$(TARGET_CC) \
+		cargo build $(BAT_CARGO_OPTS)
+endef

David, can you add some details about the issue with CC_<target> ?

It would be great if you can use the upcoming cargo package infra, but this infra doesn't handle CC_<target>.

As you noticed the build fail because we need to set CC_aarch64-none-linux-gnu environment variable for aarch64 target build.

Arnout, Patrick. It seems David discovered a cross-compilation issue with cargo. I reproduced the issue, cargo is using the host compiler instead of the cross-compiler:

error: failed to run custom build command for libloading v0.5.2

Caused by:
process didn't exit successfully:
/home/naourr/buildroot/test/bat/build/bat-0.13.0/target/release/build/libloading-0c8de6c7b10afd2b/build-script-build (exit code: 1)
--- stdout
cargo:rustc-link-lib=dl
TARGET = Some("x86_64-unknown-linux-gnu")
OPT_LEVEL = Some("3")
HOST = Some("x86_64-unknown-linux-gnu")
CC_x86_64-unknown-linux-gnu = None
CC_x86_64_unknown_linux_gnu = None
HOST_CC = None
CC = Some("/home/naourr/buildroot/test/bat/host/bin/aarch64-none-linux-gnu-gcc") CFLAGS_x86_64-unknown-linux-gnu = None
CFLAGS_x86_64_unknown_linux_gnu = None
HOST_CFLAGS = None
CFLAGS = Some("-D_LARGEFILE_SOURCE -D_LARGEFILE64_SOURCE -D_FILE_OFFSET_BITS=64
-Os ")
CRATE_CC_NO_DEFAULTS = None
DEBUG = Some("false")
CARGO_CFG_TARGET_FEATURE = Some("fxsr,sse,sse2")
running: "/home/naourr/buildroot/test/bat/host/bin/aarch64-none-linux-gnu-gcc"
"-O3" "-ffunction-sections" "-fdata-sections" "-fPIC" "-m64"
"-D_LARGEFILE_SOURCE" "-D_LARGEFILE64_SOURCE" "-D_FILE_OFFSET_BITS=64" "-Os"
"-o" "/home/naourr/buildroot/test/bat/build/bat-0.13.0/target/release/build/libloading-f48b6720ea7caaa6/out/src/os/unix/global_static.o" "-c" "src/os/unix/global_static.c"
cargo:warning=aarch64-none-linux-gnu-gcc: error: unrecognized command line
option ?-m64?
exit code: 1

See:
https://stackoverflow.com/questions/54029117/why-is-the-target-environment-variable-reset-when-compiling-a-rust-program-in-a

Best regards,
Romain

Quoted 8 lines
package/bat/bat.mk new file +7 -0
+
+define BAT_INSTALL_TARGET_CMDS
+	$(INSTALL) -D -m 0755 $(@D)/$(BAT_BIN_DIR)/bat \
+		$(TARGET_DIR)/usr/bin/bat
+endef
+
+$(eval $(generic-package))
#2 lore raw

PATCH v2 1/1 package/bat: new package

Hi,

Quoted 94 lines · Romain Naour

David,

Le 27/03/2020 ? 18:40, David Pierret a ?crit :

Quoted 17 lines

bat is a cat(1) clone with syntax highlighting and Git integration.

This package need rust version 1.37.0 or later

----
bat supports syntax highlighting for a large number of programming and markup languages. He can communicates with git to show modifications with respect to the index.
For conveignance use, bat can pipe its own output to less if the output is too large for one screen.

v1 -> v2
Add selection of less out of busybox for command line option compatibility
---

[...]

package/bat/Config.in line 7

Quoted 9 lines

+++ b/package/bat/Config.in

package/bat/Config.in new file +7 -0
@@ -0,0 +1,13 @@
+config BR2_PACKAGE_BAT
+     bool "bat"
+     depends on BR2_PACKAGE_HOST_RUSTC_TARGET_ARCH_SUPPORTS
+     select BR2_PACKAGE_HOST_RUSTC
+     # we need a full version of less
+     select BR2_PACKAGE_BUSYBOX_SHOW_OTHERS
+     # less needs ncurses

This comment is useless.

package/bat/Config.in line 9

Quoted 2 lines
package/bat/Config.in new file +2 -0
+     select BR2_PACKAGE_NCURSES
+     select BR2_PACKAGE_LESS

Add a comment "# Runtime dependency" for each.

Quoted 42 lines
package/bat/Config.in new file +4 -0
+     help
+       A cat(1) clone with syntax highlighting and Git integration.
+
+       https://github.com/sharkdp/bat
package/bat/bat.hash new file +4 -0
new file mode 100644
index 0000000000..14438b8a6f
@@ -0,0 +1,4 @@
+# Locally generated
+sha256 f4aee370013e2a3bc84c405738ed0ab6e334d3a9f22c18031a7ea008cd5abd2a  bat-0.13.0.tar.gz
+sha256 c71d239df91726fc519c6eb72d318ec65820627232b2f796219e87dcf35d0ab4  LICENSE-APACHE
+sha256 dc931b3f4376dc2b12486ded9f51487719099074587d757ea6125bb59deeb221  LICENSE-MIT
package/bat/bat.mk new file +22 -0
new file mode 100644
index 0000000000..89711ac33b
@@ -0,0 +1,39 @@
+################################################################################
+#
+# bat
+#
+################################################################################
+
+BAT_VERSION = 0.13.0
+BAT_SITE = $(call github,sharkdp,bat,v$(BAT_VERSION))
+BAT_LICENSE = Apache-2.0 or MIT
+BAT_LICENSE_FILES = LICENSE-APACHE LICENSE-MIT
+BAT_DEPENDENCIES = host-rustc
+
+BAT_CFLAGS = $(TARGET_CFLAGS)
+
+BAT_CARGO_ENV = CARGO_HOME=$(HOST_DIR)/share/cargo
+BAT_CARGO_MODE = $(if $(BR2_ENABLE_DEBUG),debug,release)
+
+BAT_BIN_DIR = target/$(RUSTC_TARGET_NAME)/$(BAT_CARGO_MODE)
+
+BAT_CARGO_OPTS = \
+              --bins \
+              --$(BAT_CARGO_MODE) \

package/bat/bat.mk line 32

Quoted 10 lines
package/bat/bat.mk new file +10 -0
+              --target=$(RUSTC_TARGET_NAME) \
+              --manifest-path=$(@D)/Cargo.toml
+
+define BAT_BUILD_CMDS
+     # we need to use the 'env' command to set the CC_<target> variable since
+     # the rustc_target_name contain minus characters not allowed in bash.
+     env $(TARGET_MAKE_ENV) $(BAT_CARGO_ENV) \
+     CC_$(RUSTC_TARGET_NAME)=$(TARGET_CC) \
+             cargo build $(BAT_CARGO_OPTS)
+endef

David, can you add some details about the issue with CC_<target> ?

Quoted 2 lines

It would be great if you can use the upcoming cargo package infra, but this infra doesn't handle CC_<target>.

Yes, I will do it for the v3, but we need to fix the CC_<target> first, because the
upcoming cargo infra allow the package to not specify the BUILD_CMD macro.

Quoted 41 lines

As you noticed the build fail because we need to set CC_aarch64-none-linux-gnu environment variable for aarch64 target build.

Arnout, Patrick. It seems David discovered a cross-compilation issue with cargo. I reproduced the issue, cargo is using the host compiler instead of the cross-compiler:

error: failed to run custom build command for libloading v0.5.2

Caused by:
process didn't exit successfully:
/home/naourr/buildroot/test/bat/build/bat-0.13.0/target/release/build/libloading-0c8de6c7b10afd2b/build-script-build (exit code: 1)
--- stdout
cargo:rustc-link-lib=dl
TARGET = Some("x86_64-unknown-linux-gnu")
OPT_LEVEL = Some("3")
HOST = Some("x86_64-unknown-linux-gnu")
CC_x86_64-unknown-linux-gnu = None
CC_x86_64_unknown_linux_gnu = None
HOST_CC = None
CC = Some("/home/naourr/buildroot/test/bat/host/bin/aarch64-none-linux-gnu-gcc") CFLAGS_x86_64-unknown-linux-gnu = None
CFLAGS_x86_64_unknown_linux_gnu = None
HOST_CFLAGS = None
CFLAGS = Some("-D_LARGEFILE_SOURCE -D_LARGEFILE64_SOURCE -D_FILE_OFFSET_BITS=64
-Os ")
CRATE_CC_NO_DEFAULTS = None
DEBUG = Some("false")
CARGO_CFG_TARGET_FEATURE = Some("fxsr,sse,sse2")
running: "/home/naourr/buildroot/test/bat/host/bin/aarch64-none-linux-gnu-gcc"
"-O3" "-ffunction-sections" "-fdata-sections" "-fPIC" "-m64"
"-D_LARGEFILE_SOURCE" "-D_LARGEFILE64_SOURCE" "-D_FILE_OFFSET_BITS=64" "-Os"
"-o" "/home/naourr/buildroot/test/bat/build/bat-0.13.0/target/release/build/libloading-f48b6720ea7caaa6/out/src/os/unix/global_static.o" "-c" "src/os/unix/global_static.c"
cargo:warning=aarch64-none-linux-gnu-gcc: error: unrecognized command line
option ?-m64?
exit code: 1

Quoted 2 lines

See:
https://stackoverflow.com/questions/54029117/why-is-the-target-environment-variable-reset-when-compiling-a-rust-program-in-a

Some rust dependances use the host compiler as target compiler (not considered as defects by maintainers).
see : https://github.com/alexcrichton/cc-rs/issues/382#issuecomment-473948063

To force Cargo to use the good compiler, you need to specify the CC by architectures like explain in this article :
https://github.com/alexcrichton/cc-rs#external-configuration-via-environment-variables

For this I've used the env command who accept the variables name
containing minus sign.
see : https://github.com/NixOS/nixpkgs/blob/master/pkgs/build-support/rust/default.nix#L152-L163

Quoted 13 lines

Best regards,
Romain

Quoted 8 lines
package/bat/bat.mk new file +7 -0
+
+define BAT_INSTALL_TARGET_CMDS
+     $(INSTALL) -D -m 0755 $(@D)/$(BAT_BIN_DIR)/bat \
+             $(TARGET_DIR)/usr/bin/bat
+endef
+
+$(eval $(generic-package))
#3 lore raw

PATCH v2 1/1 package/bat: new package

In reply to Romain Naour
Quoted 28 lines · On Sat, 28 Mar 2020 22:18:29 +0100 Romain Naour <[email protected]> wrote:

David, can you add some details about the issue with CC_<target> ?

It would be great if you can use the upcoming cargo package infra, but this infra doesn't handle CC_<target>.

As you noticed the build fail because we need to set CC_aarch64-none-linux-gnu environment variable for aarch64 target build.

Arnout, Patrick. It seems David discovered a cross-compilation issue with cargo. I reproduced the issue, cargo is using the host compiler instead of the cross-compiler:

error: failed to run custom build command for libloading v0.5.2

Caused by:
process didn't exit successfully:
/home/naourr/buildroot/test/bat/build/bat-0.13.0/target/release/build/libloading-0c8de6c7b10afd2b/build-script-build (exit code: 1)
--- stdout
cargo:rustc-link-lib=dl
TARGET = Some("x86_64-unknown-linux-gnu")
OPT_LEVEL = Some("3")
HOST = Some("x86_64-unknown-linux-gnu")
CC_x86_64-unknown-linux-gnu = None
CC_x86_64_unknown_linux_gnu = None
HOST_CC = None
CC = Some("/home/naourr/buildroot/test/bat/host/bin/aarch64-none-linux-gnu-gcc") CFLAGS_x86_64-unknown-linux-gnu = None

Quoted 8 lines

CFLAGS_x86_64_unknown_linux_gnu = None
HOST_CFLAGS = None
CFLAGS = Some("-D_LARGEFILE_SOURCE -D_LARGEFILE64_SOURCE -D_FILE_OFFSET_BITS=64 -Os ")
CRATE_CC_NO_DEFAULTS = None
DEBUG = Some("false")
CARGO_CFG_TARGET_FEATURE = Some("fxsr,sse,sse2")
running: "/home/naourr/buildroot/test/bat/host/bin/aarch64-none-linux-gnu-gcc"

The selected compiler is correct!

Quoted 1 line

"-O3" "-ffunction-sections" "-fdata-sections" "-fPIC" "-m64"

However, probably due to the TARGET value being wrong, an invalid -m64 option was passed here.

That being said, I applied this patch, dropped the CC_something hack to reproduce the problem... and it doesn't appear anymore. Could you see if it also work for you now ?

Note that I did not even update the "bat" version, but it anyway uses a newer version of libloading: it uses 0.5.2 here, while in your case, it was using 0c8de6c7b10afd2b (which oddly enough is not a valid commit in the rust_libloading Github repository).

Could you double check that this issue still exists ?

Thomas

Signature · 3 lines
Thomas Petazzoni, CTO, Bootlin
Embedded Linux and Kernel engineering
https://bootlin.com