Skip to content

Commit d43074b

Browse files
author
creatoy
committed
init
0 parents  commit d43074b

File tree

6 files changed

+467
-0
lines changed

6 files changed

+467
-0
lines changed

.github/workflows/deploy.yml

Lines changed: 121 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,121 @@
1+
# Action name
2+
name: Deploy
3+
4+
# 触发条件,这里是新的 tag 被 push 时触发
5+
on:
6+
push:
7+
tags:
8+
# 正则匹配 tag 格式,如 v0.1.0
9+
- "v[0-9]+.[0-9]+.[0-9]+"
10+
workflow_dispatch:
11+
12+
permissions:
13+
contents: write
14+
15+
# 实际工作
16+
jobs:
17+
build-and-upload:
18+
name: Build and Upload
19+
runs-on: ${{ matrix.os }}
20+
21+
strategy:
22+
fail-fast: false
23+
# 配置编译目标平台,这里是在 Ubuntu, MacOS, Windows 上分别编译
24+
matrix:
25+
include:
26+
- build: linux
27+
os: ubuntu-latest
28+
target: x86_64-unknown-linux-gnu
29+
features: "linux-shared-hidraw"
30+
31+
- build: macos
32+
os: macos-latest
33+
target: x86_64-apple-darwin
34+
features: ""
35+
36+
- build: windows
37+
os: windows-latest
38+
target: x86_64-pc-windows-msvc
39+
features: ""
40+
# 执行流程
41+
steps:
42+
# 克隆仓库代码
43+
- name: Clone repository
44+
uses: actions/checkout@v3
45+
46+
# 获取发布版本号
47+
- name: Get the release version from the tag
48+
shell: bash
49+
run: echo "VERSION=${GITHUB_REF#refs/tags/}" >> $GITHUB_ENV
50+
51+
# 安装 rust
52+
- name: Install rust
53+
uses: dtolnay/rust-toolchain@stable
54+
# 将上面配置的 target 传入
55+
with:
56+
targets: ${{ matrix.target }}
57+
58+
# 安装依赖库
59+
- name: Install dependencies
60+
shell: bash
61+
run: |
62+
if [ "${{ matrix.build }}" = "linux" ]; then
63+
set -eux
64+
sudo apt-get update -y
65+
sudo apt-get install -y libudev-dev
66+
# sudo apt-get install -y libusb-1.0.0-dev
67+
sudo apt-get install -y tree
68+
elif [ "${{ matrix.build }}" = "macos" ]; then
69+
brew install tree
70+
fi
71+
72+
# 构建二进制文件
73+
- name: Build binary files
74+
uses: actions-rs/cargo@v1
75+
with:
76+
# use-cross: true
77+
command: build
78+
args: --verbose --release --target ${{ matrix.target }}
79+
80+
# 打包上传二进制文件
81+
- name: Archive files
82+
shell: bash
83+
run: |
84+
bin_name="hid"
85+
bin_dir="addons/hid/bin"
86+
87+
mkdir -p "$bin_dir"
88+
if [ "${{ matrix.build }}" = "linux" ]; then
89+
bin_file="lib$bin_name.${{ matrix.build }}.so"
90+
mv target/${{ matrix.target }}/release/lib$bin_name.so $bin_dir/$bin_file
91+
elif [ "${{ matrix.build }}" = "macos" ]; then
92+
bin_file="lib$bin_name.${{ matrix.build }}.dylib"
93+
mv target/${{ matrix.target }}/release/lib$bin_name.dylib $bin_dir/$bin_file
94+
else
95+
bin_file="$bin_name.${{ matrix.build }}.dll"
96+
mv target/${{ matrix.target }}/release/$bin_name.dll $bin_dir/$bin_file
97+
fi
98+
99+
cat>$bin_dir/../$bin_name.gdextension<<EOF
100+
[configuration]
101+
entry_symbol = "hid_lib_init"
102+
compatibility_minimum = 4.0
103+
[libraries]
104+
${{ matrix.build }}.x86_64 = "bin/$bin_file"
105+
EOF
106+
107+
archive_name="$bin_name-${{ env.VERSION }}-${{ matrix.build }}"
108+
if [ "${{ matrix.build }}" = "windows" ]; then
109+
7z a "$archive_name.zip" "addons"
110+
echo "ASSET=$archive_name.zip" >> $GITHUB_ENV
111+
else
112+
tree addons
113+
tar -czvf "$archive_name.tar.gz" "addons"
114+
echo "ASSET=$archive_name.tar.gz" >> $GITHUB_ENV
115+
fi
116+
117+
- name: Release files
118+
uses: softprops/action-gh-release@v1
119+
with:
120+
files: |
121+
${{ env.ASSET }}

.gitignore

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
/target
2+
/Cargo.lock

Cargo.toml

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
[package]
2+
name = "hid"
3+
version = "0.0.1"
4+
edition = "2021"
5+
6+
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
7+
8+
[lib]
9+
crate-type = ["cdylib"]
10+
11+
[dependencies]
12+
hidapi = "2.3.3"
13+
godot = { git = "https://github.com/godot-rust/gdext", branch = "master" }

README.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
## A hidapi extension for godot
2+
3+
> WIP
4+
5+
* Written by rust with gdext

0 commit comments

Comments
 (0)