Skip to content

Commit

Permalink
Merge remote-tracking branch 'yscope/main' into enable-exception
Browse files Browse the repository at this point in the history
# Conflicts:
#	Taskfile.yml
  • Loading branch information
junhaoliao committed Oct 5, 2024
2 parents 990fd0c + 3457e37 commit 34ca552
Show file tree
Hide file tree
Showing 10 changed files with 203 additions and 302 deletions.
51 changes: 51 additions & 0 deletions .github/workflows/lint.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
name: "lint"

on:
pull_request:
types: ["opened", "reopened", "synchronize"]
push:
schedule:
# Run daily at 00:15 UTC (the 15 is to avoid periods of high load)
- cron: "15 0 * * *"
workflow_dispatch:

permissions:
# So the workflow can cancel in-progress jobs
contents: "write"

concurrency:
group: "${{github.workflow}}-${{github.ref}}"
# Cancel in-progress jobs for efficiency
cancel-in-progress: true

jobs:
lint:
strategy:
matrix:
os: ["macos-latest", "ubuntu-latest"]
runs-on: "${{matrix.os}}"
steps:
- uses: "actions/checkout@v4"
with:
submodules: "recursive"

- uses: "actions/setup-python@v5"
with:
python-version: "3.8"

- name: "Install task"
run: "npm install -g @go-task/cli"

- if: "matrix.os == 'macos-latest'"
name: "Install coreutils (for md5sum)"
run: "brew install coreutils"

- name: "Log tool versions"
run: |-
md5sum --version
python --version
tar --version
task --version
- name: "Run lint task"
run: "task lint:check"
4 changes: 4 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,10 @@ build
cmake-build-*
dist

# Generated lint configs
.clang-format
.clang-tidy

# IDEs
.idea
.vscode
23 changes: 10 additions & 13 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -26,19 +26,16 @@ project(
# )
#endif()

# Enable compile commands by default if the generator supports it.
if(NOT DEFINED CMAKE_EXPORT_COMPILE_COMMANDS)
set(CMAKE_EXPORT_COMPILE_COMMANDS
ON
CACHE BOOL
"Enable/Disable output of compile commands during generation."
FORCE
)
endif()
if(CMAKE_EXPORT_COMPILE_COMMANDS)
# Disable response files since `clang-tidy` doesn't seem to be able to use them
set(CMAKE_CXX_USE_RESPONSE_FILE_FOR_INCLUDES OFF)
endif()
# Enable exporting compile commands
set(CMAKE_EXPORT_COMPILE_COMMANDS
ON
CACHE BOOL
"Enable/Disable output of compile commands during generation."
FORCE
)

# Disable response files since `clang-tidy` doesn't seem to be able to use them
set(CMAKE_CXX_USE_RESPONSE_FILE_FOR_INCLUDES OFF)

# Set the default build type to Release if not specified
if(NOT CMAKE_BUILD_TYPE)
Expand Down
30 changes: 27 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -28,10 +28,34 @@ To clean the build:
task clean
```

# Development
Before opening the project in an IDE, you'll first need to download and install [emscripten]:
# Contributing
Follow the steps below to develop and contribute to the project.

## Set up
Before opening the project in an IDE, run the commands below.

Download and install [emscripten]:
```shell
task emsdk
```

Set up the config files for our C++ linting tools:
```shell
task lint:cpp-configs
```

## Linting
Before submitting a pull request, ensure you’ve run the linting commands below and either fixed any
violations or suppressed the warning.

To run all linting checks:
```shell
task lint:check
```

To run all linting checks AND automatically fix any fixable issues:
```shell
task emscripten
task lint:fix
```

[bug-report]: https://github.com/y-scope/clp-ffi-js/issues/new?labels=bug&template=bug-report.yml
Expand Down
12 changes: 9 additions & 3 deletions Taskfile.yml
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
version: "3"

includes:
lint: "lint-tasks.yml"
utils: "tools/yscope-dev-utils/taskfiles/utils.yml"

vars:
Expand Down Expand Up @@ -41,16 +42,21 @@ tasks:
- "src/**/*"
generates: ["{{.CHECKSUM_FILE}}"]
deps:
# - "emsdk"
- "emsdk"
- task: "utils:validate-checksum"
vars:
CHECKSUM_FILE: "{{.CHECKSUM_FILE}}"
DATA_DIR: "{{.OUTPUT_DIR}}"
cmds:
- "mkdir -p '{{.OUTPUT_DIR}}'"
- |-
cmake -S "{{.ROOT_DIR}}" -B "{{.OUTPUT_DIR}}" -G "Unix Makefiles"
cmake --build "{{.OUTPUT_DIR}}" --parallel --target {{.G_CLP_FFI_JS_TARGET_NAMES}}
cmake \
-G "Unix Makefiles" \
-DCMAKE_TOOLCHAIN_FILE="{{.G_EMSDK_DIR}}/upstream/emscripten/cmake/Modules/Platform/\
Emscripten.cmake" \
-S "{{.ROOT_DIR}}" \
-B "{{.OUTPUT_DIR}}"
- "cmake --build '{{.OUTPUT_DIR}}' --parallel --target {{.G_CLP_FFI_JS_TARGET_NAME}}"
# This command must be last
- task: "utils:compute-checksum"
vars:
Expand Down
3 changes: 3 additions & 0 deletions lint-requirements.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
# Lock to v18.x until we can upgrade our code to meet v19's formatting standards.
clang-format~=18.1
yamllint>=1.35.1
96 changes: 96 additions & 0 deletions lint-tasks.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,96 @@
version: "3"

vars:
G_SRC_CLP_FFI_JS_DIR: "{{.ROOT_DIR}}/src/clp_ffi_js"
G_LINT_VENV_DIR: "{{.G_BUILD_DIR}}/lint-venv"

tasks:
check:
cmds:
- task: "cpp-check"
- task: "yml-check"

fix:
cmds:
- task: "cpp-fix"
- task: "yml-fix"

cpp-configs:
cmd: "{{.ROOT_DIR}}/tools/yscope-dev-utils/lint-configs/symlink-cpp-lint-configs.sh"

cpp-check:
sources: &cpp_source_files
- "{{.G_SRC_CLP_FFI_JS_DIR}}/.clang-format"
- "{{.G_SRC_CLP_FFI_JS_DIR}}/**/*.cpp"
- "{{.G_SRC_CLP_FFI_JS_DIR}}/**/*.h"
- "{{.G_SRC_CLP_FFI_JS_DIR}}/**/*.hpp"
- "{{.TASKFILE}}"
- "tools/yscope-dev-utils/lint-configs/.clang-format"
cmds:
- task: "clang-format"
vars:
FLAGS: "--dry-run"

cpp-fix:
sources: *cpp_source_files
cmds:
- task: "clang-format"
vars:
FLAGS: "-i"

yml:
aliases:
- "yml-check"
- "yml-fix"
deps: ["venv"]
cmds:
- |-
. "{{.G_LINT_VENV_DIR}}/bin/activate"
yamllint \
--config-file "{{.ROOT_DIR}}/tools/yscope-dev-utils/lint-configs/.yamllint.yml" \
--strict \
.github \
lint-tasks.yml \
Taskfile.yml
clang-format:
internal: true
requires:
vars: ["FLAGS"]
deps: ["cpp-configs", "venv"]
cmds:
- |-
. "{{.G_LINT_VENV_DIR}}/bin/activate"
find "{{.G_SRC_CLP_FFI_JS_DIR}}" \
-type f \
\( -iname "*.cpp" -o -iname "*.h" -o -iname "*.hpp" \) \
-print0 | \
xargs -0 clang-format {{.FLAGS}} -Werror
venv:
internal: true
vars:
CHECKSUM_FILE: "{{.G_BUILD_DIR}}/{{.TASK | replace \":\" \"#\"}}.md5"
OUTPUT_DIR: "{{.G_LINT_VENV_DIR}}"
sources:
- "{{.ROOT_DIR}}/Taskfile.yml"
- "{{.TASKFILE}}"
- "lint-requirements.txt"
generates: ["{{.CHECKSUM_FILE}}"]
deps:
- ":init"
- task: ":utils:validate-checksum"
vars:
CHECKSUM_FILE: "{{.CHECKSUM_FILE}}"
DATA_DIR: "{{.OUTPUT_DIR}}"
cmds:
- task: ":utils:create-venv"
vars:
LABEL: "lint"
OUTPUT_DIR: "{{.OUTPUT_DIR}}"
REQUIREMENTS_FILE: "lint-requirements.txt"
# This command must be last
- task: ":utils:compute-checksum"
vars:
DATA_DIR: "{{.OUTPUT_DIR}}"
OUTPUT_FILE: "{{.CHECKSUM_FILE}}"
Loading

0 comments on commit 34ca552

Please sign in to comment.