Skip to content

Commit

Permalink
Merge remote-tracking branch 'upstream/main' into add_ssh_utils
Browse files Browse the repository at this point in the history
* upstream/main:
  Rename environment variables controlling the Makefile (#26)
  Adopt dev container as primary environment (#39)
  Make the `build` verb build for only one target (#31)
  chore(deps): bump ghcr.io/devcontainers/features/common-utils (#38)
  chore(deps): bump log from 0.4.21 to 0.4.22 in the default group (#37)
  Add dev container (#36)
  Add link to acap-rs-app-template in `README.md` (#34)
  Document `python3-venv` dependency (#35)
  fix: Repair `Makefile` (#32)
  fix(embedded_web_page): Put web page in `html/` (#30)
  Organize dependencies consistently (#29)
  chore(deps): bump glib-sys from 0.19.5 to 0.19.8 in the default group (#28)
  chore: Explain more make targets (#27)
  Add embedded web page example (#14)
  • Loading branch information
apljungquist committed Jul 3, 2024
2 parents f8e33d1 + 64970ae commit 594df5a
Show file tree
Hide file tree
Showing 18 changed files with 252 additions and 66 deletions.
9 changes: 9 additions & 0 deletions .devcontainer/devcontainer-lock.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
{
"features": {
"ghcr.io/devcontainers/features/common-utils:2": {
"version": "2.4.4",
"resolved": "ghcr.io/devcontainers/features/common-utils@sha256:85c6505e809cc7c400b21997d7ae6f50811720d591813243f14d98cf2c577041",
"integrity": "sha256:85c6505e809cc7c400b21997d7ae6f50811720d591813243f14d98cf2c577041"
}
}
}
14 changes: 14 additions & 0 deletions .devcontainer/devcontainer.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
{
"name": "acap-rs",
"build": {
"dockerfile": "../Dockerfile",
"context": ".."
},
"features": {
"ghcr.io/devcontainers/features/common-utils:2": {},
},
"remoteUser": "${localEnv:USER}",
"containerEnv": {
"CARGO_HOME": "/home/${localEnv:USER}/.cargo"
}
}
4 changes: 4 additions & 0 deletions .github/dependabot.yml
Original file line number Diff line number Diff line change
Expand Up @@ -18,3 +18,7 @@ updates:
- "minor"
- "patch"
versioning-strategy: lockfile-only
- package-ecosystem: "devcontainers"
directory: "/"
schedule:
interval: "weekly"
15 changes: 11 additions & 4 deletions .github/workflows/CI.yml
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,16 @@ jobs:
steps:
- name: Checkout
uses: actions/checkout@v4
- name: Install dependencies
- name: Install dev container dependencies
run: npm install -g @devcontainers/[email protected]
- name: Run checks in dev container
run: |
devcontainer up --workspace-folder .
devcontainer exec --workspace-folder . make --always-make check_all
devcontainer exec --workspace-folder . make build AXIS_PACKAGE=licensekey_handler
devcontainer exec --workspace-folder . make build AXIS_PACKAGE=embedded_web_page
- name: Install host dependencies
run: cargo install cross
- name: Run checks
- name: Run checks on host
run: |
make --always-make check_all
PACKAGE=licensekey_handler make build
make check_all
12 changes: 8 additions & 4 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ syslog = "6.1.1"
thiserror = "1.0.57"

licensekey = { path = "crates/licensekey" }
licensekey-sys = { path = "crates/licensekey-sys" }
app-logging = { path = "crates/app-logging" }

[workspace.package]
Expand Down
4 changes: 3 additions & 1 deletion Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ ARG REPO=axisecp
ARG SDK=acap-native-sdk
ARG UBUNTU_VERSION=22.04
ARG VERSION=1.14
ARG BASE_IMAGE=debian:bookworm-20240423-slim
ARG BASE_IMAGE=debian:bookworm-20240423

FROM ${REPO}/${SDK}:${VERSION}-aarch64-ubuntu${UBUNTU_VERSION} AS sdk-aarch64
FROM ${REPO}/${SDK}:${VERSION}-armv7hf-ubuntu${UBUNTU_VERSION} AS sdk-armv7hf
Expand All @@ -21,7 +21,9 @@ RUN apt-get update \
clang \
g++-aarch64-linux-gnu \
g++-arm-linux-gnueabihf \
libglib2.0-dev \
pkg-config \
iputils-ping \
python3-jsonschema \
wget \
&& rm -rf /var/lib/apt/lists/*
Expand Down
142 changes: 90 additions & 52 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -7,16 +7,16 @@
# Name of package containing the app to be built.
# Rust does not enforce that the path to the package matches the package name, but
# this makefile does to keep things simple.
PACKAGE ?= hello_world
AXIS_PACKAGE ?= hello_world

# The architecture that will be assumed when interacting with the device.
ARCH ?= aarch64
AXIS_DEVICE_ARCH ?= aarch64

# The IP address of the device to interact with.
DEVICE_IP ?= 192.168.0.90
AXIS_DEVICE_IP ?= 192.168.0.90

# The password to use when interacting with the device.
PASS ?= pass
AXIS_DEVICE_PASS ?= pass

# Other
# -----
Expand All @@ -28,52 +28,77 @@ PASS ?= pass
# the target is up to date.
.DELETE_ON_ERROR: ;

# Don't remove intermediate files.
.SECONDARY:

# Prevent pesky default rules from creating unexpected dependency graphs.
.SUFFIXES: ;

# Rebuild targets when marking them as phony directly is not enough.
FORCE:;
.PHONY: FORCE

# Use the current environment when already in a container.
ifeq (0, $(shell test -e /.dockerenv; echo $$?))

ACAP_BUILD = . /opt/axis/acapsdk/$(ENVIRONMENT_SETUP) && cd $(@D) && acap-build --build no-build .

CROSS := cargo

# It doesn't matter which SDK is sourced for installing, but using a wildcard would fail since there are multiple in the container.
EAP_INSTALL = cd $(CURDIR)/target/$(AXIS_DEVICE_ARCH)/$(AXIS_PACKAGE)/ \
&& . /opt/axis/acapsdk/environment-setup-cortexa53-crypto-poky-linux && eap-install.sh $(AXIS_DEVICE_IP) $(AXIS_DEVICE_PASS) $@

# Use a containerized environment when running on host.
else

# Bare minimum to make the output from the container available on host with correct permissions.
DOCKER_RUN = docker run \
--volume ${CURDIR}/target/$(ARCH)/$(PACKAGE)/:/opt/app \
--volume ${CURDIR}/target/$(AXIS_DEVICE_ARCH)/$(AXIS_PACKAGE)/:/opt/app \
--user $(shell id -u):$(shell id -g) \
axisecp/acap-native-sdk:1.12-$(ARCH)-ubuntu22.04
axisecp/acap-native-sdk:1.12-$(AXIS_DEVICE_ARCH)-ubuntu22.04

ACAP_BUILD = $(DOCKER_RUN) sh -c ". /opt/axis/acapsdk/environment-setup-* && acap-build --build no-build ."

CROSS := cross

EAP_INSTALL = $(DOCKER_RUN) sh -c ". /opt/axis/acapsdk/environment-setup-* && eap-install.sh $(AXIS_DEVICE_IP) $(AXIS_DEVICE_PASS) $@"

endif


## Verbs
## =====

help:
@mkhelp print_docs $(firstword $(MAKEFILE_LIST)) help

## Build <PACKAGE> for all architectures
build: target/aarch64/$(PACKAGE)/_envoy target/armv7hf/$(PACKAGE)/_envoy
## Build <AXIS_PACKAGE> for <AXIS_DEVICE_ARCH>
build: target/$(AXIS_DEVICE_ARCH)/$(AXIS_PACKAGE)/_envoy
mkdir -p target/acap
cp $(patsubst %/_envoy,%/*.eap,$^) target/acap



## Install <PACKAGE> on <DEVICE_IP> using password <PASS> and assuming architecture <ARCH>
## Install <AXIS_PACKAGE> on <AXIS_DEVICE_IP> using password <AXIS_DEVICE_PASS> and assuming architecture <AXIS_DEVICE_ARCH>
install:
@ $(DOCKER_RUN) sh -c ". /opt/axis/acapsdk/environment-setup-* && eap-install.sh $(DEVICE_IP) $(PASS) install" \
@ $(EAP_INSTALL) \
| grep -v '^to start your application type$$' \
| grep -v '^ eap-install.sh start$$'

## Remove <PACKAGE> from <DEVICE_IP> using password <PASS> and assuming architecture <ARCH>
## Remove <AXIS_PACKAGE> from <AXIS_DEVICE_IP> using password <AXIS_DEVICE_PASS> and assuming architecture <AXIS_DEVICE_ARCH>
remove:
@ $(DOCKER_RUN) sh -c ". /opt/axis/acapsdk/environment-setup-* && eap-install.sh $(DEVICE_IP) $(PASS) remove"
@ $(EAP_INSTALL)

## Start <PACKAGE> on <DEVICE_IP> using password <PASS> and assuming architecture <ARCH>
## Start <AXIS_PACKAGE> on <AXIS_DEVICE_IP> using password <AXIS_DEVICE_PASS> and assuming architecture <AXIS_DEVICE_ARCH>
start:
@ $(DOCKER_RUN) sh -c ". /opt/axis/acapsdk/environment-setup-* && eap-install.sh $(DEVICE_IP) $(PASS) start" \
@ $(EAP_INSTALL) \
| grep -v '^to stop your application type$$' \
| grep -v '^ eap-install.sh stop$$'

## Stop <PACKAGE> on <DEVICE_IP> using password <PASS> and assuming architecture <ARCH>
## Stop <AXIS_PACKAGE> on <AXIS_DEVICE_IP> using password <AXIS_DEVICE_PASS> and assuming architecture <AXIS_DEVICE_ARCH>
stop:
@ $(DOCKER_RUN) sh -c ". /opt/axis/acapsdk/environment-setup-* && eap-install.sh $(DEVICE_IP) $(PASS) stop"
@ $(EAP_INSTALL)

## Build and run <PACKAGE> directly on <DEVICE_IP> assuming architecture <ARCH>
## Build and run <AXIS_PACKAGE> directly on <AXIS_DEVICE_IP> assuming architecture <AXIS_DEVICE_ARCH>
##
## Forwards the following environment variables to the remote process:
##
Expand All @@ -85,18 +110,20 @@ stop:
## * The app is installed on the device.
## * The app is stopped.
## * The device has SSH enabled the ssh user root configured.
run: target/$(ARCH)/$(PACKAGE)/_envoy
acap-ssh-utils --host $(DEVICE_IP) --user root --pass $(PASS) patch $(<D)/*.eap
acap-ssh-utils --host $(DEVICE_IP) --user root --pass $(PASS) run-app \
run: target/$(AXIS_DEVICE_ARCH)/$(AXIS_PACKAGE)/_envoy
acap-ssh-utils --host $(AXIS_DEVICE_IP) --user root --pass $(AXIS_DEVICE_PASS) patch $(<D)/*.eap
acap-ssh-utils --host $(AXIS_DEVICE_IP) --user root --pass $(AXIS_DEVICE_PASS) run-app \
--environment RUST_LOG=debug \
--environment RUST_LOG_STYLE=always \
$(PACKAGE)
$(AXIS_PACKAGE)

## Install development dependencies
sync_env:
sync_env: venv/bin/npm

cargo install --root venv --target-dir $(CURDIR)/target --path $(CURDIR)/crates/acap-ssh-utils
cargo install --root venv --target-dir $(CURDIR)/target cross
PIP_CONSTRAINT=constraints.txt pip install --requirement requirements.txt
npm install -g @devcontainers/[email protected]

## Checks
## ------
Expand All @@ -106,13 +133,13 @@ check_all: check_build check_docs check_format check_lint check_tests check_gene
.PHONY: check_all

## Check that all crates can be built
check_build: target/aarch64/$(PACKAGE)/_envoy target/armv7hf/$(PACKAGE)/_envoy
check_build: target/aarch64/$(AXIS_PACKAGE)/_envoy target/armv7hf/$(AXIS_PACKAGE)/_envoy
cargo build \
--exclude licensekey \
--exclude licensekey-sys \
--exclude licensekey_handler \
--workspace
cross build \
$(CROSS) build \
--exclude acap-ssh-utils \
--target aarch64-unknown-linux-gnu \
--workspace
Expand All @@ -122,15 +149,15 @@ check_build: target/aarch64/$(PACKAGE)/_envoy target/armv7hf/$(PACKAGE)/_envoy
## Check that docs can be built
check_docs:
RUSTDOCFLAGS="-Dwarnings" cargo doc
RUSTDOCFLAGS="-Dwarnings" cross doc \
RUSTDOCFLAGS="-Dwarnings" $(CROSS) doc \
--document-private-items \
--exclude acap-ssh-utils \
--no-deps \
--target aarch64-unknown-linux-gnu \
--workspace
.PHONY: check_docs

## _
## Check that the code is formatted correctly
check_format:
cargo fmt --check
.PHONY: check_format
Expand All @@ -141,8 +168,7 @@ check_generated_files: $(patsubst %/,%/src/bindings.rs,$(wildcard crates/*-sys/)
git --no-pager diff --exit-code HEAD -- $^
.PHONY: check_generated_files


## _
## Check that the code is free of lints
check_lint:
RUSTFLAGS="-Dwarnings" cargo clippy \
--all-targets \
Expand All @@ -151,7 +177,7 @@ check_lint:
--exclude licensekey-sys \
--exclude licensekey_handler \
--workspace
RUSTFLAGS="-Dwarnings" cross clippy \
RUSTFLAGS="-Dwarnings" $(CROSS) clippy \
--all-targets \
--exclude acap-ssh-utils \
--no-deps \
Expand All @@ -171,12 +197,12 @@ check_tests:
## Fixes
## -----

## _
## Attempt to fix formatting automatically
fix_format:
cargo fmt
.PHONY: fix_format

## _
## Attempt to fix lints automatically
fix_lint:
cargo clippy --fix
.PHONY: fix_lint
Expand Down Expand Up @@ -204,39 +230,51 @@ crates/%-sys/src/bindings.rs: FORCE
# * `.DELETE_ON_ERROR` does not work for directories, and
# * the name of the `.eap` file is annoying to predict.
# When building for all targets using a single image we cannot rely on wildcard matching.
target/aarch64/$(PACKAGE)/_envoy: ENVIRONMENT_SETUP=environment-setup-cortexa53-crypto-poky-linux
target/armv7hf/$(PACKAGE)/_envoy: ENVIRONMENT_SETUP=environment-setup-cortexa9hf-neon-poky-linux-gnueabi
target/%/$(PACKAGE)/_envoy: ARCH=$*
target/%/$(PACKAGE)/_envoy: target/%/$(PACKAGE)/$(PACKAGE) target/%/$(PACKAGE)/manifest.json target/%/$(PACKAGE)/LICENSE
ifeq (0, $(shell test -e /.dockerenv; echo $$?))
. /opt/axis/acapsdk/$(ENVIRONMENT_SETUP) && cd $(@D) && acap-build --build no-build .
else
$(DOCKER_RUN) sh -c ". /opt/axis/acapsdk/environment-setup-* && acap-build --build no-build ."
endif
target/aarch64/$(AXIS_PACKAGE)/_envoy: ENVIRONMENT_SETUP=environment-setup-cortexa53-crypto-poky-linux
target/armv7hf/$(AXIS_PACKAGE)/_envoy: ENVIRONMENT_SETUP=environment-setup-cortexa9hf-neon-poky-linux-gnueabi
target/%/$(AXIS_PACKAGE)/_envoy: AXIS_DEVICE_ARCH=$*
target/%/$(AXIS_PACKAGE)/_envoy: target/%/$(AXIS_PACKAGE)/lib target/%/$(AXIS_PACKAGE)/html target/%/$(AXIS_PACKAGE)/$(AXIS_PACKAGE) target/%/$(AXIS_PACKAGE)/manifest.json target/%/$(AXIS_PACKAGE)/LICENSE
$(ACAP_BUILD)
touch $@

target/%/$(PACKAGE)/manifest.json: apps/$(PACKAGE)/manifest.json
target/%/$(AXIS_PACKAGE)/html: FORCE
mkdir -p $(dir $@)
if [ -d $@ ]; then rm -r $@; fi
if [ -d apps/$(AXIS_PACKAGE)/html ]; then cp -r apps/$(AXIS_PACKAGE)/html $@; fi

target/%/$(AXIS_PACKAGE)/lib: FORCE
mkdir -p $(dir $@)
if [ -d $@ ]; then rm -r $@; fi
if [ -d apps/$(AXIS_PACKAGE)/lib ]; then cp -r apps/$(AXIS_PACKAGE)/lib $@; fi

target/%/$(AXIS_PACKAGE)/manifest.json: apps/$(AXIS_PACKAGE)/manifest.json
mkdir -p $(dir $@)
cp $< $@

target/%/$(PACKAGE)/LICENSE: apps/$(PACKAGE)/LICENSE
target/%/$(AXIS_PACKAGE)/LICENSE: apps/$(AXIS_PACKAGE)/LICENSE
mkdir -p $(dir $@)
cp $< $@

# The target triple and the name of the docker image do not match, so
# at some point we need to map one to the other. It might as well be here.
target/aarch64/$(PACKAGE)/$(PACKAGE): target/aarch64-unknown-linux-gnu/release/$(PACKAGE)
target/aarch64/$(AXIS_PACKAGE)/$(AXIS_PACKAGE): target/aarch64-unknown-linux-gnu/release/$(AXIS_PACKAGE)
mkdir -p $(dir $@)
cp $< $@

target/armv7hf/$(PACKAGE)/$(PACKAGE): target/thumbv7neon-unknown-linux-gnueabihf/release/$(PACKAGE)
target/armv7hf/$(AXIS_PACKAGE)/$(AXIS_PACKAGE): target/thumbv7neon-unknown-linux-gnueabihf/release/$(AXIS_PACKAGE)
mkdir -p $(dir $@)
cp $< $@

# Always rebuild the executable because configuring accurate cache invalidation is annoying.
target/%/release/$(PACKAGE): FORCE
ifeq (0, $(shell test -e /.dockerenv; echo $$?))
cargo -v build --release --target $* --package $(PACKAGE)
else
cross -v build --release --target $* --package $(PACKAGE)
endif
target/%/release/$(AXIS_PACKAGE): FORCE
$(CROSS) -v build --release --target $* --package $(AXIS_PACKAGE)
touch $@ # This is a hack to make the `_envoy` target above always build


venv/bin/npm: venv/downloads/node-v18.16.1-linux-x64.tar.gz
tar -xf "$<" --strip-components 1 -C venv

venv/downloads/node-v18.16.1-linux-x64.tar.gz:
mkdir -p $(@D)
curl -L -o "$@" "https://nodejs.org/dist/v18.16.1/node-v18.16.1-linux-x64.tar.gz"
echo "59582f51570d0857de6333620323bdeee5ae36107318f86ce5eca24747cabf5b $@" | sha256sum -c -
Loading

0 comments on commit 594df5a

Please sign in to comment.