Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Binding the OTIO C API to Rust #4

Draft
wants to merge 3 commits into
base: main
Choose a base branch
from
Draft
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
26 changes: 26 additions & 0 deletions .devcontainer/devcontainer.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
// For format details, see https://aka.ms/devcontainer.json. For config options, see the README at:
// https://github.com/microsoft/vscode-dev-containers/tree/v0.245.2/containers/docker-existing-dockerfile
{
"name": "Existing Dockerfile",

// Sets the run context to one level up instead of the .devcontainer folder.
"context": "..",

// Update the 'dockerFile' property if you aren't using the standard 'Dockerfile' filename.
"dockerFile": "../Dockerfile",

// Use 'forwardPorts' to make a list of ports inside the container available locally.
// "forwardPorts": [],

// Uncomment the next line to run commands after the container is created - for example installing curl.
// "postCreateCommand": "apt-get update && apt-get install -y curl",

// Uncomment when using a ptrace-based debugger like C++, Go, and Rust
// "runArgs": [ "--cap-add=SYS_PTRACE", "--security-opt", "seccomp=unconfined" ],

// Uncomment to use the Docker CLI from inside the container. See https://aka.ms/vscode-remote/samples/docker-from-docker.
// "mounts": [ "source=/var/run/docker.sock,target=/var/run/docker.sock,type=bind" ],

// Uncomment to connect as a non-root user if you've added one. See https://aka.ms/vscode-remote/containers/non-root.
"remoteUser": "vfxrs"
}
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -12,3 +12,6 @@ Cargo.lock

# MSVC Windows builds of rustc generate these, which store debugging information
*.pdb

# Editor
.vscode/
15 changes: 5 additions & 10 deletions Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,10 +1,5 @@
[package]
name = "opentimelineio-bind"
version = "0.1.0"
build = "build.rs"
edition = "2021"

# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html

[dependencies]
libc = "0.2"
[workspace]
members = [
"opentimelineio",
"opentimelineio-sys",
]
66 changes: 66 additions & 0 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
FROM aswf/ci-otio:2022.2

ARG USERNAME=vfxrs
ARG USER_UID=1000
ARG USER_GID=$USER_UID

# Create the user
RUN groupadd --gid $USER_GID $USERNAME && \
useradd --uid $USER_UID --gid $USER_GID -m $USERNAME && \
echo $USERNAME ALL=\(root\) NOPASSWD:ALL > /etc/sudoers.d/$USERNAME && \
chmod 0440 /etc/sudoers.d/$USERNAME

# Install Rust
ENV RUSTUP_HOME=/usr/local/rustup \
CARGO_HOME=/usr/local/cargo \
PATH=/usr/local/cargo/bin:$PATH \
RUST_VERSION=1.63.0 \
RUST_ARCH=x86_64-unknown-linux-gnu \
RUST_ANALYZER_VERSION=2022-09-12
RUN curl -O "https://static.rust-lang.org/rustup/archive/1.25.1/${RUST_ARCH}/rustup-init" && \
chmod +x rustup-init && \
./rustup-init -y --no-modify-path --profile default --default-toolchain $RUST_VERSION --default-host ${RUST_ARCH} && \
rm rustup-init && \
chmod -R a+w $RUSTUP_HOME $CARGO_HOME && \
chgrp -R $USERNAME $RUSTUP_HOME $CARGO_HOME && \
rustup --version && \
cargo --version && \
rustc --version

# Install Rust Analyzer
RUN cd /tmp && \
git clone https://github.com/rust-lang/rust-analyzer.git && \
cd rust-analyzer && \
git checkout $RUST_ANALYZER_VERSION && \
cargo xtask install --server && \
cd ../ && \
rm -rf rust-analyzer
# Gets installed to /usr/local/cargo/bin/rust-analyzer

# # Compile OpenTimelineIO
ENV OTIO_VERSION=v0.14.1 \
COTIO_VERSION=9745fe5911d3d6495184da1ce3a6efba1d68b389
RUN mkdir -p /tmp/otio
# Compile OpenTimelineIO C bindings
RUN cd /tmp/otio && \
git clone --recurse-submodules https://github.com/OpenTimelineIO/OpenTimelineIO-C-Bindings.git && \
cd OpenTimelineIO-C-Bindings && \
git checkout $COTIO_VERSION && \
mkdir build && \
cd build && \
cmake -DCMAKE_INSTALL_PREFIX=/opt/otio -DCOTIO_SHARED_LIBS=ON ../ && \
make -j $(nproc --all) && \
make install && \
cp /tmp/otio/OpenTimelineIO-C-Bindings/include/copentimelineio/typeInfo.h /opt/otio/include/copentimelineio/typeInfo.h
# Cleanup
RUN rm -rf /tmp/otio

ENV LD_LIBRARY_PATH=/usr/local/lib:/usr/local/lib64:$LD_LIBRARY_PATH

# Add useful tools
RUN rustup component add llvm-tools-preview && \
cargo install bindgen && \
cargo install cargo-valgrind && \
cargo install cargo-llvm-cov

USER $USERNAME
8 changes: 8 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -33,3 +33,11 @@ Cloning into 'opentimelineio-bind'...
```
> cargo build
```

Testing

```bash
clear && LD_LIBRARY_PATH=$LD_LIBRARY_PATH:/opt/otio/lib:/opt/otio/lib64 cargo llvm-cov --html
clear && LD_LIBRARY_PATH=$LD_LIBRARY_PATH:/opt/otio/lib:/opt/otio/lib64 cargo valgrind test

```
25 changes: 0 additions & 25 deletions generatebindings.py

This file was deleted.

8 changes: 8 additions & 0 deletions opentimelineio-sys/Cargo.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
[package]
name = "opentimelineio-sys"
version = "0.1.0"
edition = "2021"

# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html

[dependencies]
27 changes: 27 additions & 0 deletions opentimelineio-sys/bindgen.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
import os
import subprocess
import sys
from pathlib import Path

_SYS_SRC_PATH = Path(os.path.dirname(__file__)) / "src"


def main(include_dir: Path):
rust_path = _SYS_SRC_PATH / "lib.rs"
header_path = _SYS_SRC_PATH / "lib.h"

subprocess.check_call(
[
"bindgen",
"-o",
str(rust_path),
str(header_path),
"--",
f"-I{str(include_dir)}",
],
cwd=_SYS_SRC_PATH,
)


if __name__ == "__main__":
main(Path(sys.argv[1]))
7 changes: 7 additions & 0 deletions opentimelineio-sys/build.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
fn main() {
// TODO: Use proper way to get the search paths and libraries.
println!("cargo:rustc-link-search=native=/opt/otio/lib");
println!("cargo:rustc-link-search=native=/opt/otio/lib64");
println!("cargo:rustc-link-lib=dylib=copentime");
println!("cargo:rustc-link-lib=dylib=copentimelineio");
}
56 changes: 56 additions & 0 deletions opentimelineio-sys/src/lib.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
#pragma once

// #include <cmocka.h>
// #include <cmocka_pbc.h>

#include <copentime/errorStatus.h>
#include <copentime/optionalOpenTime.h>
#include <copentime/rationalTime.h>
#include <copentime/timeRange.h>
#include <copentime/timeTransform.h>

#include <copentimelineio/any.h>
#include <copentimelineio/anyDictionary.h>
#include <copentimelineio/anyVector.h>
#include <copentimelineio/clip.h>
#include <copentimelineio/composable.h>
#include <copentimelineio/composableRetainerVector.h>
#include <copentimelineio/composableVector.h>
#include <copentimelineio/composition.h>
#include <copentimelineio/deserialization.h>
#include <copentimelineio/effect.h>
#include <copentimelineio/effectRetainerVector.h>
#include <copentimelineio/effectVector.h>
#include <copentimelineio/errorStatus.h>
#include <copentimelineio/externalReference.h>
#include <copentimelineio/freezeFrame.h>
#include <copentimelineio/gap.h>
#include <copentimelineio/generatorReference.h>
#include <copentimelineio/item.h>
#include <copentimelineio/linearTimeWarp.h>
#include <copentimelineio/mapComposableTimeRange.h>
#include <copentimelineio/marker.h>
#include <copentimelineio/markerRetainerVector.h>
#include <copentimelineio/markerVector.h>
#include <copentimelineio/mediaReference.h>
#include <copentimelineio/missingReference.h>
#include <copentimelineio/optionalPairRationalTime.h>
#include <copentimelineio/retainerPairComposable.h>
#include <copentimelineio/safely_typed_any.h>
#include <copentimelineio/serializableCollection.h>
#include <copentimelineio/serializableObject.h>
#include <copentimelineio/serializableObjectRetainerVector.h>
#include <copentimelineio/serializableObjectVector.h>
#include <copentimelineio/serializableObjectWithMetadata.h>
#include <copentimelineio/serialization.h>
#include <copentimelineio/stack.h>
#include <copentimelineio/stackAlgorithm.h>
#include <copentimelineio/timeEffect.h>
#include <copentimelineio/timeline.h>
#include <copentimelineio/track.h>
#include <copentimelineio/trackAlgorithm.h>
#include <copentimelineio/trackVector.h>
#include <copentimelineio/transition.h>
#include <copentimelineio/typeInfo.h>
#include <copentimelineio/typeRegistry.h>
#include <copentimelineio/unknownSchema.h>
Loading