Skip to content

Commit

Permalink
synocli-file: add ripgrep, initial rust support (#3883)
Browse files Browse the repository at this point in the history
* ripgrep: initial package v. 11.0.2
This also adds support for building rust packages.

* update ripgrep to v13.0.0
* build with pcre2 feature

* enhance rust build
- install cargo to /opt/cargo
- download additional rust targets

* Add rust build to framework
- add common Makefile for rust build and installation
- install rust targets on demand
- remove rust target installation from Dockerfile

* Add ripgrep to synocli-file
- add ripgrep to synocli-file
- move spk/ripgrep to diyspk/ripgrep

* enhance rust Makefile
- allow to define other release channel than 'stable'
- allow to define additional cargo build args

* Install rustup when compiling package.
* ripgrep: include build for ARMv7L

Co-authored-by: hgy59 <[email protected]>
Co-authored-by: etcusrvar <[email protected]>
  • Loading branch information
3 people authored Jun 28, 2021
1 parent 55a15e8 commit bab9528
Show file tree
Hide file tree
Showing 8 changed files with 240 additions and 6 deletions.
20 changes: 20 additions & 0 deletions cross/ripgrep/Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
PKG_NAME = ripgrep
PKG_VERS = 13.0.0
PKG_EXT = tar.gz
PKG_DIST_NAME = $(PKG_VERS).$(PKG_EXT)
PKG_DIST_SITE = https://github.com/BurntSushi/ripgrep/archive
PKG_DIST_FILE = $(PKG_NAME)-$(PKG_VERS).$(PKG_EXT)
PKG_DIR = $(PKG_NAME)-$(PKG_VERS)

DEPENDS =

# powerpc archs (except qoriq) are not supported
UNSUPPORTED_ARCHS += $(OLD_PPC_ARCHS)

HOMEPAGE = https://github.com/BurntSushi/ripgrep
COMMENT = ripgrep recursively searches directories for a regex pattern
LICENSE = public domain/Unlicense

CARGO_BUILD_ARGS += --features 'pcre2'

include ../../mk/spksrc.cross-rust.mk
1 change: 1 addition & 0 deletions cross/ripgrep/PLIST
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
bin:bin/rg
3 changes: 3 additions & 0 deletions cross/ripgrep/digests
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
ripgrep-13.0.0.tar.gz SHA1 1e67603fbc5dd955d0f65fb6ea3c380145fbcb01
ripgrep-13.0.0.tar.gz SHA256 0fb17aaf285b3eee8ddab17b833af1e190d73de317ff9648751ab0660d763ed2
ripgrep-13.0.0.tar.gz MD5 3080265a3ccc09bdc0c81527b09afa15
21 changes: 21 additions & 0 deletions diyspk/ripgrep/Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
SPK_NAME = ripgrep
SPK_VERS = 13.0.0
SPK_REV = 1
SPK_ICON = src/ripgrep.png

DEPENDS = cross/$(SPK_NAME)

# powerpc archs (except qoriq) are not supported
UNSUPPORTED_ARCHS += $(OLD_PPC_ARCHS)

MAINTAINER = Hylen
DESCRIPTION = ripgrep is a line-oriented search tool that recursively searches your current directory for a regex pattern.
DISPLAY_NAME = ripgrep
STARTABLE = no

SPK_COMMANDS = bin/rg

HOMEPAGE = https://github.com/BurntSushi/ripgrep
LICENSE = public domain/Unlicense

include ../../mk/spksrc.spk.mk
Empty file added diyspk/ripgrep/PLIST
Empty file.
Binary file added diyspk/ripgrep/src/ripgrep.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
182 changes: 182 additions & 0 deletions mk/spksrc.cross-rust.mk
Original file line number Diff line number Diff line change
@@ -0,0 +1,182 @@
# Build rust programs
#
# prerequisites:
# - module does not require kernel (REQUIRE_KERNEL)
#
# remarks:
# - most content is taken from spksrc.cc.mk and modified for rust
# - CONFIGURE_TARGET is not supported (used for rust target installation)
# - build and install is done in one step
#

# Common makefiles
include ../../mk/spksrc.common.mk
include ../../mk/spksrc.directories.mk

# Configure the included makefiles
URLS = $(PKG_DIST_SITE)/$(PKG_DIST_NAME)
NAME = $(PKG_NAME)
COOKIE_PREFIX = $(PKG_NAME)-
ifneq ($(PKG_DIST_FILE),)
LOCAL_FILE = $(PKG_DIST_FILE)
else
LOCAL_FILE = $(PKG_DIST_NAME)
endif
DIST_FILE = $(DISTRIB_DIR)/$(LOCAL_FILE)
DIST_EXT = $(PKG_EXT)

ifneq ($(ARCH),)
ARCH_SUFFIX = -$(ARCH)-$(TCVERSION)
TC = syno$(ARCH_SUFFIX)
endif

##### rust specific configurations

# configure is used to install rust targets
CONFIGURE_TARGET = install_rust_target

# skip compile_target if not used by module
ifeq ($(strip $(COMPILE_TARGET)),)
COMPILE_TARGET = nop
endif

RUST_TOOLCHAIN ?= stable

RUST_TARGET =
# map archs to rust targets
ifeq ($(findstring $(ARCH), $(x64_ARCHS)),$(ARCH))
RUST_TARGET=x86_64-unknown-linux-gnu
endif
ifeq ($(findstring $(ARCH), $(i686_ARCHS)),$(ARCH))
RUST_TARGET=i686-unknown-linux-gnu
endif
ifeq ($(findstring $(ARCH), $(ARMv5_ARCHS)),$(ARCH))
# may be not supported for cargo
RUST_TARGET=armv5te-unknown-linux-gnueabi
endif
ifeq ($(findstring $(ARCH), $(ARMv7_ARCHS) $(ARMv7L_ARCHS)),$(ARCH))
RUST_TARGET=armv7-unknown-linux-gnueabihf
endif
ifeq ($(findstring $(ARCH), $(ARMv7L_ARCHS)),$(ARCH))
RUST_TARGET=armv7-unknown-linux-gnueabi
endif
ifeq ($(findstring $(ARCH), $(ARMv8_ARCHS)),$(ARCH))
RUST_TARGET=aarch64-unknown-linux-gnu
endif
ifeq ($(findstring $(ARCH), $(PPC_ARCHS)),$(ARCH))
RUST_TARGET=powerpc-unknown-linux-gnu
endif
ifeq ($(RUST_TARGET),)
$(error Arch $(ARCH) not supported)
endif

# Use distrib folder as cargo download cache
CARGO_HOME_PATH=/spksrc/distrib/cargo
ENV += CARGO_HOME=$(CARGO_HOME_PATH)
ENV += PATH=:$(CARGO_HOME_PATH)/bin/:$(PATH)

ifeq (,$(shell $(ENV) which rustup))
install_rustup:
@echo " ==> install rustup" ; \
curl --proto '=https' --tlsv1.2 -sSf https://sh.rustup.rs | \
CARGO_HOME=$(CARGO_HOME_PATH) sh -s -- -y
else
install_rustup:
@echo " ==> rustup already installed" ;
endif

install_rust_toolchain: install_rustup
@echo " ==> install rust toolchain [$(RUST_TOOLCHAIN)]" ; \
env $(ENV) rustup toolchain install $(RUST_TOOLCHAIN) ;
env $(ENV) rustup default $(RUST_TOOLCHAIN) ;

# Install rust target on demand:
install_rust_target: install_rust_toolchain
@echo " ==> install rust target [$(RUST_TARGET)]" ; \
env $(ENV) rustup target install $(RUST_TARGET) ;

# Set default RUST_SRC_DIR
ifeq ($(strip $(RUST_SRC_DIR)),)
RUST_SRC_DIR = $(WORK_DIR)/$(PKG_DIR)
endif

# Set linker environment variable
RUST_LINKER_ENV=CARGO_TARGET_$(shell echo $(RUST_TARGET) | tr - _ | tr a-z A-Z)_LINKER
CARGO_ENV=$(RUST_LINKER_ENV)=$(TC_PATH)$(TC_PREFIX)gcc

# Set the cargo parameters
CARGO_BUILD_ARGS += --target=$(RUST_TARGET)
CARGO_BUILD_ARGS += --path $(RUST_SRC_DIR)
CARGO_BUILD_ARGS += --root $(STAGING_INSTALL_PREFIX)


ifeq ($(strip $(INSTALL_TARGET)),)
INSTALL_TARGET = rust_build_and_install_target
endif

# Default rust build and installation with cargo
rust_build_and_install_target:
@echo " ==> Cargo install rust package $(PKG_NAME)"
$(ENV) $(CARGO_ENV) cargo install $(CARGO_BUILD_ARGS)


#####

include ../../mk/spksrc.pre-check.mk

include ../../mk/spksrc.cross-env.mk

include ../../mk/spksrc.download.mk

include ../../mk/spksrc.depend.mk

checksum: download
include ../../mk/spksrc.checksum.mk

extract: checksum depend
include ../../mk/spksrc.extract.mk

patch: extract
include ../../mk/spksrc.patch.mk

configure: patch
include ../../mk/spksrc.configure.mk

compile: configure
include ../../mk/spksrc.compile.mk

install: compile
include ../../mk/spksrc.install.mk

plist: install
include ../../mk/spksrc.plist.mk

### Clean rules
smart-clean:
rm -rf $(WORK_DIR)/$(PKG_DIR)
rm -f $(WORK_DIR)/.$(COOKIE_PREFIX)*

clean:
rm -fr work work-*

all: install plist

### For make kernel-required (used by spksrc.spk.mk)
include ../../mk/spksrc.kernel-required.mk

### For make digests
include ../../mk/spksrc.generate-digests.mk

### For make dependency-tree
include ../../mk/spksrc.dependency-tree.mk

.PHONY: all-archs
all-archs: $(addprefix arch-,$(AVAILABLE_TOOLCHAINS))

####

arch-%:
@$(MSG) Building package for arch $*
-@MAKEFLAGS= $(MAKE) ARCH=$(basename $(subst -,.,$(basename $(subst .,,$*)))) TCVERSION=$(if $(findstring $*,$(basename $(subst -,.,$(basename $(subst .,,$*))))),$(DEFAULT_TC),$(notdir $(subst -,/,$*)))

####
19 changes: 13 additions & 6 deletions spk/synocli-file/Makefile
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
SPK_NAME = synocli-file
SPK_VERS = 2.2
SPK_REV = 9
SPK_VERS = 2.3
SPK_REV = 10
SPK_ICON = src/synocli-file.png

DEPENDS = cross/less cross/tree cross/ncdu cross/jdupes cross/rhash cross/mc cross/nano cross/file
DEPENDS += cross/detox cross/pcre2
DEPENDS += cross/zstd cross/lzip cross/plzip
DEPENDS += cross/fdupes
OPTIONAL_DEPENDS = cross/rmlint cross/rnm cross/micro cross/fzf
OPTIONAL_DEPENDS = cross/rmlint cross/rnm cross/micro cross/fzf cross/ripgrep

MAINTAINER = SynoCommunity
DISPLAY_NAME = SynoCli File Tools
Expand All @@ -34,13 +34,19 @@ DEPENDS += cross/micro cross/fzf
OPTIONAL_DESC := $(OPTIONAL_DESC)", micro (editor), fzf (fuzzy finder)"
endif

ifneq ($(findstring $(ARCH), $(OLD_PPC_ARCHS)),$(ARCH))
DEPENDS += cross/ripgrep
OPTIONAL_DESC := $(OPTIONAL_DESC)", rg \(ripgrep\)"
endif


# activate additional features for pcre2grep and pcre2test
PCRE2_CLI_FULL=1
PCRE2_CLI_FULL = 1
export PCRE2_CLI_FULL

DESCRIPTION = "SynoCli File Tools provides a set of small command-line utilities: less, tree, ncdu, jdupes, fdupes, rhash, mc \(midnight commander\), nano, file, detox, pcre2, zstd, lzip, plzip$(OPTIONAL_DESC)."
DESCRIPTION = "SynoCli File Tools provides a set of small command-line utilities: less, tree, ncdu, jdupes, fdupes, rhash, mc \(midnight commander\), nano, file, detox, pcre2, zstd, lzip, plzip, detox$(OPTIONAL_DESC)."
STARTABLE = no
CHANGELOG = "1. Add micro (editor)<br/>2. Add Lzip and Plzip<br/>3. Add fzf (fuzzy finder)<br/>4. Update mc to version 4.8.26<br/>Fix rmlint and zstd."
CHANGELOG = "1. Add rg (ripgrep)."

HOMEPAGE = https://github.com/SynoCommunity/spksrc/wiki/FAQ-SynoCliFile
LICENSE = Each tool is licensed under it's respective license.
Expand All @@ -61,6 +67,7 @@ SPK_COMMANDS += bin/lzip bin/plzip
SPK_COMMANDS += bin/fdupes
SPK_COMMANDS += bin/micro
SPK_COMMANDS += bin/fzf
SPK_COMMANDS += bin/rg

SPK_COMMANDS += bin/rhash
SPK_COMMANDS += bin/ed2k-link
Expand Down

0 comments on commit bab9528

Please sign in to comment.