Skip to content

Commit 7f7f4c7

Browse files
authored
feat: Add C bindings (#230)
1 parent 7228494 commit 7f7f4c7

24 files changed

+3040
-156
lines changed

.clang-format

Lines changed: 225 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,225 @@
1+
---
2+
Language: Cpp
3+
# BasedOnStyle: Google
4+
AccessModifierOffset: -1
5+
AlignAfterOpenBracket: Align
6+
AlignArrayOfStructures: None
7+
AlignConsecutiveMacros: None
8+
AlignConsecutiveAssignments: None
9+
AlignConsecutiveBitFields: None
10+
AlignConsecutiveDeclarations: None
11+
AlignEscapedNewlines: Left
12+
AlignOperands: Align
13+
AlignTrailingComments: true
14+
AllowAllArgumentsOnNextLine: true
15+
AllowAllParametersOfDeclarationOnNextLine: true
16+
AllowShortEnumsOnASingleLine: true
17+
AllowShortBlocksOnASingleLine: Never
18+
AllowShortCaseLabelsOnASingleLine: false
19+
AllowShortFunctionsOnASingleLine: All
20+
AllowShortLambdasOnASingleLine: All
21+
AllowShortIfStatementsOnASingleLine: WithoutElse
22+
AllowShortLoopsOnASingleLine: true
23+
AlwaysBreakAfterDefinitionReturnType: None
24+
AlwaysBreakAfterReturnType: None
25+
AlwaysBreakBeforeMultilineStrings: true
26+
AlwaysBreakTemplateDeclarations: Yes
27+
AttributeMacros:
28+
- __capability
29+
BinPackArguments: true
30+
BinPackParameters: true
31+
BraceWrapping:
32+
AfterCaseLabel: false
33+
AfterClass: false
34+
AfterControlStatement: Never
35+
AfterEnum: false
36+
AfterFunction: false
37+
AfterNamespace: false
38+
AfterObjCDeclaration: false
39+
AfterStruct: false
40+
AfterUnion: false
41+
AfterExternBlock: false
42+
BeforeCatch: false
43+
BeforeElse: false
44+
BeforeLambdaBody: false
45+
BeforeWhile: false
46+
IndentBraces: false
47+
SplitEmptyFunction: true
48+
SplitEmptyRecord: true
49+
SplitEmptyNamespace: true
50+
BreakBeforeBinaryOperators: None
51+
BreakBeforeConceptDeclarations: true
52+
BreakBeforeBraces: Attach
53+
BreakBeforeInheritanceComma: false
54+
BreakInheritanceList: BeforeColon
55+
BreakBeforeTernaryOperators: true
56+
BreakConstructorInitializersBeforeComma: false
57+
BreakConstructorInitializers: BeforeColon
58+
BreakAfterJavaFieldAnnotations: false
59+
BreakStringLiterals: true
60+
ColumnLimit: 80
61+
CommentPragmas: '^ IWYU pragma:'
62+
QualifierAlignment: Leave
63+
CompactNamespaces: false
64+
ConstructorInitializerIndentWidth: 4
65+
ContinuationIndentWidth: 4
66+
Cpp11BracedListStyle: true
67+
DeriveLineEnding: true
68+
DerivePointerAlignment: true
69+
DisableFormat: false
70+
EmptyLineAfterAccessModifier: Never
71+
EmptyLineBeforeAccessModifier: LogicalBlock
72+
ExperimentalAutoDetectBinPacking: false
73+
PackConstructorInitializers: NextLine
74+
BasedOnStyle: ''
75+
ConstructorInitializerAllOnOneLineOrOnePerLine: false
76+
AllowAllConstructorInitializersOnNextLine: true
77+
FixNamespaceComments: true
78+
ForEachMacros:
79+
- foreach
80+
- Q_FOREACH
81+
- BOOST_FOREACH
82+
IfMacros:
83+
- KJ_IF_MAYBE
84+
IncludeBlocks: Regroup
85+
IncludeCategories:
86+
- Regex: '^<ext/.*\.h>'
87+
Priority: 2
88+
SortPriority: 0
89+
CaseSensitive: false
90+
- Regex: '^<.*\.h>'
91+
Priority: 1
92+
SortPriority: 0
93+
CaseSensitive: false
94+
- Regex: '^<.*'
95+
Priority: 2
96+
SortPriority: 0
97+
CaseSensitive: false
98+
- Regex: '.*'
99+
Priority: 3
100+
SortPriority: 0
101+
CaseSensitive: false
102+
IncludeIsMainRegex: '([-_](test|unittest))?$'
103+
IncludeIsMainSourceRegex: ''
104+
IndentAccessModifiers: false
105+
IndentCaseLabels: true
106+
IndentCaseBlocks: false
107+
IndentGotoLabels: true
108+
IndentPPDirectives: None
109+
IndentExternBlock: AfterExternBlock
110+
IndentRequires: false
111+
IndentWidth: 2
112+
IndentWrappedFunctionNames: false
113+
InsertTrailingCommas: None
114+
JavaScriptQuotes: Leave
115+
JavaScriptWrapImports: true
116+
KeepEmptyLinesAtTheStartOfBlocks: false
117+
LambdaBodyIndentation: Signature
118+
MacroBlockBegin: ''
119+
MacroBlockEnd: ''
120+
MaxEmptyLinesToKeep: 1
121+
NamespaceIndentation: None
122+
ObjCBinPackProtocolList: Never
123+
ObjCBlockIndentWidth: 2
124+
ObjCBreakBeforeNestedBlockParam: true
125+
ObjCSpaceAfterProperty: false
126+
ObjCSpaceBeforeProtocolList: true
127+
PenaltyBreakAssignment: 2
128+
PenaltyBreakBeforeFirstCallParameter: 1
129+
PenaltyBreakComment: 300
130+
PenaltyBreakFirstLessLess: 120
131+
PenaltyBreakOpenParenthesis: 0
132+
PenaltyBreakString: 1000
133+
PenaltyBreakTemplateDeclaration: 10
134+
PenaltyExcessCharacter: 1000000
135+
PenaltyReturnTypeOnItsOwnLine: 200
136+
PenaltyIndentedWhitespace: 0
137+
PointerAlignment: Left
138+
PPIndentWidth: -1
139+
RawStringFormats:
140+
- Language: Cpp
141+
Delimiters:
142+
- cc
143+
- CC
144+
- cpp
145+
- Cpp
146+
- CPP
147+
- 'c++'
148+
- 'C++'
149+
CanonicalDelimiter: ''
150+
BasedOnStyle: google
151+
- Language: TextProto
152+
Delimiters:
153+
- pb
154+
- PB
155+
- proto
156+
- PROTO
157+
EnclosingFunctions:
158+
- EqualsProto
159+
- EquivToProto
160+
- PARSE_PARTIAL_TEXT_PROTO
161+
- PARSE_TEST_PROTO
162+
- PARSE_TEXT_PROTO
163+
- ParseTextOrDie
164+
- ParseTextProtoOrDie
165+
- ParseTestProto
166+
- ParsePartialTestProto
167+
CanonicalDelimiter: pb
168+
BasedOnStyle: google
169+
ReferenceAlignment: Pointer
170+
ReflowComments: true
171+
RemoveBracesLLVM: false
172+
SeparateDefinitionBlocks: Leave
173+
ShortNamespaceLines: 1
174+
SortIncludes: CaseSensitive
175+
SortJavaStaticImport: Before
176+
SortUsingDeclarations: true
177+
SpaceAfterCStyleCast: false
178+
SpaceAfterLogicalNot: false
179+
SpaceAfterTemplateKeyword: true
180+
SpaceBeforeAssignmentOperators: true
181+
SpaceBeforeCaseColon: false
182+
SpaceBeforeCpp11BracedList: false
183+
SpaceBeforeCtorInitializerColon: true
184+
SpaceBeforeInheritanceColon: true
185+
SpaceBeforeParens: ControlStatements
186+
SpaceBeforeParensOptions:
187+
AfterControlStatements: true
188+
AfterForeachMacros: true
189+
AfterFunctionDefinitionName: false
190+
AfterFunctionDeclarationName: false
191+
AfterIfMacros: true
192+
AfterOverloadedOperator: false
193+
BeforeNonEmptyParentheses: false
194+
SpaceAroundPointerQualifiers: Default
195+
SpaceBeforeRangeBasedForLoopColon: true
196+
SpaceInEmptyBlock: false
197+
SpaceInEmptyParentheses: false
198+
SpacesBeforeTrailingComments: 2
199+
SpacesInAngles: Never
200+
SpacesInConditionalStatement: false
201+
SpacesInContainerLiterals: true
202+
SpacesInCStyleCastParentheses: false
203+
SpacesInLineCommentPrefix:
204+
Minimum: 1
205+
Maximum: -1
206+
SpacesInParentheses: false
207+
SpacesInSquareBrackets: false
208+
SpaceBeforeSquareBrackets: false
209+
BitFieldColonSpacing: Both
210+
Standard: Auto
211+
StatementAttributeLikeMacros:
212+
- Q_EMIT
213+
StatementMacros:
214+
- Q_UNUSED
215+
- QT_REQUIRE_VERSION
216+
TabWidth: 8
217+
UseCRLF: false
218+
UseTab: Never
219+
WhitespaceSensitiveMacros:
220+
- STRINGIZE
221+
- PP_STRINGIZE
222+
- BOOST_PP_STRINGIZE
223+
- NS_SWIFT_NAME
224+
- CF_SWIFT_NAME
225+
...

.github/workflows/bindings.yml

Lines changed: 100 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,100 @@
1+
on:
2+
release:
3+
types:
4+
- published
5+
name: Publish bindings
6+
jobs:
7+
build-binaries:
8+
if: startsWith(github.ref_name, 'accesskit_c-v')
9+
runs-on: ${{ matrix.os }}
10+
strategy:
11+
matrix:
12+
include:
13+
- os: macOS-latest
14+
target: aarch64-apple-darwin
15+
path: macos-arm64
16+
- os: macOS-latest
17+
target: x86_64-apple-darwin
18+
path: macos-x86_64
19+
- os: windows-2019
20+
target: aarch64-pc-windows-msvc
21+
path: win-arm64-msvc
22+
- os: windows-2019
23+
target: i686-pc-windows-msvc
24+
path: win-x86-msvc
25+
- os: windows-2019
26+
target: x86_64-pc-windows-msvc
27+
path: win-x86_64-msvc
28+
- os: ubuntu-latest
29+
target: i686-pc-windows-gnu
30+
use-cross: true
31+
path: win-x86-mingw
32+
- os: ubuntu-latest
33+
target: x86_64-pc-windows-gnu
34+
use-cross: true
35+
path: win-x86_64-mingw
36+
- os: ubuntu-latest
37+
target: i686-unknown-linux-gnu
38+
use-cross: true
39+
path: linux-x86
40+
- os: ubuntu-latest
41+
target: x86_64-unknown-linux-gnu
42+
path: linux-x86_64
43+
name: cargo build
44+
steps:
45+
- uses: actions/checkout@v3
46+
47+
- name: install stable toolchain
48+
uses: actions-rs/toolchain@v1
49+
with:
50+
toolchain: stable
51+
target: ${{ matrix.target }}
52+
profile: minimal
53+
override: true
54+
55+
- name: cargo build
56+
uses: actions-rs/cargo@v1
57+
with:
58+
command: build
59+
use-cross: ${{ matrix.use-cross || false }}
60+
args: --package accesskit_c --release --target ${{ matrix.target }}
61+
62+
- name: Upload binaries
63+
uses: actions/upload-artifact@v3
64+
with:
65+
name: ${{ matrix.path }}
66+
path: |
67+
target/${{ matrix.target }}/release/*.a
68+
target/${{ matrix.target }}/release/*.dll
69+
target/${{ matrix.target }}/release/*.dylib
70+
target/${{ matrix.target }}/release/*.lib
71+
target/${{ matrix.target }}/release/*.pdb
72+
target/${{ matrix.target }}/release/*.so
73+
74+
generate-headers:
75+
if: startsWith(github.ref_name, 'accesskit_c-v')
76+
uses: AccessKit/accesskit/.github/workflows/generate-headers.yml@main
77+
78+
publish:
79+
needs: [build-binaries, generate-headers]
80+
runs-on: ubuntu-latest
81+
name: Publish
82+
steps:
83+
- uses: actions/checkout@v3
84+
85+
- uses: actions/download-artifact@v3
86+
with:
87+
path: accesskit_c/lib
88+
89+
- run: mv accesskit_c/lib/headers accesskit_c/include
90+
- run: cp -r bindings/c/examples accesskit_c/
91+
- run: cp bindings/c/*.md accesskit_c/
92+
- run: cp LICENSE* accesskit_c/
93+
- run: mv accesskit_c ${{ github.ref_name }}
94+
- run: zip -r ${{ github.ref_name }}.zip ${{ github.ref_name }}
95+
96+
- uses: AButler/upload-release-assets@v2.0
97+
with:
98+
files: ${{ github.ref_name }}.zip
99+
repo-token: ${{ secrets.GITHUB_TOKEN }}
100+
release-tag: ${{ github.ref_name }}

.github/workflows/ci.yml

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,9 +7,9 @@ on:
77
name: CI
88

99
jobs:
10-
rustfmt:
10+
fmt:
1111
runs-on: ubuntu-latest
12-
name: cargo fmt
12+
name: Check formatting
1313
steps:
1414
- uses: actions/checkout@v2
1515

@@ -27,6 +27,12 @@ jobs:
2727
command: fmt
2828
args: --all -- --check
2929

30+
- name: clang-format
31+
uses: jidicula/clang-format-action@v4.11.0
32+
with:
33+
clang-format-version: 15
34+
check-path: bindings/c
35+
3036
test:
3137
runs-on: ${{ matrix.os }}
3238
strategy:
@@ -57,3 +63,6 @@ jobs:
5763
uses: actions-rs/cargo@v1
5864
with:
5965
command: test
66+
67+
generate-headers:
68+
uses: AccessKit/accesskit/.github/workflows/generate-headers.yml@main
Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
on:
2+
workflow_call:
3+
4+
jobs:
5+
generate-headers:
6+
runs-on: ubuntu-latest
7+
name: Generate headers
8+
steps:
9+
- uses: actions/checkout@v3
10+
11+
- name: install nightly toolchain
12+
uses: actions-rs/toolchain@v1
13+
with:
14+
toolchain: nightly
15+
profile: minimal
16+
override: true
17+
18+
- uses: dtolnay/install@master
19+
with:
20+
crate: cbindgen
21+
- run: make -C bindings/c include/accesskit.h
22+
23+
- name: Upload header file
24+
uses: actions/upload-artifact@v3
25+
with:
26+
name: headers
27+
path: bindings/c/include/accesskit.h

.github/workflows/release-please.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,3 +10,4 @@ jobs:
1010
- uses: GoogleCloudPlatform/release-please-action@v3
1111
with:
1212
command: manifest
13+
token: ${{ secrets.RELEASE_PLEASE_TOKEN }}

.gitignore

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,4 +18,3 @@ target
1818

1919
#KDE
2020
.directory
21-

0 commit comments

Comments
 (0)