Skip to content

SEM-567: Add build for ultimaker scripts #1

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

Closed
wants to merge 2 commits into from
Closed
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
3 changes: 2 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -36,5 +36,6 @@ ui_*.h
!.git*
!.travis*

build/
_build_armhf/
_build_arm64/
*.log
26 changes: 19 additions & 7 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,14 +1,26 @@
PROJECT(framebuffer-vncserver)
CMAKE_MINIMUM_REQUIRED(VERSION 2.6)

cmake_minimum_required(VERSION 3.10...3.27)
project(framebuffer-vncserver)

FILE(GLOB SOURCES src/*.c)
ADD_EXECUTABLE(framebuffer-vncserver ${SOURCES})
INSTALL(TARGETS framebuffer-vncserver RUNTIME DESTINATION bin)

# LIBVNC
find_library(LIBVNC NAMES libvncserver vncserver)
target_link_libraries(framebuffer-vncserver ${LIBVNC})
# LIBVNC via pkg-config
find_package(PkgConfig REQUIRED)
pkg_check_modules(LIBVNC REQUIRED libvncserver)
include_directories(${LIBVNC_INCLUDE_DIRS})
link_directories(${LIBVNC_LIBRARY_DIRS})
target_link_libraries(framebuffer-vncserver ${LIBVNC_LIBRARIES})

install(PROGRAMS ${CMAKE_SOURCE_DIR}/framebuffer-vncserver.sh DESTINATION bin)

# Install systemd service file
install(FILES ${CMAKE_SOURCE_DIR}/framebuffer-vncserver.service DESTINATION lib/systemd/system)

MESSAGE( STATUS "LIBVNC: " ${LIBVNC} )
set(CPACK_GENERATOR "DEB")
set(CPACK_PACKAGE_NAME "${CPACK_PACKAGE_NAME}")
set(CPACK_PACKAGE_VERSION "${CPACK_PACKAGE_VERSION}")
set(CPACK_DEBIAN_PACKAGE_MAINTAINER "Ultimaker")
set(CPACK_PACKAGE_CONTACT "[email protected]")
set(CPACK_DEBIAN_PACKAGE_DEPENDS "libvncserver1 (>= 0.9.12)")
include(CPack)
33 changes: 33 additions & 0 deletions CPackConfig.cmake
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
set(CPACK_PACKAGE_VENDOR "Ultimaker")
set(CPACK_PACKAGE_CONTACT "Ultimaker <[email protected]>")
set(CPACK_PACKAGE_DESCRIPTION_SUMMARY "VNC server for Ultimaker 3D printers")
set(CPACK_PACKAGE_VERSION_MAJOR 9999)
set(CPACK_PACKAGE_VERSION_MINOR 99)
set(CPACK_PACKAGE_VERSION_PATCH 99)
set(CPACK_PACKAGE_PRIORITY optional)
set(CPACK_PACKAGE_SECTION "utils")
set(CPACK_GENERATOR "DEB")

find_package(Git)
if(GIT_FOUND)
execute_process(COMMAND ${GIT_EXECUTABLE} rev-parse --abbrev-ref HEAD OUTPUT_VARIABLE GIT_VERSION_BRANCH WORKING_DIRECTORY "${CMAKE_CURRENT_SOURCE_DIR}" OUTPUT_STRIP_TRAILING_WHITESPACE)
execute_process(COMMAND ${GIT_EXECUTABLE} describe --tags --dirty OUTPUT_VARIABLE GIT_VERSION_TAGS_DIRTY WORKING_DIRECTORY "${CMAKE_CURRENT_SOURCE_DIR}" OUTPUT_STRIP_TRAILING_WHITESPACE)
set(GIT_VERSION "${GIT_VERSION_TAGS_DIRTY}-${GIT_VERSION_BRANCH}")
else()
set(GIT_VERSION "Unknown")
message(WARNING "Git not found, not adding git revision description")
endif()

if("${CPACK_PACKAGE_VERSION}" STREQUAL "9999.99.99")
set(CPACK_PACKAGE_DESCRIPTION_SUMMARY "(${GIT_VERSION}) ${CPACK_PACKAGE_DESCRIPTION_SUMMARY}")
endif()

set(CPACK_DEBIAN_PACKAGE_ARCHITECTURE all)

set(CPACK_DEBIAN_PACKAGE_CONTROL_EXTRA "${CMAKE_CURRENT_SOURCE_DIR}/debian/postinst")
set(CPACK_DEBIAN_PACKAGE_DEPENDS "libvncserver1, libc6 (>= 2.28)")

# Customize the output .deb file name to include architecture
set(CPACK_PACKAGE_FILE_NAME "${CMAKE_PROJECT_NAME}-${CPACK_PACKAGE_VERSION}-${CMAKE_SYSTEM_PROCESSOR}")

include(CPack)
21 changes: 0 additions & 21 deletions Dockerfile

This file was deleted.

39 changes: 39 additions & 0 deletions build.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
#!/bin/bash

set -eu

# common directory variables
SYSCONFDIR="${SYSCONFDIR:-/etc}"
SRC_DIR="$(pwd)"
PACKAGE_NAME="${PACKAGE_NAME:-framebuffer-vncserver}"
RELEASE_VERSION="${RELEASE_VERSION:-999.999.999}"

create_debian_package()
{
make package
}

build()
{
local ARCH="${1}"
local BUILD_DIR="${SRC_DIR}/_build_${ARCH}"
mkdir -p "${BUILD_DIR}"
cd "${BUILD_DIR}" || return
rm -f ./*.deb

# Create Debian control files
mkdir -p "${BUILD_DIR}/DEBIAN"
sed -e 's|@RELEASE_VERSION@|'"${RELEASE_VERSION}"'|g' \
-e 's|@ARCH@|'"${ARCH}"'|g' \
"${SRC_DIR}/debian/control.in" > "${BUILD_DIR}/DEBIAN/control"
cp "${SRC_DIR}/debian/postinst" "${BUILD_DIR}/DEBIAN/"

echo "Building for ${ARCH} with cmake"
cmake .. -DCMAKE_INSTALL_PREFIX=/usr \
-DCPACK_PACKAGE_VERSION="${RELEASE_VERSION}" \
-DCPACK_PACKAGE_NAME="${PACKAGE_NAME}" \
-DCPACK_PACKAGE_ARCH="${ARCH}"
create_debian_package
}

build "$1"
57 changes: 57 additions & 0 deletions build_for_ultimaker.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
#!/bin/bash
#
# Copyright (C) 2025 Ultimaker B.V.
#

set -euo pipefail

SRC_DIR="$(pwd)"
RELEASE_VERSION="${RELEASE_VERSION:-9999.99.99}"
DOCKER_WORK_DIR="/build"

run_in_docker() {
docker run \
--rm \
--privileged \
-u "$(id -u):$(id -g)" \
-v "${SRC_DIR}:${DOCKER_WORK_DIR}" \
-e "RELEASE_VERSION=${RELEASE_VERSION:-}" \
-w "${DOCKER_WORK_DIR}" \
"${DOCKER_IMAGE_NAME}" \
"$@"
}

build_docker_image() {
local ARCH=$1
local DOCKERFILE="docker_env/Dockerfile.${ARCH}"
local IMAGE_NAME="framebuffer-vncserver:${ARCH}"

echo "Building Docker image for ${ARCH}..."
docker buildx build \
--platform "linux/${ARCH}" \
--load \
-f "${DOCKERFILE}" \
-t "${IMAGE_NAME}" .

DOCKER_IMAGE_NAME="${IMAGE_NAME}"
}

if ! command -V docker; then
echo "Docker not found, docker-less builds are not supported."
exit 1
fi

cleanup()
{
rm -rf "${SRC_DIR}/_build_armhf"
rm -rf "${SRC_DIR}/_build_arm64"
}

cleanup

for ARCH in armhf arm64; do
build_docker_image "${ARCH}"
run_in_docker "./build.sh" "${ARCH}"
done

exit 0
4 changes: 4 additions & 0 deletions cmake/toolchain-arm64.cmake
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
set(CMAKE_SYSTEM_NAME Linux)
set(CMAKE_SYSTEM_PROCESSOR aarch64)
set(CMAKE_C_COMPILER aarch64-linux-gnu-gcc)
set(CMAKE_CXX_COMPILER aarch64-linux-gnu-g++)
5 changes: 5 additions & 0 deletions cmake/toolchain-armhf.cmake
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
set(CMAKE_SYSTEM_NAME Linux)
set(CMAKE_SYSTEM_PROCESSOR arm)

set(CMAKE_C_COMPILER arm-linux-gnueabihf-gcc)
set(CMAKE_CXX_COMPILER arm-linux-gnueabihf-g++)
8 changes: 8 additions & 0 deletions debian/control.in
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
Package: ulti-remote-display
Version: @RELEASE_VERSION@
Architecture: @ARCH@
Maintainer: Ultimaker <[email protected]>
Section: admin
Priority: optional
Description: VNC server to allow remote connection to Okuda, including touch screen functionality
Depends: libvncserver1
3 changes: 3 additions & 0 deletions debian/postinst
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
#!/bin/sh

systemctl daemon-reload
18 changes: 18 additions & 0 deletions docker_env/Dockerfile.arm64
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
FROM arm64v8/ubuntu:20.04

ENV DEBIAN_FRONTEND=noninteractive

RUN apt-get update && apt-get install -y \
ca-certificates \
build-essential \
cmake \
ninja-build \
git \
file \
pkg-config \
libvncserver-dev \
&& apt-get clean

WORKDIR /build/framebuffer-vncserver

RUN git config --global --add safe.directory /build
26 changes: 26 additions & 0 deletions docker_env/Dockerfile.armhf
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
FROM arm32v7/ubuntu:20.04

ENV DEBIAN_FRONTEND=noninteractive

RUN apt-get update && apt-get install -y \
ca-certificates
RUN apt-get update && apt-get install -y \
build-essential \
wget \
curl \
ninja-build \
git \
file \
pkg-config \
libvncserver-dev \
software-properties-common \
gnupg \
&& wget --no-check-certificate -O - https://apt.kitware.com/keys/kitware-archive-latest.asc | apt-key add - \
&& apt-add-repository 'deb https://apt.kitware.com/ubuntu/ focal main' \
&& apt-get update \
&& apt-get install -y cmake \
&& apt-get clean

WORKDIR /build/framebuffer-vncserver

RUN git config --global --add safe.directory /build
10 changes: 10 additions & 0 deletions framebuffer-vncserver.service
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
[Unit]
Description=Framebuffer VNC Server service
[email protected]

[Service]
Type=exec
ExecStart=/usr/bin/framebuffer-vncserver.sh

[Install]
WantedBy=griffin.target
28 changes: 28 additions & 0 deletions framebuffer-vncserver.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
#!/bin/bash
#
# Copyright (C) 2025 Ultimaker B.V.
#
# Description: This script looks for which input event refers to the touch screen and starts
# a Framebuffer VNC server passing that input event as argument
#

set -eu

TOUCHSCREEN_ADDR="0038"
TOUCH_EVENT=""

for EVENT in {0..5}; do
if readlink /sys/class/input/event${EVENT} | grep -q -e "[0-5]-${TOUCHSCREEN_ADDR}"; then
TOUCH_EVENT="${EVENT}";
fi;
done;

touchscreen_input="/dev/input/event${TOUCH_EVENT}"

if [ ! -c "${touchscreen_input}" ]; then
echo "Could not find touchscreen device..."
exit 1
fi;

echo "Starting framebuffer vnc server..."
/usr/bin/framebuffer-vncserver -t "${touchscreen_input}"