From 3413021d30517842271963515029685e1bd2b715 Mon Sep 17 00:00:00 2001 From: Dorota Czaplejewicz Date: Thu, 29 Aug 2019 15:34:42 +0000 Subject: [PATCH 1/2] rust: Use Cargo to build the Rust portion Pros: Ability to use Rust libraries from crates.io Problems: Need to lock library versions and document their reproducible building, either via Cargo.lock or vendoring. --- .gitlab-ci.yml | 4 ++++ Cargo.toml | 8 ++++++++ cargo.sh | 14 ++++++++++++++ debian/control | 1 + meson.build | 2 +- src/meson.build | 28 +++++++++++++++------------- 6 files changed, 43 insertions(+), 14 deletions(-) create mode 100644 Cargo.toml create mode 100644 cargo.sh diff --git a/.gitlab-ci.yml b/.gitlab-ci.yml index 79dbb366..e29afae3 100644 --- a/.gitlab-ci.yml +++ b/.gitlab-ci.yml @@ -9,6 +9,10 @@ stages: - librem5 before_script: + - apt-get -y update + - apt-get -y install wget ca-certificates gnupg + - echo "deb http://ci.puri.sm/ scratch librem5" > /etc/apt/sources.list.d/ci.list + - wget -O- https://ci.puri.sm/ci-repo.key | apt-key add - - apt-get -y update - apt-get -y build-dep . diff --git a/Cargo.toml b/Cargo.toml new file mode 100644 index 00000000..e6e1015c --- /dev/null +++ b/Cargo.toml @@ -0,0 +1,8 @@ +[package] +name = "rs" +version = "0.1.0" + +[lib] +name = "rs" +path = "src/lib.rs" +crate-type = ["staticlib"] diff --git a/cargo.sh b/cargo.sh new file mode 100644 index 00000000..3fb0c97c --- /dev/null +++ b/cargo.sh @@ -0,0 +1,14 @@ +#!/bin/sh +set -e + +export CARGO_TARGET_DIR=`pwd` +if [ ! -z ${2} ]; then + OUT_PATH=`realpath "${2}"` +fi + +cd $1 +cargo $3 -p rs + +if [ ! -z ${OUT_PATH} ]; then + cp "${CARGO_TARGET_DIR}"/debug/librs.a "${OUT_PATH}" +fi diff --git a/debian/control b/debian/control index ec86951a..ca3c4681 100644 --- a/debian/control +++ b/debian/control @@ -3,6 +3,7 @@ Section: x11 Priority: optional Maintainer: Dorota Czaplejewicz Build-Depends: + cargo, debhelper (>= 10), meson (>=0.43.0), pkg-config, diff --git a/meson.build b/meson.build index f1457d1a..9c16e90b 100644 --- a/meson.build +++ b/meson.build @@ -3,7 +3,7 @@ project( 'c', 'rust', version: '1.0.10', license: 'GPLv3', - meson_version: '>=0.49.0', + meson_version: '>=0.51.0', default_options: [ 'warning_level=1', 'buildtype=debugoptimized', diff --git a/src/meson.build b/src/meson.build index bdd161d1..69319ce6 100644 --- a/src/meson.build +++ b/src/meson.build @@ -56,25 +56,27 @@ deps = [ # dependency('libxklavier'), # FIXME remove ] -# Replacement for eekboard-server -rslib = static_library( - 'rslib', - sources: ['lib.rs'], - rust_crate_type: 'staticlib' +cargo = find_program('cargo') +cargo_script = find_program('../cargo.sh') + +rslibs = custom_target( + 'rslibs', + build_by_default: true, + build_always_stale: true, + output: ['librs.a'], + install: false, + command: [cargo_script, '@CURRENT_SOURCE_DIR@', '@OUTPUT@', 'build'] ) -rstests = executable( - 'rstests', - sources: ['lib.rs'], - rust_args: ['--test'], - install: false +test( + 'rstest', + cargo_script, + args: [meson.source_root(), '', 'test'] ) -test('rstests', rstests) - libsqueekboard = static_library('libsqueekboard', sources, - link_with: rslib, + link_with: [rslibs], include_directories: [include_directories('..'), include_directories('../eek')], dependencies: deps, c_args: [ From fc5f671e57ace7debecb0376cc80ef7eb68395ef Mon Sep 17 00:00:00 2001 From: David Boddie Date: Fri, 6 Sep 2019 22:15:02 +0200 Subject: [PATCH 2/2] Add new meson and current ninja to the dependencies --- debian/control | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/debian/control b/debian/control index ca3c4681..caa757a5 100644 --- a/debian/control +++ b/debian/control @@ -5,7 +5,8 @@ Maintainer: Dorota Czaplejewicz Build-Depends: cargo, debhelper (>= 10), - meson (>=0.43.0), + meson (>=0.51.0), + ninja-build, pkg-config, libglib2.0-dev, libgtk-3-dev,