-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #1 from peccu/rust
Switch Nodejs to Rust
- Loading branch information
Showing
37 changed files
with
2,267 additions
and
3,300 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
# See here for image contents: https://github.com/microsoft/vscode-dev-containers/tree/v0.238.1/containers/rust/.devcontainer/base.Dockerfile | ||
|
||
# [Choice] Debian OS version (use bullseye on local arm64/Apple Silicon): buster, bullseye | ||
ARG VARIANT="buster" | ||
FROM mcr.microsoft.com/vscode/devcontainers/rust:0-${VARIANT} | ||
|
||
# [Optional] Uncomment this section to install additional packages. | ||
# RUN apt-get update && export DEBIAN_FRONTEND=noninteractive \ | ||
# && apt-get -y install --no-install-recommends <your-package-list-here> | ||
|
||
# based on https://github.com/schrosis/rust-template-for-vscode-remotecontainers | ||
RUN rustup component add rls rust-analysis rust-src rustfmt clippy \ | ||
&& cargo install cargo-edit cargo-watch |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,59 @@ | ||
// For format details, see https://aka.ms/devcontainer.json. For config options, see the README at: | ||
// https://github.com/microsoft/vscode-dev-containers/tree/v0.238.1/containers/rust | ||
{ | ||
"name": "Rust", | ||
"build": { | ||
"dockerfile": "Dockerfile", | ||
"args": { | ||
// Use the VARIANT arg to pick a Debian OS version: buster, bullseye | ||
// Use bullseye when on local on arm64/Apple Silicon. | ||
"VARIANT": "buster" | ||
} | ||
}, | ||
"runArgs": [ | ||
"--init", | ||
"--cap-add=SYS_PTRACE", | ||
"--security-opt", | ||
"seccomp=unconfined" | ||
], | ||
|
||
// Configure tool-specific properties. | ||
"customizations": { | ||
// Configure properties specific to VS Code. | ||
"vscode": { | ||
// Set *default* container specific settings.json values on container create. | ||
"settings": { | ||
"lldb.executable": "/usr/bin/lldb", | ||
// VS Code don't watch files under ./target | ||
"files.watcherExclude": { | ||
"**/target/**": true | ||
}, | ||
"rust-analyzer.checkOnSave.command": "clippy" | ||
}, | ||
|
||
// Add the IDs of extensions you want installed when the container is created. | ||
"extensions": [ | ||
"vadimcn.vscode-lldb", | ||
"mutantdino.resourcemonitor", | ||
"rust-lang.rust-analyzer", | ||
"tamasfe.even-better-toml", | ||
"serayuzgur.crates" | ||
] | ||
} | ||
}, | ||
|
||
// Use 'forwardPorts' to make a list of ports inside the container available locally. | ||
// "forwardPorts": [], | ||
|
||
// Use 'postCreateCommand' to run commands after the container is created. | ||
// "postCreateCommand": "rustc --version", | ||
|
||
// Comment out to connect as root instead. More info: https://aka.ms/vscode-remote/containers/non-root. | ||
"remoteUser": "vscode", | ||
"features": { | ||
"git": "latest", | ||
"docker-in-docker": { | ||
"version": "latest" | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -104,3 +104,5 @@ dist | |
.tern-port | ||
|
||
public/images/**~ | ||
|
||
/cargo |
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,223 @@ | ||
# The way this works is the following: | ||
# | ||
# The create-release job runs purely to initialize the GitHub release itself | ||
# and to output upload_url for the following job. | ||
# | ||
# The build-release job runs only once create-release is finished. It gets the | ||
# release upload URL from create-release job outputs, then builds the release | ||
# executables for each supported platform and attaches them as release assets | ||
# to the previously created release. | ||
# | ||
# The key here is that we create the release only once. | ||
# | ||
# Reference: | ||
# https://eugene-babichenko.github.io/blog/2020/05/09/github-actions-cross-platform-auto-releases/ | ||
|
||
name: release | ||
on: | ||
push: | ||
# Enable when testing release infrastructure on a branch. | ||
# branches: | ||
# - rust | ||
tags: | ||
- "[0-9]+.[0-9]+.[0-9]+" | ||
jobs: | ||
create-release: | ||
name: create-release | ||
runs-on: ubuntu-latest | ||
# env: | ||
# # Set to force version number, e.g., when no tag exists. | ||
# APP_VERSION: TEST-0.0.12 | ||
outputs: | ||
upload_url: ${{ steps.release.outputs.upload_url }} | ||
app_version: ${{ env.APP_VERSION }} | ||
pj_name: ${{ env.PJ_NAME }} | ||
steps: | ||
- name: Get the release version from the tag | ||
shell: bash | ||
if: env.APP_VERSION == '' | ||
run: | | ||
# Apparently, this is the right way to get a tag name. Really? | ||
# | ||
# See: https://github.community/t5/GitHub-Actions/How-to-get-just-the-tag-name/m-p/32167/highlight/true#M1027 | ||
echo "APP_VERSION=${GITHUB_REF#refs/tags/}" >> $GITHUB_ENV | ||
echo "version is: ${{ env.APP_VERSION }}" | ||
- name: Get project name from github env | ||
shell: bash | ||
run: | | ||
echo "PJ_NAME=${GITHUB_REPOSITORY#$GITHUB_REPOSITORY_OWNER/}" >> $GITHUB_ENV | ||
- name: Create GitHub release | ||
id: release | ||
uses: actions/create-release@v1 | ||
env: | ||
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} | ||
with: | ||
tag_name: ${{ env.APP_VERSION }} | ||
release_name: ${{ env.APP_VERSION }} | ||
|
||
build-release: | ||
name: build-release | ||
needs: ['create-release'] | ||
runs-on: ${{ matrix.os }} | ||
env: | ||
# For some builds, we use cross to test on 32-bit and big-endian | ||
# systems. | ||
CARGO: cargo | ||
# When CARGO is set to CROSS, this is set to `--target matrix.target`. | ||
TARGET_FLAGS: "" | ||
# When CARGO is set to CROSS, TARGET_DIR includes matrix.target. | ||
TARGET_DIR: ./target | ||
# Emit backtraces on panics. | ||
RUST_BACKTRACE: 1 | ||
# Build static releases with PCRE2. | ||
PCRE2_SYS_STATIC: 1 | ||
# APP Binary name | ||
BIN_NAME: preview-image-folder | ||
strategy: | ||
matrix: | ||
# build: [linux, linux-arm, macos, win-msvc, win-gnu, win32-msvc] | ||
build: [linux, linux32, linux-arm, macos, win-msvc, win32-msvc] | ||
include: | ||
- build: linux | ||
os: ubuntu-18.04 | ||
rust: nightly | ||
target: x86_64-unknown-linux-musl | ||
- build: linux32 | ||
os: ubuntu-18.04 | ||
rust: nightly | ||
target: i586-unknown-linux-musl | ||
- build: linux-arm | ||
os: ubuntu-18.04 | ||
rust: nightly | ||
target: arm-unknown-linux-gnueabihf | ||
- build: macos | ||
os: macos-latest | ||
rust: nightly | ||
target: x86_64-apple-darwin | ||
- build: win-msvc | ||
os: windows-2019 | ||
rust: nightly | ||
target: x86_64-pc-windows-msvc | ||
# - build: win-gnu | ||
# os: windows-2019 | ||
# rust: nightly-x86_64-gnu | ||
# target: x86_64-pc-windows-gnu | ||
- build: win32-msvc | ||
os: windows-2019 | ||
rust: nightly | ||
target: i686-pc-windows-msvc | ||
|
||
steps: | ||
- name: Checkout repository | ||
uses: actions/checkout@v3 | ||
|
||
- name: Install packages (Ubuntu) | ||
if: matrix.os == 'ubuntu-18.04' | ||
run: | | ||
ci/ubuntu-install-packages | ||
- name: Install packages (macOS) | ||
if: matrix.os == 'macos-latest' | ||
run: | | ||
ci/macos-install-packages | ||
- name: Install Rust | ||
uses: dtolnay/rust-toolchain@v1 | ||
with: | ||
toolchain: ${{ matrix.rust }} | ||
target: ${{ matrix.target }} | ||
|
||
- name: Use Cross | ||
shell: bash | ||
run: | | ||
cargo install cross | ||
echo "CARGO=cross" >> $GITHUB_ENV | ||
echo "TARGET_FLAGS=--target ${{ matrix.target }}" >> $GITHUB_ENV | ||
echo "TARGET_DIR=./target/${{ matrix.target }}" >> $GITHUB_ENV | ||
- name: Show command used for Cargo | ||
run: | | ||
echo "cargo command is: ${{ env.CARGO }}" | ||
echo "target flag is: ${{ env.TARGET_FLAGS }}" | ||
echo "target dir is: ${{ env.TARGET_DIR }}" | ||
- name: Build release binary | ||
run: ${{ env.CARGO }} build --verbose --release ${{ env.TARGET_FLAGS }} | ||
|
||
- name: Strip release binary (linux and macos) | ||
if: matrix.build == 'linux' || matrix.build == 'macos' | ||
run: strip "target/${{ matrix.target }}/release/$BIN_NAME" | ||
|
||
- name: Strip release binary (arm) | ||
if: matrix.build == 'linux-arm' | ||
run: | | ||
docker run --rm -v \ | ||
"$PWD/target:/target:Z" \ | ||
rustembedded/cross:arm-unknown-linux-gnueabihf \ | ||
arm-linux-gnueabihf-strip \ | ||
/target/arm-unknown-linux-gnueabihf/release/$BIN_NAME | ||
- name: Build archive | ||
shell: bash | ||
run: | | ||
outdir="$(ci/cargo-out-dir "${{ env.TARGET_DIR }}")" | ||
staging="${{ needs.create-release.outputs.pj_name }}-${{ needs.create-release.outputs.app_version }}-${{ matrix.target }}" | ||
mkdir -p "$staging" | ||
# mkdir -p "$staging"/{complete,doc} | ||
# cp {README.md,COPYING,UNLICENSE,LICENSE-MIT} "$staging/" | ||
# cp {CHANGELOG.md,FAQ.md,GUIDE.md} "$staging/doc/" | ||
# cp "$outdir"/{rg.bash,rg.fish,_rg.ps1} "$staging/complete/" | ||
# cp complete/_rg "$staging/complete/" | ||
if [ "${{ matrix.os }}" = "windows-2019" ]; then | ||
cp "target/${{ matrix.target }}/release/$BIN_NAME.exe" "$staging/" | ||
7z a "$staging.zip" "$staging" | ||
echo "ASSET=$staging.zip" >> $GITHUB_ENV | ||
else | ||
# The man page is only generated on Unix systems. ¯\_(ツ)_/¯ | ||
# cp "$outdir"/$BIN_NAME.1 "$staging/doc/" | ||
cp "target/${{ matrix.target }}/release/$BIN_NAME" "$staging/" | ||
tar czf "$staging.tar.gz" "$staging" | ||
echo "ASSET=$staging.tar.gz" >> $GITHUB_ENV | ||
fi | ||
- name: Upload release archive | ||
uses: actions/[email protected] | ||
env: | ||
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} | ||
with: | ||
upload_url: ${{ needs.create-release.outputs.upload_url }} | ||
asset_path: ${{ env.ASSET }} | ||
asset_name: ${{ env.ASSET }} | ||
asset_content_type: application/octet-stream | ||
|
||
build-docker-image: | ||
name: build-docker-image | ||
needs: ['create-release', 'build-release'] | ||
runs-on: ubuntu-latest | ||
env: | ||
DOCKER_HUB_USER: peccu | ||
steps: | ||
- | ||
name: Checkout repository | ||
uses: actions/checkout@v3 | ||
- | ||
name: Set up Docker Buildx | ||
uses: docker/setup-buildx-action@v2 | ||
- | ||
name: Login to DockerHub | ||
uses: docker/login-action@v2 | ||
with: | ||
username: ${{ secrets.DOCKERHUB_USERNAME }} | ||
password: ${{ secrets.DOCKERHUB_TOKEN }} | ||
- | ||
name: Build and push | ||
uses: docker/build-push-action@v3 | ||
with: | ||
context: ./build | ||
push: true | ||
build-args: ${{ needs.create-release.outputs.app_version }} | ||
tags: | | ||
${{ env.DOCKER_HUB_USER }}/${{ needs.create-release.outputs.pj_name }}:latest | ||
${{ env.DOCKER_HUB_USER }}/${{ needs.create-release.outputs.pj_name }}:${{ needs.create-release.outputs.app_version }} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -104,3 +104,9 @@ dist | |
.tern-port | ||
|
||
*~ | ||
|
||
|
||
# Added by cargo | ||
|
||
/target | ||
/cargo |
Oops, something went wrong.