Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 18 additions & 0 deletions .clang-format
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
BasedOnStyle: LLVM
IndentWidth: 4
TabWidth: 4
UseTab: Never
ColumnLimit: 120
AllowShortFunctionsOnASingleLine: None
AllowShortIfStatementsOnASingleLine: Never
AllowShortLoopsOnASingleLine: false
BreakBeforeBraces: Allman
PointerAlignment: Left
AccessModifierOffset: -4
NamespaceIndentation: None
FixNamespaceComments: true
IncludeBlocks: Regroup
SortIncludes: true
SpaceAfterCStyleCast: true
AlignConsecutiveAssignments: false
AlignConsecutiveDeclarations: false
36 changes: 36 additions & 0 deletions .clang-tidy
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
Checks: >
-*,
bugprone-*,
-bugprone-easily-swappable-parameters,
modernize-*,
-modernize-use-trailing-return-type,
-modernize-use-ranges,
performance-*,
readability-*,
-readability-identifier-length,
-readability-magic-numbers,
-readability-function-cognitive-complexity,
readability-implicit-bool-conversion,
cppcoreguidelines-*,
-cppcoreguidelines-avoid-magic-numbers,
-cppcoreguidelines-pro-type-reinterpret-cast,
-cppcoreguidelines-pro-type-vararg,
-cppcoreguidelines-owning-memory,
-cppcoreguidelines-special-member-functions,
-cppcoreguidelines-pro-bounds-pointer-arithmetic,
-cppcoreguidelines-pro-bounds-constant-array-index,
-cppcoreguidelines-pro-bounds-array-to-pointer-decay,
-cppcoreguidelines-avoid-c-arrays,
-cppcoreguidelines-pro-type-const-cast,
-cppcoreguidelines-pro-type-member-init,
-modernize-avoid-c-arrays,
-cppcoreguidelines-pro-bounds-avoid-unchecked-container-access,
misc-*,
-misc-non-private-member-variables-in-classes,
-misc-include-cleaner,
-misc-use-anonymous-namespace,
portability-*,
-portability-avoid-pragma-once

WarningsAsErrors: ''
HeaderFilterRegex: '.*'
20 changes: 20 additions & 0 deletions .gitattributes
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
* text=auto

*.cpp text eol=lf
*.hpp text eol=lf
*.h text eol=lf
*.c text eol=lf
*.txt text eol=lf
*.md text eol=lf
*.sh text eol=lf
*.yml text eol=lf
*.yaml text eol=lf
CMakeLists.txt text eol=lf
*.cmake text eol=lf
*.json text eol=lf
module.prop text eol=lf

*.png binary
*.jpg binary
*.zip binary
*.tar.gz binary
118 changes: 118 additions & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,118 @@
name: CI

on:
push:
branches: [main]
pull_request:
branches: [main]
release:
types: [published]

jobs:
lint:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v6

- name: Install LLVM tools
uses: egor-tensin/setup-clang@v2
with:
version: 22

- name: Check formatting
run: clang-format-22 --dry-run --Werror $(find src tests -name '*.cpp' -o -name '*.hpp' -o -name '*.h')

- name: Generate compile commands for lint
run: cmake -S . -B build_lint -DCMAKE_EXPORT_COMPILE_COMMANDS=ON

- name: Run clang-tidy
run: clang-tidy-22 -p build_lint $(find src tests -name '*.cpp')

test:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v6

- name: Configure
run: cmake -S . -B build -G Ninja -DCMAKE_BUILD_TYPE=Release

- name: Build
run: cmake --build build --target procon2droid_tests

- name: Run tests
run: ctest --test-dir build --output-on-failure

build-android:
runs-on: ubuntu-latest
strategy:
matrix:
abi: [arm64-v8a, armeabi-v7a]
steps:
- uses: actions/checkout@v6

- name: Set up Android NDK
uses: nttld/setup-ndk@v1
with:
ndk-version: r27c
link-to-sdk: true

- name: Configure ${{ matrix.abi }}
run: |
cmake -S . -B build_${{ matrix.abi }} \
-G Ninja \
-DCMAKE_BUILD_TYPE=Release \
-DCMAKE_TOOLCHAIN_FILE=$ANDROID_NDK_HOME/build/cmake/android.toolchain.cmake \
-DANDROID_ABI=${{ matrix.abi }} \
-DANDROID_PLATFORM=android-24 \
-DPROCON2DROID_BUILD_TESTS=OFF

- name: Build ${{ matrix.abi }}
run: cmake --build build_${{ matrix.abi }} --target enable rumble

- name: Upload binaries
uses: actions/upload-artifact@v7
with:
name: binaries-${{ matrix.abi }}
path: |
build_${{ matrix.abi }}/src/enable
build_${{ matrix.abi }}/src/rumble

package:
needs: build-android
runs-on: ubuntu-latest
if: github.event_name == 'release'
steps:
- uses: actions/checkout@v6

- name: Download arm64 binaries
uses: actions/download-artifact@v8
with:
name: binaries-arm64-v8a
path: dist/arm64-v8a

- name: Download armv7 binaries
uses: actions/download-artifact@v8
with:
name: binaries-armeabi-v7a
path: dist/armeabi-v7a

- name: Regenerate module.prop
run: cmake -S . -B build_dummy

- name: Package Magisk module
run: |
for abi in arm64-v8a armeabi-v7a; do
mkdir -p "package_$abi/system/bin"
cp module.prop "package_$abi/"
cp service.sh "package_$abi/"
cp "dist/$abi/enable" "package_$abi/system/bin/"
cp "dist/$abi/rumble" "package_$abi/system/bin/"
chmod +x "package_$abi/system/bin/"*
zip -r "procon2droid-${GITHUB_REF_NAME}-$abi.zip" "package_$abi/"
done

- name: Upload release assets
uses: softprops/action-gh-release@v3
with:
files: |
procon2droid-*.zip
28 changes: 28 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
build/
build-debug/
build-android-arm64/
build-android-armv7/
build_android/
build_dummy/
compile_commands.json
*.o
*.obj
*.exe
*.out
*.app

# Packaging outputs
*.zip
*.tar.gz

# Generated files
module.prop

# IDE / editor
.vscode/
.idea/
*.swp
*.swo
*~
.DS_Store
Thumbs.db
44 changes: 44 additions & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
cmake_minimum_required(VERSION 3.21)

project(procon2droid
VERSION 1.1.0
DESCRIPTION "Magisk/KernelSU module for Nintendo Switch 2 Pro Controller"
LANGUAGES CXX
)

# Generate module.prop from template so version stays in sync with CMake
math(EXPR MODULE_VERSION_CODE "${PROJECT_VERSION_MAJOR} * 10000 + ${PROJECT_VERSION_MINOR} * 100 + ${PROJECT_VERSION_PATCH}")
configure_file(
"${CMAKE_SOURCE_DIR}/module.prop.in"
"${CMAKE_SOURCE_DIR}/module.prop"
@ONLY
)

set(CMAKE_CXX_STANDARD 20)
set(CMAKE_CXX_STANDARD_REQUIRED ON)
set(CMAKE_CXX_EXTENSIONS OFF)

set(CMAKE_EXPORT_COMPILE_COMMANDS ON)

if(CMAKE_SYSTEM_NAME STREQUAL "Android")
set(CMAKE_POSITION_INDEPENDENT_CODE ON)
endif()

include(FetchContent)

FetchContent_Declare(
spdlog
GIT_REPOSITORY https://github.com/gabime/spdlog.git
GIT_TAG v1.17.0
)
set(SPDLOG_USE_STD_FORMAT ON CACHE BOOL "" FORCE)
FetchContent_MakeAvailable(spdlog)

add_subdirectory(src)

option(PROCON2DROID_BUILD_TESTS "Build test suite" ON)

if(PROCON2DROID_BUILD_TESTS AND NOT CMAKE_SYSTEM_NAME STREQUAL "Android")
enable_testing()
add_subdirectory(tests)
endif()
91 changes: 91 additions & 0 deletions CMakePresets.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,91 @@
{
"version": 6,
"cmakeMinimumRequired": {
"major": 3,
"minor": 21,
"patch": 0
},
"configurePresets": [
{
"name": "native",
"hidden": false,
"description": "Native build with tests (Linux/macOS/Windows with VS+Clang)",
"generator": "Ninja",
"binaryDir": "${sourceDir}/build",
"cacheVariables": {
"CMAKE_BUILD_TYPE": "Release",
"PROCON2DROID_BUILD_TESTS": "ON"
}
},
{
"name": "native-debug",
"hidden": false,
"description": "Native debug build with tests and debug info",
"generator": "Ninja",
"binaryDir": "${sourceDir}/build-debug",
"cacheVariables": {
"CMAKE_BUILD_TYPE": "Debug",
"PROCON2DROID_BUILD_TESTS": "ON"
}
},
{
"name": "android-arm64",
"hidden": false,
"description": "Android cross-compile for arm64-v8a. Requires ANDROID_NDK_HOME env var.",
"generator": "Ninja",
"binaryDir": "${sourceDir}/build-android-arm64",
"cacheVariables": {
"CMAKE_BUILD_TYPE": "Release",
"CMAKE_TOOLCHAIN_FILE": "$env{ANDROID_NDK_HOME}/build/cmake/android.toolchain.cmake",
"ANDROID_ABI": "arm64-v8a",
"ANDROID_PLATFORM": "android-24",
"PROCON2DROID_BUILD_TESTS": "OFF"
}
},
{
"name": "android-armv7",
"hidden": false,
"description": "Android cross-compile for armeabi-v7a. Requires ANDROID_NDK_HOME env var.",
"generator": "Ninja",
"binaryDir": "${sourceDir}/build-android-armv7",
"cacheVariables": {
"CMAKE_BUILD_TYPE": "Release",
"CMAKE_TOOLCHAIN_FILE": "$env{ANDROID_NDK_HOME}/build/cmake/android.toolchain.cmake",
"ANDROID_ABI": "armeabi-v7a",
"ANDROID_PLATFORM": "android-24",
"PROCON2DROID_BUILD_TESTS": "OFF"
}
}
],
"buildPresets": [
{
"name": "native",
"configurePreset": "native",
"targets": ["procon2droid_tests"]
},
{
"name": "native-all",
"configurePreset": "native",
"description": "Build everything (tests only on native)"
},
{
"name": "android-arm64",
"configurePreset": "android-arm64",
"targets": ["enable", "rumble"]
},
{
"name": "android-armv7",
"configurePreset": "android-armv7",
"targets": ["enable", "rumble"]
}
],
"testPresets": [
{
"name": "native",
"configurePreset": "native",
"output": {
"outputOnFailure": true
}
}
]
}
Loading