Skip to content

Commit

Permalink
Merge pull request #1 from ila-embsys/dev
Browse files Browse the repository at this point in the history
GOpenHMD base
  • Loading branch information
ila-embsys authored Jan 26, 2024
2 parents 3676087 + c6b0395 commit ebc8263
Show file tree
Hide file tree
Showing 32 changed files with 2,381 additions and 1 deletion.
69 changes: 69 additions & 0 deletions .dev-env.Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,69 @@
# TODO: replace build from sources to package install
FROM mcr.microsoft.com/devcontainers/base:jammy as build-uncrustify

ARG UNCRUSTIFY_VER=0.78.1

RUN DEBIAN_FRONTEND=noninteractive apt-get update \
&& apt-get install --no-install-recommends -y \
g++ \
cmake \
make

RUN cd /usr/src \
&& wget https://codeload.github.com/uncrustify/uncrustify/zip/refs/tags/uncrustify-${UNCRUSTIFY_VER} \
-O uncrustify.zip \
&& unzip uncrustify.zip \
&& cd uncrustify-uncrustify-${UNCRUSTIFY_VER} \
&& mkdir -p build \
&& cd build \
&& cmake -DCMAKE_INSTALL_PREFIX:PATH=/usr .. \
&& cmake --build . --target install --config Release \
&& cd /usr/src \
&& rm -rf uncrustify.zip uncrustify-uncrustify-${UNCRUSTIFY_VER}

# TODO: replace build from sources to package install
FROM mcr.microsoft.com/devcontainers/base:jammy as build-vala-lint

RUN DEBIAN_FRONTEND=noninteractive apt-get update \
&& apt-get install --no-install-recommends -y \
valac \
meson \
# vala-lint build deps
libvala-0.56-dev \
libjson-glib-dev

RUN cd /usr/src \
&& wget https://codeload.github.com/vala-lang/vala-lint/zip/refs/heads/master \
-O vala-lint.zip \
&& unzip vala-lint.zip \
&& cd vala-lint-master \
&& meson build --prefix=/usr \
&& cd build \
&& ninja \
&& ninja install \
&& cd /usr/src \
&& rm -rf vala-lint.zip vala-lint-master

FROM mcr.microsoft.com/devcontainers/base:jammy

COPY --from=build-vala-lint /usr/bin/io.elementary.vala-lint /usr/bin/
COPY --from=build-vala-lint /usr/lib/x86_64-linux-gnu/libvala-linter* /usr/lib/x86_64-linux-gnu/

COPY --from=build-uncrustify /usr/bin/uncrustify /usr/bin/

RUN echo 'deb http://download.opensuse.org/repositories/home:/Prince781/xUbuntu_22.04/ /' \
| sudo tee /etc/apt/sources.list.d/home:Prince781.list \
&& curl -fsSL https://download.opensuse.org/repositories/home:Prince781/xUbuntu_22.04/Release.key \
| gpg --dearmor | tee /etc/apt/trusted.gpg.d/home_Prince781.gpg > /dev/null

RUN DEBIAN_FRONTEND=noninteractive apt-get update \
&& apt-get install --no-install-recommends -y \
valac \
gjs \
meson \
libopenhmd-dev \
gobject-introspection \
libgirepository1.0-dev \
vala-language-server
# Built newer version
# uncrustify
37 changes: 37 additions & 0 deletions .devcontainer/devcontainer.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
// For format details, see https://aka.ms/devcontainer.json. For config options, see the
// README at: https://github.com/devcontainers/templates/tree/main/src/ubuntu
{
"name": "Ubuntu",
// Or use a Dockerfile or Docker Compose file. More info: https://containers.dev/guide/dockerfile
// "image": "mcr.microsoft.com/devcontainers/base:jammy"
"build": {
// Path is relative to the devcontainer.json file.
"dockerfile": "../.dev-env.Dockerfile"
},
"customizations": {
"vscode": {
"extensions": [
"mesonbuild.mesonbuild",
"prince781.vala",
"vadimcn.vscode-lldb",
"ColinKiama.linter-vala",
"fnando.linter"
]
}
}

// Features to add to the dev container. More info: https://containers.dev/features.
// "features": {},

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

// Use 'postCreateCommand' to run commands after the container is created.
// "postCreateCommand": "uname -a",

// Configure tool-specific properties.
// "customizations": {},

// Uncomment to connect as root instead. More info: https://aka.ms/dev-containers-non-root.
// "remoteUser": "root"
}
51 changes: 51 additions & 0 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
name: tests
on: [pull_request, workflow_dispatch]

permissions:
checks: write

jobs:
test:
name: tests
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@v2
- name: Update packages
run: sudo apt-get update
- name: Install packages
uses: awalsh128/[email protected]
with:
packages: valac gjs meson libopenhmd-dev gobject-introspection libgirepository1.0-dev
version: 1.0
- name: Meson Build
uses: BSFishy/[email protected]
with:
action: build
setup-options: --prefix=${{ github.workspace }}/dist-install
- name: Meson Build 'typelib' target
run: cd build && meson compile 'gopenhmd typelib'
- name: Meson Test
uses: BSFishy/[email protected]
with:
action: test
- name: Meson Install
uses: BSFishy/[email protected]
with:
action: install
- name: Install typelib
run: install -D ./build/GOpenHMD-*.typelib -t ./dist-install/share/girepository-1.0/
- name: Publish Test Results
uses: EnricoMi/publish-unit-test-result-action@v2
if: ${{ !env.ACT }}
with:
comment_mode: off
files: |
build/meson-logs/*.junit.xml
- name: Archive artifacts
uses: actions/upload-artifact@v3
if: ${{ !env.ACT }}
with:
name: dist-install
path: |
dist-install
11 changes: 11 additions & 0 deletions .gitpod.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
image:
file: .dev-env.Dockerfile

vscode:
extensions:
- mesonbuild.mesonbuild
- prince781.vala
- vadimcn.vscode-lldb
- ColinKiama.linter-vala
- fnando.linter

43 changes: 43 additions & 0 deletions .vscode/launch.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
{
// Use IntelliSense to learn about possible attributes.
// Hover to view descriptions of existing attributes.
// For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387
"version": "0.2.0",
"configurations": [
{
"type": "lldb",
"request": "launch",
"name": "Vala : GOpenHMD : Device",
"program": "./builddir/tests/vala-gopenhmd-device",
"env": { "G_MESSAGES_DEBUG": "all" }
},
{
"type": "lldb",
"request": "launch",
"name": "Vala : GOpenHMD : Device descriptions",
"program": "./builddir/tests/vala-gopenhmd-device-descriptions",
"env": { "G_MESSAGES_DEBUG": "all" }
},
{
"type": "lldb",
"request": "launch",
"name": "Vala : GOpenHMD : Pose",
"program": "./builddir/tests/vala-gopenhmd-pose",
"env": { "G_MESSAGES_DEBUG": "all" }
},
{
"type": "lldb",
"request": "launch",
"name": "Vala : GOpenHMD : Probe",
"program": "./builddir/tests/vala-gopenhmd-pose",
"env": { "G_MESSAGES_DEBUG": "all" }
},
{
"type": "lldb",
"request": "launch",
"name": "Vala : OpenHMD : Info",
"program": "./builddir/tests/vala-openhmd-info",
"env": { "G_MESSAGES_DEBUG": "all" }
}
]
}
12 changes: 12 additions & 0 deletions .vscode/settings.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
{
"terminal.integrated.env.linux": {
"G_MESSAGES_DEBUG": "all",
"GI_TYPELIB_PATH": "${workspaceFolder}/builddir",
"LD_LIBRARY_PATH": "${workspaceFolder}/builddir",
},
"terminal.integrated.env.windows": {
"G_MESSAGES_DEBUG": "all",
"GI_TYPELIB_PATH": "${workspaceFolder}/builddir",
"LD_LIBRARY_PATH": "${workspaceFolder}/builddir",
},
}
6 changes: 5 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -1 +1,5 @@
# GOpenHMD
# GOpenHMD

[![Gitpod ready-to-code](https://img.shields.io/badge/Gitpod-ready--to--code-blue?logo=gitpod)](https://gitpod.io/#https://github.com/ila-embsys/GOpenHMD)

GOpenHMD is a wrapper of OpenHMD that uses GObject to provide language bindings by GObject introspection.
35 changes: 35 additions & 0 deletions examples/gjs.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
#!/usr/bin/env gjs

const GOpenHMD = imports.gi.GOpenHMD;


function devs_info(context) {
devs = context.enumerate()

for (var i = 0; i < devs.length; i++) {
print("Discovered device:" +
` vendor: '${devs[i].vendor}'` +
` product': '${devs[i].product}'`)
}
}


function dev_quat_info(context, dev) {
context.update();
var quat = dev.rotation_quat();
console.debug(`quat: x=${quat.x}, y=${quat.y}, z=${quat.z}, w=${quat.w}`);
GOpenHMD.sleep(0.01);
}


print(`Version: ${GOpenHMD.version().to_string()}`)

var context = new GOpenHMD.Context();

devs_info(context);

var dev = context.open_device(0, null)

for(var i = 0; i < 300; i++){
dev_quat_info(context, dev)
}
32 changes: 32 additions & 0 deletions examples/python.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
#!/usr/bin/env python3

import gi

gi.require_version('GOpenHMD', '1.0')
from gi.repository import GOpenHMD


def devs_info(context):
for dev in context.enumerate():
print(f"Discovered device: vendor '{dev.get_vendor()}'"
f", product '{dev.get_product()}'"
)


def dev_quat_info(context, dev):
context.update()
quat = dev.rotation_quat()
print(f"quat: x={quat.x} y={quat.y} z={quat.z} w={quat.w}")
GOpenHMD.sleep(0.01)


print(f"Version: {GOpenHMD.version().to_string()}")

context = GOpenHMD.Context()

devs_info(context)

dev = context.open_device(0)

for i in range(0, 300):
dev_quat_info(context, dev)
46 changes: 46 additions & 0 deletions meson.build
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
project('GOpenHMD', 'vala')

vapi_dir = meson.current_source_dir() / 'openhmd-bindings'


add_project_arguments(['--vapidir', vapi_dir], language: 'vala')

gopenhmd_dep = [
dependency('glib-2.0'),
dependency('gobject-2.0'),
dependency('openhmd'),
]

sources = files(
'src/gopenhmd.vala',
'src/context.vala',
'src/device_description.vala',
'src/device_settings.vala',
'src/device.vala',
'src/interfaces.vala',
)

subdir('tests')

gopenhmd_lib = shared_library('gopenhmd',
vala_gir: 'GOpenHMD-1.0.gir',
dependencies: gopenhmd_dep,
sources: sources,
install: true,
install_dir: [true, true, true, true])

pkg = import('pkgconfig')
pkg.generate(gopenhmd_lib)

g_ir_compiler = find_program('g-ir-compiler')

custom_target('gopenhmd typelib', command: [
g_ir_compiler,
'--shared-library=libgopenhmd',
'--output', '@OUTPUT@', '@INPUT@'
],
input: meson.current_build_dir() / 'GOpenHMD-1.0.gir',
output: 'GOpenHMD-1.0.typelib',
depends: gopenhmd_lib,
install: false,
install_dir: get_option('libdir') / 'girepository-1.0')
Loading

0 comments on commit ebc8263

Please sign in to comment.