Skip to content

Commit 233a86b

Browse files
committed
feat: Add initial support for Rust bindings with TypeDesc
Signed-off-by: Scott Wilson <[email protected]>
1 parent 5707dea commit 233a86b

File tree

15 files changed

+3059
-1
lines changed

15 files changed

+3059
-1
lines changed

.github/workflows/build-steps.yml

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -68,6 +68,8 @@ on:
6868
type: string
6969
nametag:
7070
type: string
71+
rust:
72+
type: string
7173
secrets:
7274
PASSED_GITHUB_TOKEN:
7375
required: false
@@ -155,6 +157,15 @@ jobs:
155157
if: inputs.clang_format == '1'
156158
shell: bash
157159
run: src/build-scripts/run-clang-format.bash
160+
- name: Rust Install Toolchain
161+
if: inputs.rust == '1'
162+
uses: dtolnay/rust-toolchain@4305c38b25d97ef35a8ad1f985ccf2d2242004f2 # stable
163+
- name: Rust Test
164+
if: inputs.rust == '1'
165+
shell: bash
166+
env:
167+
OIIO_CXX_STANDARD: c++${{inputs.cxx_std}}
168+
run: src/build-scripts/ci-rust-test.bash
158169
- name: Code coverage
159170
if: inputs.coverage == '1'
160171
run: src/build-scripts/ci-coverage.bash

.github/workflows/ci.yml

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -280,6 +280,7 @@ jobs:
280280
ctest_test_timeout: ${{ matrix.ctest_test_timeout }}
281281
coverage: ${{ matrix.coverage || 0 }}
282282
sonar: ${{ matrix.sonar || 0 }}
283+
rust: ${{ matrix.rust || 0 }}
283284
strategy:
284285
fail-fast: false
285286
matrix:
@@ -293,6 +294,7 @@ jobs:
293294
fmt_ver: 10.1.1
294295
pybind11_ver: v2.10.0
295296
setenvs: PUGIXML_VERSION=v1.13
297+
rust: 1
296298
- desc: VFX2023 icc/C++17 py3.10 exr3.1 ocio2.1 qt5.15
297299
nametag: linux-vfx2023.icc
298300
runner: ubuntu-latest
@@ -307,6 +309,7 @@ jobs:
307309
OIIO_EXTRA_CPP_ARGS="-fp-model=precise"
308310
FREETYPE_VERSION=VER-2-13-0
309311
DISABLE_libuhdr=1
312+
rust: 1
310313
# For icc, use fp-model precise to eliminate needless LSB errors
311314
# that make test results differ from other platforms.
312315
- desc: VFX2023 icx/C++17 py3.10 exr3.1 ocio2.2 qt5.15
@@ -323,6 +326,7 @@ jobs:
323326
xOPENCOLORIO_CXX=g++
324327
UHDR_CMAKE_C_COMPILER=gcc
325328
UHDR_CMAKE_CXX_COMPILER=g++
329+
rust: 1
326330
# Building libuhdr with icx results in test failures
327331
# so we force using gcc/g++.
328332
- desc: VFX2024 gcc11/C++17 py3.11 exr3.2 ocio2.3
@@ -335,6 +339,7 @@ jobs:
335339
pybind11_ver: v2.12.0
336340
benchmark: 1
337341
setenvs: PUGIXML_VERSION=v1.14
342+
rust: 1
338343
- desc: VFX2024 clang/C++17 py3.11 exr3.2 ocio2.3
339344
nametag: linux-vfx2024.clang
340345
runner: ubuntu-latest
@@ -347,6 +352,7 @@ jobs:
347352
pybind11_ver: v2.12.0
348353
benchmark: 1
349354
setenvs: PUGIXML_VERSION=v1.14
355+
rust: 1
350356
- desc: VFX2025 gcc11/C++17 py3.11 exr3.3 ocio2.4
351357
nametag: linux-vfx2025
352358
runner: ubuntu-latest
@@ -456,7 +462,7 @@ jobs:
456462
FREETYPE_VERSION=master
457463
QT_VERSION=0 INSTALL_OPENCV=0
458464
# The installed OpenVDB has a TLS conflict with Python 3.8
459-
# Disabling the `apt-get update` in gh-installdeps.bash
465+
# Disabling the `apt-get update` in gh-installdeps.bash
460466
# addresses a job killing problem in the GHA Ubuntu
461467
# 24.04 runners that cropped up circa May 29 2024. Maybe
462468
# it will be fixed and we can do the update again later?
@@ -548,6 +554,7 @@ jobs:
548554
ctest_test_timeout: ${{ matrix.ctest_test_timeout || '800' }}
549555
coverage: ${{ matrix.coverage || 0 }}
550556
sonar: ${{ matrix.sonar || 0 }}
557+
rust: ${{ matrix.rust || 0 }}
551558
strategy:
552559
fail-fast: false
553560
matrix:
@@ -563,13 +570,15 @@ jobs:
563570
ctest_test_timeout: 1200
564571
setenvs: export MACOSX_DEPLOYMENT_TARGET=12.0
565572
benchmark: 1
573+
rust: 1
566574
- desc: MacOS-14-ARM aclang15/C++20/py3.12
567575
runner: macos-14
568576
nametag: macos14-arm-py312
569577
cc_compiler: clang
570578
cxx_compiler: clang++
571579
cxx_std: 20
572580
python_ver: "3.12"
581+
rust: 1
573582
- desc: MacOS-15-ARM aclang16/C++20/py3.13
574583
runner: macos-15
575584
nametag: macos15-arm-py313
@@ -578,6 +587,7 @@ jobs:
578587
cxx_std: 20
579588
python_ver: "3.13"
580589
benchmark: 1
590+
rust: 1
581591

582592

583593
#
@@ -614,6 +624,7 @@ jobs:
614624
ctest_test_timeout: ${{ matrix.ctest_test_timeout }}
615625
coverage: ${{ matrix.coverage || 0 }}
616626
sonar: ${{ matrix.sonar || 0 }}
627+
rust: ${{ matrix.rust || 0 }}
617628
strategy:
618629
fail-fast: false
619630
matrix:
@@ -625,13 +636,15 @@ jobs:
625636
generator: "Visual Studio 16 2019"
626637
python_ver: "3.9"
627638
setenvs: export OPENIMAGEIO_PYTHON_LOAD_DLLS_FROM_PATH=1
639+
rust: 1
628640
- desc: Windows-2022 VS2022
629641
runner: windows-2022
630642
nametag: windows-2022
631643
vsver: 2022
632644
generator: "Visual Studio 17 2022"
633645
python_ver: "3.9"
634646
setenvs: export OPENIMAGEIO_PYTHON_LOAD_DLLS_FROM_PATH=1
647+
rust: 1
635648
- desc: Windows-2025 VS2022
636649
runner: windows-2025
637650
nametag: windows-2025
@@ -640,3 +653,4 @@ jobs:
640653
python_ver: "3.9"
641654
setenvs: export OPENIMAGEIO_PYTHON_LOAD_DLLS_FROM_PATH=1
642655
benchmark: 1
656+
rust: 1
Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
#!/usr/bin/env bash
2+
3+
# Copyright Contributors to the OpenImageIO project.
4+
# SPDX-License-Identifier: Apache-2.0
5+
# https://github.com/AcademySoftwareFoundation/OpenImageIO
6+
7+
# Important: set -ex causes this whole script to terminate with error if
8+
# any command in it fails. This is crucial for CI tests.
9+
# (Though we let it run all the way through for code coverage workflows.)
10+
if [[ "${CODECOV}" == "" ]]; then
11+
set -ex
12+
fi
13+
14+
export LD_LIBRARY_PATH=$LD_LIBRARY_PATH:$OpenImageIO_ROOT/lib
15+
export PKG_CONFIG_PATH=$PKG_CONFIG_PATH:$OpenImageIO_ROOT/lib/pkgconfig
16+
17+
# TEST
18+
echo TEST
19+
cat $OpenImageIO_ROOT/lib/pkgconfig/OpenImageIO.pc
20+
echo END TEST
21+
# END TEST
22+
23+
echo "Using C++ STD ${OIIO_CXX_STANDARD}"
24+
25+
echo "Running Rust oiio-sys tests"
26+
27+
pushd src/rust/oiio-sys
28+
time cargo test --all-features
29+
popd
30+
31+
echo "Running Rust oiio tests"
32+
33+
pushd src/rust
34+
time cargo test --all-features
35+
popd

src/rust/.gitignore

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

src/rust/Cargo.toml

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
[package]
2+
name = "oiio"
3+
version = "0.1.0"
4+
edition = "2021"
5+
description = "High-level OpenImageIO bindings over oiio-sys"
6+
documentation = "https://docs.rs/oiio"
7+
authors = [
8+
"Scott Wilson <[email protected]>",
9+
"David Aguilar <[email protected]>",
10+
]
11+
license = "Apache-2.0"
12+
keywords = ["graphics", "images", "render", "texture", "vfx"]
13+
categories = ["graphics", "multimedia::images", "rendering::data-formats"]
14+
readme = "README.md"
15+
homepage = "https://github.com/AcademySoftwareFoundation/OpenImageIO"
16+
repository = "https://github.com/AcademySoftwareFoundation/OpenImageIO.git"
17+
18+
[workspace]
19+
members = ["oiio-sys"]
20+
21+
[dependencies]
22+
oiio-sys = { path = "oiio-sys", version = "0.1.0" }
23+
thiserror = "2.0.12"
24+
25+
[dev-dependencies]
26+
proptest = "1.6.0"
27+
proptest-derive = "0.5.1"
28+
29+
# The docs are the same across all platforms so we only need to build once.
30+
[package.metadata.docs.rs]
31+
targets = ["x86_64-unknown-linux-gnu"]
32+
rustc-args = ["--cfg", "docsrs"]
33+
34+
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html

src/rust/oiio-sys/.clang-format

Lines changed: 130 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,130 @@
1+
Language: Cpp
2+
BasedOnStyle: WebKit
3+
4+
AccessModifierOffset: -4
5+
AlignAfterOpenBracket: Align
6+
AlignConsecutiveAssignments: true
7+
#AlignConsecutiveAssignments: Consecutive
8+
#AlignConsecutiveBitFields: Consecutive
9+
AlignConsecutiveDeclarations: false
10+
#AlignConsecutiveDeclarations: None
11+
AlignEscapedNewlines: Left
12+
AlignOperands: true
13+
AlignTrailingComments: true
14+
AllowAllArgumentsOnNextLine: true
15+
AllowAllConstructorInitializersOnNextLine: true
16+
AllowAllParametersOfDeclarationOnNextLine: false
17+
AllowShortBlocksOnASingleLine: true
18+
AllowShortCaseLabelsOnASingleLine: true
19+
AllowShortFunctionsOnASingleLine: All
20+
AllowShortLambdasOnASingleLine: All
21+
AllowShortIfStatementsOnASingleLine: Never
22+
AllowShortLoopsOnASingleLine: false
23+
AlwaysBreakAfterDefinitionReturnType: None
24+
AlwaysBreakAfterReturnType: TopLevel
25+
AlwaysBreakBeforeMultilineStrings: false
26+
AlwaysBreakTemplateDeclarations: MultiLine
27+
BinPackArguments: true
28+
BinPackParameters: true
29+
BraceWrapping:
30+
AfterCaseLabel: false
31+
AfterClass: false
32+
AfterControlStatement: false
33+
AfterEnum: false
34+
AfterFunction: true
35+
AfterNamespace: false
36+
AfterObjCDeclaration: false
37+
AfterStruct: false
38+
AfterUnion: false
39+
AfterExternBlock: false
40+
BeforeCatch: false
41+
BeforeElse: false
42+
IndentBraces: false
43+
SplitEmptyFunction: false
44+
SplitEmptyRecord: false
45+
SplitEmptyNamespace: false
46+
BreakBeforeBinaryOperators: All
47+
BreakBeforeBraces: WebKit
48+
BreakBeforeInheritanceComma: false
49+
BreakInheritanceList: BeforeColon
50+
BreakBeforeTernaryOperators: true
51+
BreakConstructorInitializersBeforeComma: false
52+
BreakConstructorInitializers: BeforeComma
53+
BreakAfterJavaFieldAnnotations: false
54+
BreakStringLiterals: false
55+
ColumnLimit: 80
56+
CommentPragmas: "^ IWYU pragma:"
57+
CompactNamespaces: false
58+
ConstructorInitializerAllOnOneLineOrOnePerLine: false
59+
ConstructorInitializerIndentWidth: 4
60+
ContinuationIndentWidth: 4
61+
Cpp11BracedListStyle: false
62+
DerivePointerAlignment: false
63+
DisableFormat: false
64+
ExperimentalAutoDetectBinPacking: false
65+
FixNamespaceComments: true
66+
ForEachMacros:
67+
- foreach
68+
- Q_FOREACH
69+
- BOOST_FOREACH
70+
IncludeBlocks: Preserve
71+
IncludeCategories:
72+
- Regex: '^"(llvm|llvm-c|clang|clang-c)/'
73+
Priority: 2
74+
- Regex: '^(<|"(gtest|gmock|isl|json)/)'
75+
Priority: 3
76+
- Regex: ".*"
77+
Priority: 1
78+
IncludeIsMainRegex: "(Test)?$"
79+
IndentCaseLabels: false
80+
IndentExternBlock: NoIndent
81+
IndentPPDirectives: AfterHash
82+
IndentWidth: 4
83+
IndentWrappedFunctionNames: false
84+
JavaScriptQuotes: Leave
85+
JavaScriptWrapImports: true
86+
KeepEmptyLinesAtTheStartOfBlocks: false
87+
MacroBlockBegin: ""
88+
MacroBlockEnd: ""
89+
MaxEmptyLinesToKeep: 3
90+
NamespaceIndentation: Inner
91+
ObjCBinPackProtocolList: Auto
92+
ObjCBlockIndentWidth: 4
93+
ObjCSpaceAfterProperty: true
94+
ObjCSpaceBeforeProtocolList: true
95+
PenaltyBreakAssignment: 40
96+
PenaltyBreakBeforeFirstCallParameter: 100
97+
PenaltyBreakComment: 300
98+
PenaltyBreakFirstLessLess: 120
99+
PenaltyBreakString: 1000
100+
PenaltyBreakTemplateDeclaration: 10
101+
PenaltyExcessCharacter: 75
102+
PenaltyReturnTypeOnItsOwnLine: 50
103+
PointerAlignment: Left
104+
ReflowComments: false
105+
SortIncludes: true
106+
SortUsingDeclarations: true
107+
SpaceAfterCStyleCast: false
108+
SpaceAfterLogicalNot: false
109+
SpaceAfterTemplateKeyword: false
110+
SpaceBeforeAssignmentOperators: true
111+
SpaceBeforeCpp11BracedList: true
112+
SpaceBeforeCtorInitializerColon: true
113+
SpaceBeforeInheritanceColon: true
114+
SpaceBeforeParens: ControlStatements
115+
SpaceBeforeRangeBasedForLoopColon: true
116+
SpaceInEmptyBlock: false
117+
SpaceInEmptyParentheses: false
118+
SpacesBeforeTrailingComments: 2
119+
SpacesInAngles: false
120+
SpacesInContainerLiterals: true
121+
SpacesInCStyleCastParentheses: false
122+
SpacesInParentheses: false
123+
SpacesInSquareBrackets: false
124+
Standard: c++17
125+
StatementMacros:
126+
- Q_UNUSED
127+
- QT_REQUIRE_VERSION
128+
TabWidth: 8
129+
UseTab: Never
130+
#...

src/rust/oiio-sys/.clang-tidy

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
Checks: "-*,clang-analyzer-security*"
2+
WarningsAsErrors: ""
3+
HeaderFilterRegex: '(OpenImageIO/[a-zA-Z0-9_]+\.h)|(imageio)|(oiio)|(iv/)|(_pvt\.h)'
4+
AnalyzeTemporaryDtors: false
5+
User: lg
6+
CheckOptions:
7+
- key: modernize-use-nullptr.NullMacros
8+
value: "NULL"
9+
- key: modernize-use-emplace.SmartPointers
10+
value: "OIIO::intrusive_ptr"

src/rust/oiio-sys/Cargo.toml

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
[package]
2+
name = "oiio-sys"
3+
version = "0.1.0"
4+
edition = "2021"
5+
description = "Rust sys bindings for OpenImageIO https://github.com/AcademySoftwareFoundation/OpenImageIO"
6+
documentation = "https://docs.rs/oiio-sys"
7+
authors = [
8+
"Scott Wilson <[email protected]>",
9+
"David Aguilar <[email protected]>",
10+
]
11+
license = "Apache-2.0"
12+
keywords = ["graphics", "images", "render", "texture", "vfx"]
13+
categories = ["graphics", "multimedia::images", "rendering::data-formats"]
14+
readme = "README.md"
15+
homepage = "https://github.com/AcademySoftwareFoundation/OpenImageIO"
16+
repository = "https://github.com/AcademySoftwareFoundation/OpenImageIO.git"
17+
links = "OpenImageIO"
18+
19+
[dependencies]
20+
cxx = { version = "1.0.158", features = ["c++17"] }
21+
22+
[build-dependencies]
23+
anyhow = "1.0.98"
24+
cxx-build = "1.0.158"
25+
pkg-config = "0.3.32"
26+
27+
[dev-dependencies]
28+
proptest = "1.6.0"
29+
proptest-derive = "0.5.1"
30+
31+
# The docs are the same across all platforms so we only need to build once.
32+
[package.metadata.docs.rs]
33+
targets = ["x86_64-unknown-linux-gnu"]
34+
rustc-args = ["--cfg", "docsrs"]
35+
36+
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html

0 commit comments

Comments
 (0)