Skip to content

Commit

Permalink
Merge pull request #4 from ice-lab/feat/basic-structure
Browse files Browse the repository at this point in the history
feat: basic project structure
  • Loading branch information
ClarkXia authored Nov 30, 2023
2 parents e264020 + 3ef40f2 commit bd5a592
Show file tree
Hide file tree
Showing 101 changed files with 12,840 additions and 1,873 deletions.
41 changes: 40 additions & 1 deletion .cargo/config.toml
Original file line number Diff line number Diff line change
@@ -1,3 +1,34 @@
# workaround for getting workspace root dir, reference: https://github.com/rust-lang/cargo/issues/3946
[env]
CARGO_WORKSPACE_DIR = { value = "", relative = true }

[alias]
lint = "clippy --workspace --all-targets -- --deny warnings"
# AKA `test-update`, handy cargo rst update without install `cargo-rst` binary
t = "test --no-fail-fast"
tu = "run -p cargo-rst -- update"

[target.'cfg(all())']
rustflags = [
# CLIPPY LINT SETTINGS
# This is a workaround to configure lints for the entire workspace, pending the ability to configure this via TOML.
# See: `https://github.com/rust-lang/cargo/issues/5034`
# `https://github.com/EmbarkStudios/rust-ecosystem/issues/22#issuecomment-947011395`
"-Wclippy::all", # all lints that are on by default (correctness, suspicious, style, complexity, perf)

# restriction
"-Wclippy::dbg_macro",
"-Wclippy::unwrap_in_result",
"-Wclippy::unwrap_used",
"-Wclippy::empty_drop",
"-Wclippy::exit",
"-Wclippy::empty_structs_with_brackets",
"-Wclippy::rc_buffer",
"-Wclippy::rc_mutex",
"-Wclippy::same_name_method",

"-Aclippy::default_constructed_unit_structs",
]
# To be able to run unit tests on macOS, support compilation to 'x86_64-apple-darwin'.
[target.'cfg(target_vendor = "apple")']
rustflags = ["-C", "link-args=-Wl,-undefined,dynamic_lookup"]
Expand All @@ -8,4 +39,12 @@ rustflags = ["-C", "link-args=-Wl,--warn-unresolved-symbols"]

# To be able to run unit tests on Windows, support compilation to 'x86_64-pc-windows-msvc'.
[target.'cfg(target_os = "windows")']
rustflags = ["-C", "link-args=/FORCE"]
rustflags = ["-C", "link-args=/FORCE"]

[target.x86_64-pc-windows-msvc]
rustflags = ["-C", "target-feature=+crt-static"]
[target.i686-pc-windows-msvc]
rustflags = ["-C", "target-feature=+crt-static"]

[target.x86_64-apple-darwin]
rustflags = ["-C", "link-arg=-undefined", "-C", "link-arg=dynamic_lookup"]
37 changes: 37 additions & 0 deletions .github/actions/clone-crates/action.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
name: clone crates

description: clone rspack crates for github

inputs:
repo:
default: 'web-infra-dev/rspack'
required: false
type: string
dest:
default: 'crates/.rspack_crates'
required: false
type: string
ref:
default: 'v0.4.0'
required: false
type: string
temp:
default: 'crates/.rspack_crates/.temp'
required: false
type: string

runs:
using: composite
steps:
- name: Clone Repo
uses: actions/checkout@v4
with:
repository: web-infra-dev/rspack
path: ${{ inputs.temp }}
ref: ${{ inputs.ref }}

- name: Clean up
shell: bash
run: node scripts/clean.mjs
env:
IS_GITHUB: true
58 changes: 58 additions & 0 deletions .github/actions/pnpm-cache/action.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
name: pnpm cache

description: Install Node.js with pnpm global cache

inputs:
node-version:
default: '18'
required: false
type: string
save-if:
default: false
required: false
type: boolean

env:
IS_GITHUB_RUNNER: startsWith(runner.name, 'GitHub Actions')

runs:
using: composite
steps:
- name: Install Node.js
uses: actions/setup-node@v4
with:
node-version: ${{ inputs.node-version }}
check-latest: true

# https://pnpm.io/continuous-integration#github-actions
# Uses `packageManagement` field from package.json
- name: Install pnpm
uses: pnpm/action-setup@v2
with:
dest: ${{ runner.tool_cache }}/pnpm

- name: Get pnpm store directory
id: pnpm-cache
shell: bash
run: echo "STORE_PATH=$(pnpm store path)" >> $GITHUB_OUTPUT

- name: Restore pnpm cache
id: restore
if: ${{ env.IS_GITHUB_RUNNER }}
uses: actions/cache/restore@v3
with:
path: ${{ steps.pnpm-cache.outputs.STORE_PATH }}
key: node-cache-${{ runner.os }}-pnpm-${{ hashFiles('pnpm-lock.yaml') }}
restore-keys: |
node-cache-${{ runner.os }}-pnpm-
- name: Install dependencies
shell: bash
run: pnpm install --no-frozen-lockfile

- name: Save pnpm cache
uses: actions/cache/save@v3
if: ${{ env.IS_GITHUB_RUNNER && inputs.save-if == 'true' && steps.restore.outputs.cache-hit != 'true' }}
with:
path: ${{ steps.pnpm-cache.outputs.STORE_PATH }}
key: node-cache-${{ runner.os }}-pnpm-${{ hashFiles('pnpm-lock.yaml') }}
86 changes: 86 additions & 0 deletions .github/actions/rustup/action.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,86 @@
# This action installs the minimal Rust profile and configures Swatinem/rust-cache.
#
# It is needed to install as few Rust components as possbile because
# it takes a few minutes to install some of components on Windows and Mac, especially rust-doc.

name: Rustup

description: Install Rust with cache

inputs:
# See https://rust-lang.github.io/rustup/concepts/components.html
clippy:
default: false
required: false
type: boolean
fmt:
default: false
required: false
type: boolean
docs:
default: false
required: false
type: boolean
save-cache:
default: false
required: false
type: boolean
shared-key:
default: 'check'
required: false
type: string

env:
IS_GITHUB_RUNNER: startsWith(runner.name, 'GitHub Actions')

runs:
using: composite
steps:
- name: Print Inputs
shell: bash
run: |
echo 'clippy: ${{ inputs.clippy }}'
echo 'fmt: ${{ inputs.fmt }}'
echo 'docs: ${{ inputs.docs }}'
echo 'save-cache: ${{ inputs.save-cache }}'
echo 'shared-key: ${{ inputs.shared-key }}'
- name: Remove `profile` line on MacOS
shell: bash
if: runner.os == 'macOS'
run: sed -i '' '/profile/d' rust-toolchain.toml

- name: Remove `profile` line on non-MacOS
shell: bash
if: runner.os != 'macOS'
run: sed -i '/profile/d' rust-toolchain.toml

- name: Set minimal
shell: bash
run: rustup set profile minimal

- name: Add Clippy
shell: bash
if: ${{ inputs.clippy == 'true' }}
run: rustup component add clippy

- name: Add Rustfmt
shell: bash
if: ${{ inputs.fmt == 'true' }}
run: rustup component add rustfmt

- name: Add docs
shell: bash
if: ${{ inputs.docs == 'true' }}
run: rustup component add rust-docs

- name: Install
shell: bash
run: rustup show

- name: Cache on ${{ github.ref_name }}
uses: Swatinem/rust-cache@v2
if: ${{ env.IS_GITHUB_RUNNER }}
with:
shared-key: ${{ inputs.shared-key }}
save-if: ${{ inputs.save-cache == 'true' }}
Loading

0 comments on commit bd5a592

Please sign in to comment.