From a8a8d6b6b6bc5030e22017a04317fadce53966bc Mon Sep 17 00:00:00 2001 From: waltari Date: Tue, 19 May 2020 16:16:58 +0900 Subject: [PATCH] custom --- .github/workflows/CICD.yml | 342 ---------------------------------- .github/workflows/release.yml | 57 ++++++ Makefile | 50 +++++ patch.zsh | 10 + src/lib.rs | 8 +- tests/integration_tests.rs | 12 +- 6 files changed, 127 insertions(+), 352 deletions(-) delete mode 100644 .github/workflows/CICD.yml create mode 100644 .github/workflows/release.yml create mode 100644 Makefile create mode 100755 patch.zsh diff --git a/.github/workflows/CICD.yml b/.github/workflows/CICD.yml deleted file mode 100644 index 410b70b4..00000000 --- a/.github/workflows/CICD.yml +++ /dev/null @@ -1,342 +0,0 @@ -name: CICD - -env: - MIN_SUPPORTED_RUST_VERSION: "1.56.0" - CICD_INTERMEDIATES_DIR: "_cicd-intermediates" - -on: - workflow_dispatch: - pull_request: - push: - branches: - - master - tags: - - '*' - -jobs: - min_version: - name: Minimum supported rust version - runs-on: ubuntu-18.04 - steps: - - name: Checkout source code - uses: actions/checkout@v2 - - - name: Install rust toolchain (v${{ env.MIN_SUPPORTED_RUST_VERSION }}) - uses: actions-rs/toolchain@v1 - with: - toolchain: ${{ env.MIN_SUPPORTED_RUST_VERSION }} - default: true - profile: minimal # minimal component installation (ie, no documentation) - components: clippy, rustfmt - - - name: Ensure `cargo fmt` has been run - uses: actions-rs/cargo@v1 - with: - command: fmt - args: -- --check - - - name: Run clippy (on minimum supported rust version to prevent warnings we can't fix) - uses: actions-rs/cargo@v1 - with: - command: clippy - args: --locked --all-targets - - - name: Run tests - uses: actions-rs/cargo@v1 - with: - command: test - args: --locked - - build: - name: ${{ matrix.job.os }} (${{ matrix.job.target }}) - runs-on: ${{ matrix.job.os }} - strategy: - fail-fast: false - matrix: - job: - - { os: ubuntu-18.04, target: arm-unknown-linux-gnueabihf , use-cross: true } - - { os: ubuntu-18.04, target: aarch64-unknown-linux-gnu , use-cross: true } - - { os: ubuntu-18.04, target: i686-unknown-linux-gnu , use-cross: true } - - { os: ubuntu-18.04, target: i686-unknown-linux-musl , use-cross: true } - - { os: ubuntu-18.04, target: x86_64-unknown-linux-gnu } - - { os: ubuntu-18.04, target: x86_64-unknown-linux-musl , use-cross: true } - - { os: macos-10.15 , target: x86_64-apple-darwin } - # - { os: windows-2019, target: i686-pc-windows-gnu } ## disabled; error: linker `i686-w64-mingw32-gcc` not found - - { os: windows-2019, target: i686-pc-windows-msvc } - - { os: windows-2019, target: x86_64-pc-windows-gnu } - - { os: windows-2019, target: x86_64-pc-windows-msvc } - steps: - - name: Checkout source code - uses: actions/checkout@v2 - - - name: Install prerequisites - shell: bash - run: | - case ${{ matrix.job.target }} in - arm-unknown-linux-gnueabihf) sudo apt-get -y update ; sudo apt-get -y install gcc-arm-linux-gnueabihf ;; - aarch64-unknown-linux-gnu) sudo apt-get -y update ; sudo apt-get -y install gcc-aarch64-linux-gnu ;; - esac - - - name: Extract crate information - shell: bash - run: | - echo "PROJECT_NAME=$(sed -n 's/^name = "\(.*\)"/\1/p' Cargo.toml | head -n1)" >> $GITHUB_ENV - echo "PROJECT_VERSION=$(sed -n 's/^version = "\(.*\)"/\1/p' Cargo.toml | head -n1)" >> $GITHUB_ENV - echo "PROJECT_MAINTAINER=$(sed -n 's/^authors = \["\(.*\)"\]/\1/p' Cargo.toml)" >> $GITHUB_ENV - echo "PROJECT_HOMEPAGE=$(sed -n 's/^homepage = "\(.*\)"/\1/p' Cargo.toml)" >> $GITHUB_ENV - - - name: Install Rust toolchain - uses: actions-rs/toolchain@v1 - with: - toolchain: stable - target: ${{ matrix.job.target }} - override: true - profile: minimal # minimal component installation (ie, no documentation) - - - name: Show version information (Rust, cargo, GCC) - shell: bash - run: | - gcc --version || true - rustup -V - rustup toolchain list - rustup default - cargo -V - rustc -V - - - name: Build - uses: actions-rs/cargo@v1 - with: - use-cross: ${{ matrix.job.use-cross }} - command: build - args: --release --target=${{ matrix.job.target }} - - - name: Run example - uses: actions-rs/cargo@v1 - with: - use-cross: ${{ matrix.job.use-cross }} - command: run - args: --release --target=${{ matrix.job.target }} --example=simple - - - name: Strip debug information from executable - id: strip - shell: bash - run: | - # Figure out suffix of binary - EXE_suffix="" - case ${{ matrix.job.target }} in - *-pc-windows-*) EXE_suffix=".exe" ;; - esac; - - # Figure out what strip tool to use if any - STRIP="strip" - case ${{ matrix.job.target }} in - arm-unknown-linux-gnueabihf) STRIP="arm-linux-gnueabihf-strip" ;; - aarch64-unknown-linux-gnu) STRIP="aarch64-linux-gnu-strip" ;; - *-pc-windows-msvc) STRIP="" ;; - esac; - - # Setup paths - BIN_DIR="${{ env.CICD_INTERMEDIATES_DIR }}/stripped-release-bin/" - mkdir -p "${BIN_DIR}" - BIN_NAME="${{ env.PROJECT_NAME }}${EXE_suffix}" - BIN_PATH="${BIN_DIR}/${BIN_NAME}" - - # Copy the release build binary to the result location - cp "target/${{ matrix.job.target }}/release/${BIN_NAME}" "${BIN_DIR}" - - # Also strip if possible - if [ -n "${STRIP}" ]; then - "${STRIP}" "${BIN_PATH}" - fi - - # Let subsequent steps know where to find the (stripped) bin - echo ::set-output name=BIN_PATH::${BIN_PATH} - echo ::set-output name=BIN_NAME::${BIN_NAME} - - - name: Set testing options - id: test-options - shell: bash - run: | - # test only library unit tests and binary for arm-type targets - unset CARGO_TEST_OPTIONS - unset CARGO_TEST_OPTIONS ; case ${{ matrix.job.target }} in arm-* | aarch64-*) CARGO_TEST_OPTIONS="--lib --bin ${PROJECT_NAME}" ;; esac; - echo ::set-output name=CARGO_TEST_OPTIONS::${CARGO_TEST_OPTIONS} - - - name: Run tests - uses: actions-rs/cargo@v1 - with: - use-cross: ${{ matrix.job.use-cross }} - command: test - args: --target=${{ matrix.job.target }} ${{ steps.test-options.outputs.CARGO_TEST_OPTIONS}} - - - name: Setup Pandoc - uses: r-lib/actions/setup-pandoc@v2 - - - name: Generate man page - run: pandoc -s -f markdown -t man -o "doc/${{ env.PROJECT_NAME }}.1" "doc/${{ env.PROJECT_NAME }}.1.md" - - - name: Create tarball - id: package - shell: bash - run: | - PKG_suffix=".tar.gz" ; case ${{ matrix.job.target }} in *-pc-windows-*) PKG_suffix=".zip" ;; esac; - PKG_BASENAME=${PROJECT_NAME}-v${PROJECT_VERSION}-${{ matrix.job.target }} - PKG_NAME=${PKG_BASENAME}${PKG_suffix} - echo ::set-output name=PKG_NAME::${PKG_NAME} - - PKG_STAGING="${{ env.CICD_INTERMEDIATES_DIR }}/package" - ARCHIVE_DIR="${PKG_STAGING}/${PKG_BASENAME}/" - mkdir -p "${ARCHIVE_DIR}" - - # Binary - cp "${{ steps.strip.outputs.BIN_PATH }}" "$ARCHIVE_DIR" - - # Man page - cp "doc/${{ env.PROJECT_NAME }}.1" "$ARCHIVE_DIR" - - # README, LICENSE and CHANGELOG files - cp "README.md" "LICENSE-MIT" "LICENSE-APACHE" "CHANGELOG.md" "$ARCHIVE_DIR" - - # base compressed package - pushd "${PKG_STAGING}/" >/dev/null - case ${{ matrix.job.target }} in - *-pc-windows-*) 7z -y a "${PKG_NAME}" "${PKG_BASENAME}"/* | tail -2 ;; - *) tar czf "${PKG_NAME}" "${PKG_BASENAME}"/* ;; - esac; - popd >/dev/null - - # Let subsequent steps know where to find the compressed package - echo ::set-output name=PKG_PATH::"${PKG_STAGING}/${PKG_NAME}" - - - name: Create Debian package - id: debian-package - shell: bash - if: startsWith(matrix.job.os, 'ubuntu') - run: | - COPYRIGHT_YEARS="2018 - "$(date "+%Y") - DPKG_STAGING="${{ env.CICD_INTERMEDIATES_DIR }}/debian-package" - DPKG_DIR="${DPKG_STAGING}/dpkg" - mkdir -p "${DPKG_DIR}" - - DPKG_BASENAME=${PROJECT_NAME} - DPKG_CONFLICTS=${PROJECT_NAME}-musl - case ${{ matrix.job.target }} in *-musl) DPKG_BASENAME=${PROJECT_NAME}-musl ; DPKG_CONFLICTS=${PROJECT_NAME} ;; esac; - DPKG_VERSION=${PROJECT_VERSION} - - unset DPKG_ARCH - case ${{ matrix.job.target }} in - aarch64-*-linux-*) DPKG_ARCH=arm64 ;; - arm-*-linux-*hf) DPKG_ARCH=armhf ;; - i686-*-linux-*) DPKG_ARCH=i686 ;; - x86_64-*-linux-*) DPKG_ARCH=amd64 ;; - *) DPKG_ARCH=notset ;; - esac; - - DPKG_NAME="${DPKG_BASENAME}_${DPKG_VERSION}_${DPKG_ARCH}.deb" - echo ::set-output name=DPKG_NAME::${DPKG_NAME} - - # Binary - install -Dm755 "${{ steps.strip.outputs.BIN_PATH }}" "${DPKG_DIR}/usr/bin/${{ steps.strip.outputs.BIN_NAME }}" - - # Man page - install -Dm644 "doc/${{ env.PROJECT_NAME }}.1" "${DPKG_DIR}/usr/share/man/man1/${{ env.PROJECT_NAME }}.1" - gzip -n --best "${DPKG_DIR}/usr/share/man/man1/${{ env.PROJECT_NAME }}.1" - - # README and LICENSE - install -Dm644 "README.md" "${DPKG_DIR}/usr/share/doc/${DPKG_BASENAME}/README.md" - install -Dm644 "LICENSE-MIT" "${DPKG_DIR}/usr/share/doc/${DPKG_BASENAME}/LICENSE-MIT" - install -Dm644 "LICENSE-APACHE" "${DPKG_DIR}/usr/share/doc/${DPKG_BASENAME}/LICENSE-APACHE" - install -Dm644 "CHANGELOG.md" "${DPKG_DIR}/usr/share/doc/${DPKG_BASENAME}/changelog" - gzip -n --best "${DPKG_DIR}/usr/share/doc/${DPKG_BASENAME}/changelog" - - cat > "${DPKG_DIR}/usr/share/doc/${DPKG_BASENAME}/copyright" < "${DPKG_DIR}/DEBIAN/control" <> $GITHUB_ENV + + - name: Setup Rust + uses: actions-rs/toolchain@v1 + with: + toolchain: stable + target: ${{ matrix.rust-target }} + default: true + profile: minimal + + - name: Setup Pandoc + uses: r-lib/actions/setup-pandoc@v2 + + - name: Set environment variables for Apple Silicon + if: matrix.rust-target == 'aarch64-apple-darwin' + run: | + export SDKROOT=$(xcrun -sdk macosx12.1 --show-sdk-path) + [[ -n $SDKROOT ]] && echo "SDKROOT=$SDKROOT" >> $GITHUB_ENV + export MACOSX_DEPLOYMENT_TARGET=$(xcrun -sdk macosx12.1 --show-sdk-platform-version) + [[ -n $MACOSX_DEPLOYMENT_TARGET ]] && echo "MACOSX_DEPLOYMENT_TARGET=$MACOSX_DEPLOYMENT_TARGET" >> $GITHUB_ENV + + - name: Build + run: make + + - name: Release + uses: softprops/action-gh-release@v1 + with: + files: '*.tar.xz' + env: + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} diff --git a/Makefile b/Makefile new file mode 100644 index 00000000..91372319 --- /dev/null +++ b/Makefile @@ -0,0 +1,50 @@ +ifeq ($(RUST_TARGET),) + TARGET := + RELEASE_SUFFIX := +else + TARGET := $(RUST_TARGET) + RELEASE_SUFFIX := -$(TARGET) + export CARGO_BUILD_TARGET = $(RUST_TARGET) +endif + +PROJECT_NAME := hexyl + +VERSION := $(subst $\",,$(word 3,$(shell grep -m1 "^version" Cargo.toml))) +RELEASE := $(PROJECT_NAME)-$(VERSION)$(RELEASE_SUFFIX) + +DIST_DIR := dist +RELEASE_DIR := $(DIST_DIR)/$(RELEASE) +MANUAL_DIR := $(RELEASE_DIR)/manual + +BINARY := target/$(TARGET)/release/$(PROJECT_NAME) +MAN1 := doc/$(PROJECT_NAME).1 + +RELEASE_BINARY := $(RELEASE_DIR)/$(PROJECT_NAME) +MANUAL := $(MANUAL_DIR)/$(PROJECT_NAME).1 + +ARTIFACT := $(RELEASE).tar.xz + +.PHONY: all +all: $(ARTIFACT) + +$(BINARY): + RUSTFLAGS='-C link-args=-s' cargo build --locked --release + +$(MAN1): + pandoc -s -f markdown -t man -o $@ $(@).md + +$(DIST_DIR) $(RELEASE_DIR) $(MANUAL_DIR): + mkdir -p $@ + +$(RELEASE_BINARY): $(BINARY) $(RELEASE_DIR) + cp -f $< $@ + +$(MANUAL): $(MAN1) $(MANUAL_DIR) + cp -f $< $@ + +$(ARTIFACT): $(RELEASE_BINARY) $(MANUAL) + tar -C $(DIST_DIR) -Jcvf $@ $(RELEASE) + +.PHONY: clean +clean: + $(RM) -rf $(ARTIFACT) $(DIST_DIR) $(MAN1) diff --git a/patch.zsh b/patch.zsh new file mode 100755 index 00000000..735244b8 --- /dev/null +++ b/patch.zsh @@ -0,0 +1,10 @@ +#!/usr/bin/env zsh + +local -a trans=( + '\u00D7' '\u2716' + '\u2022' '\u272D' +) + +for from to ($trans); do + rg -l0 $from | xargs -0 --no-run-if-empty sd $from $to +done diff --git a/src/lib.rs b/src/lib.rs index e23bc50a..263de77c 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -61,12 +61,12 @@ impl Byte { use crate::ByteCategory::*; match self.category() { - Null => '0', + Null => '⍉', AsciiPrintable => self.0 as char, AsciiWhitespace if self.0 == 0x20 => ' ', - AsciiWhitespace => '_', - AsciiOther => '•', - NonAscii => '×', + AsciiWhitespace => '⣿', + AsciiOther => '✭', + NonAscii => '⨯', } } } diff --git a/tests/integration_tests.rs b/tests/integration_tests.rs index df076e5a..dc62fc65 100644 --- a/tests/integration_tests.rs +++ b/tests/integration_tests.rs @@ -18,7 +18,7 @@ mod basic { .success() .stdout( "┌────────┬─────────────────────────┬─────────────────────────┬────────┬────────┐\n\ - │00000000│ 30 31 32 33 34 35 36 37 ┊ 38 39 61 62 63 64 65 0a │01234567┊89abcde_│\n\ + │00000000│ 30 31 32 33 34 35 36 37 ┊ 38 39 61 62 63 64 65 0a │01234567┊89abcde⣿│\n\ └────────┴─────────────────────────┴─────────────────────────┴────────┴────────┘\n", ); } @@ -70,8 +70,8 @@ mod length { .success() .stdout( "┌────────┬─────────────────────────┬─────────────────────────┬────────┬────────┐\n\ - │00000000│ 7f 45 4c 46 02 01 01 00 ┊ 00 00 00 00 00 00 00 00 │•ELF•••0┊00000000│\n\ - │00000010│ 02 00 3e 00 01 00 00 00 ┊ 00 10 40 00 00 00 00 00 │•0>0•000┊0•@00000│\n\ + │00000000│ 7f 45 4c 46 02 01 01 00 ┊ 00 00 00 00 00 00 00 00 │✭ELF✭✭✭⍉┊⍉⍉⍉⍉⍉⍉⍉⍉│\n\ + │00000010│ 02 00 3e 00 01 00 00 00 ┊ 00 10 40 00 00 00 00 00 │✭⍉>⍉✭⍉⍉⍉┊⍉✭@⍉⍉⍉⍉⍉│\n\ └────────┴─────────────────────────┴─────────────────────────┴────────┴────────┘\n", ); } @@ -186,7 +186,7 @@ mod display_offset { .success() .stdout( "┌────────┬─────────────────────────┬─────────────────────────┬────────┬────────┐\n\ - │00c0ffee│ 30 31 32 33 34 35 36 37 ┊ 38 39 61 62 63 64 65 0a │01234567┊89abcde_│\n\ + │00c0ffee│ 30 31 32 33 34 35 36 37 ┊ 38 39 61 62 63 64 65 0a │01234567┊89abcde⣿│\n\ └────────┴─────────────────────────┴─────────────────────────┴────────┴────────┘\n", ); } @@ -203,7 +203,7 @@ mod display_offset { .success() .stdout( "┌────────┬─────────────────────────┬─────────────────────────┬────────┬────────┐\n\ - │00000030│ 02 00 3e 00 01 00 00 00 ┊ 00 10 40 00 00 00 00 00 │•0>0•000┊0•@00000│\n\ + │00000030│ 02 00 3e 00 01 00 00 00 ┊ 00 10 40 00 00 00 00 00 │✭⍉>⍉✭⍉⍉⍉┊⍉✭@⍉⍉⍉⍉⍉│\n\ └────────┴─────────────────────────┴─────────────────────────┴────────┴────────┘\n", ); } @@ -266,7 +266,7 @@ mod display_settings { .success() .stdout( "┌─────────────────────────┬─────────────────────────┬────────┬────────┐\n\ - │ 30 31 32 33 34 35 36 37 ┊ 38 39 61 62 63 64 65 0a │01234567┊89abcde_│\n\ + │ 30 31 32 33 34 35 36 37 ┊ 38 39 61 62 63 64 65 0a │01234567┊89abcde⣿│\n\ └─────────────────────────┴─────────────────────────┴────────┴────────┘\n", ); }