Skip to content
Merged
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
28 changes: 28 additions & 0 deletions .github/ci-build.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
#!/bin/bash

set -e
set -x
set -o errexit
set -o pipefail

archive_name="console_pp"

if [[ "$OS_NAME" == "macOS" ]]; then
(strip 'Swift Navigation Console.dmg');
tar -czf ${archive_name}_osx.tar.gz 'Swift Navigation Console.dmg';
VERSION="$(git describe --always --tags --dirty)";
BUILD_TRIPLET="$(gcc -dumpmachine)";
mv ${archive_name}_osx.tar.gz "${archive_name}-${VERSION}-${BUILD_TRIPLET}.tar.gz";
echo "${archive_name}-${VERSION}-${BUILD_TRIPLET}.tar.gz" >release-archive.filename;
ls -l;
fi

if [[ "$OS_NAME" == "Linux" ]]; then
(cd target; strip 'Swift Navigation Console.deb');
tar -C "target" -czf ${archive_name}_linux.tar.gz 'Swift Navigation Console.deb';
VERSION="$(git describe --always --tags --dirty)";
BUILD_TRIPLET="$(gcc -dumpmachine)";
mv ${archive_name}_linux.tar.gz "${archive_name}-${VERSION}-${BUILD_TRIPLET}.tar.gz";
echo "${archive_name}-${VERSION}-${BUILD_TRIPLET}.tar.gz" >release-archive.filename;
ls -l;
fi
160 changes: 160 additions & 0 deletions .github/workflows/main.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,160 @@
name: main
Copy link
Contributor

@notoriaga notoriaga Feb 10, 2021

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I wonder if there is a way to keep this a bit more dry - I have a wip pr for adding github actions to libsbp - https://github.com/swift-nav/libsbp/pull/905/files#diff-9ed853ee5016b3f7cb01ee3da6506fd9e926a923324f327507c34e64f83dfe10R1

With the key bit being (in the build job)-

      matrix:
        os:
          - ubuntu-latest
          - macos-latest
          - windows-latest

All the rust toolchain stuff should just work ™️, not sure about the python.

Copy link
Collaborator Author

@john-michaelburke john-michaelburke Feb 11, 2021

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done. I really like this flow thank you for the suggestion!


on:
push:
branches:
- 'main'
tags:
- 'v*'
pull_request:

jobs:
checks:
runs-on: ubuntu-latest
defaults:
run:
shell: bash -l {0}
steps:
- name: Checkout source
uses: actions/checkout@v2
with:
submodules: recursive
ssh-key: ${{ secrets.SSH_KEY }}

- name: Install stable Rust
uses: actions-rs/toolchain@v1
with:
toolchain: stable
override: true
components: rustfmt, clippy
- uses: davidB/rust-cargo-make@v1
with:
version: '0.32.11'
- name: Cache conda
uses: actions/cache@v1
env:
CACHE_NUMBER: 0
with:
path: ~/conda_pkgs_dir
key:
${{ runner.os }}-conda-${{ env.CACHE_NUMBER }}-${{
hashFiles('conda.yml') }}
- uses: conda-incubator/setup-miniconda@v2
with:
activate-environment: console_pp
environment-file: conda.yml
use-only-tar-bz2: true
- name: Install Dependencies.
run: |
if [ "$RUNNER_OS" == "Linux" ]; then
sudo apt-get install -y capnproto ruby ruby-dev rubygems build-essential
sudo gem install --no-document fpm
elif [ "$RUNNER_OS" == "macOS" ]; then
brew install capnp
fi
shell: bash

- name: Poetry Install
run: |
conda activate console_pp
python -m poetry install

- name: Run Format Check
run: |
conda activate console_pp
cargo make format-check

- name: Run Type Check
run: |
conda activate console_pp
cargo make types

- name: Run Lint Check
run: |
conda activate console_pp
cargo make lint

- name: Run Tests
run: |
conda activate console_pp
cargo make tests

build:
name: Build Binaries
needs:
- checks
strategy:
matrix:
os:
- ubuntu-20.04
- macos-10.15
runs-on: ${{ matrix.os }}
defaults:
run:
shell: bash -l {0}
steps:

- name: Checkout source
uses: actions/checkout@v2
with:
submodules: recursive
ssh-key: ${{ secrets.SSH_KEY }}

- name: Install ${{ runner.os }} Dependencies.
run: |
if [ "$RUNNER_OS" == "Linux" ]; then
sudo apt-get install -y capnproto ruby ruby-dev rubygems build-essential
sudo gem install --no-document fpm
elif [ "$RUNNER_OS" == "macOS" ]; then
brew install capnp
fi

- name: Install stable Rust
uses: actions-rs/toolchain@v1
with:
toolchain: stable
override: true
components: rustfmt, clippy
- uses: davidB/rust-cargo-make@v1
with:
version: '0.32.11'

- name: Cache conda
uses: actions/cache@v1
env:
CACHE_NUMBER: 0
with:
path: ~/conda_pkgs_dir
key:
${{ runner.os }}-conda-${{ env.CACHE_NUMBER }}-${{
hashFiles('conda.yml') }}
- uses: conda-incubator/setup-miniconda@v2
with:
activate-environment: console_pp
environment-file: conda.yml
use-only-tar-bz2: true

- name: Poetry Install
run: |
conda activate console_pp
python -m poetry install

- name: Build ${{ runner.os }} Binaries.
env:
OS_NAME: ${{ runner.os }}
run: |
conda activate console_pp
if [ "$RUNNER_OS" == "Linux" ]; then
cargo make prod-installer
elif [ "$RUNNER_OS" == "macOS" ]; then
cargo make prod-mac-nuitka-installer
fi
bash ./.github/ci-build.sh
echo "RELEASE_ARCHIVE=$(cat release-archive.filename)" >>$GITHUB_ENV

- uses: actions/upload-artifact@v2
with:
name: ${{ runner.os }}-artifacts
path: |
${{ env.RELEASE_ARCHIVE }}
release-archive.filename
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
__pycache__
target
.mypy_cache
.doit*
*.build
*.dist
109 changes: 108 additions & 1 deletion Makefile.toml
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
[env]
PYTHON_FILES = { script = ["echo $(find . -path ./target -prune -false -o -name '*.py')"] }

[config]
default_to_workspace = false

Expand All @@ -20,9 +23,113 @@ pip install -e ./console_backend
fbs run
'''

[tasks.run-prod]
[tasks.prod-run]
dependencies = ["copy-capnp", "generate-resources"]
script = '''
pip install --force ./console_backend
fbs run
'''

[tasks.prod-freeze]
dependencies = ["copy-capnp", "generate-resources"]
script = '''
pip install --force ./console_backend
fbs freeze
'''

[tasks.prod-installer]
dependencies = ["prod-freeze"]
script = '''
fbs installer
'''

[tasks.prod-linux-nuitka-build]
dependencies = ["copy-capnp", "generate-resources"]
script_runner = "@shell"
script = '''
pip install --force ./console_backend
bash src/main/nuitka/linux.sh
'''

[tasks.prod-mac-nuitka-build]
dependencies = ["copy-capnp", "generate-resources"]
script_runner = "@shell"
script = '''
pip install --force ./console_backend
bash src/main/nuitka/mac.sh
'''

[tasks.prod-mac-nuitka-installer]
dependencies = ["prod-mac-nuitka-build"]
script_runner = "@shell"
script = '''
mkdir -p main.app/Contents/MacOS
cp -r main.dist/* main.app/Contents/MacOS/.
hdiutil create -volname SwiftNavConsole -srcfolder main.app -ov -format UDZO 'Swift Navigation Console.dmg'
'''

[tasks.rust-format]
dependencies = ["copy-capnp"]
command = "cargo"
args = ["fmt", "--all"]

[tasks.rust-format-check]
dependencies = ["copy-capnp"]
command = "cargo"
args = ["fmt", "--", "--check"]

[tasks.rust-lint]
dependencies = ["copy-capnp"]
command = "cargo"
args = ["clippy", "--all-targets", "--", "--deny", "warnings"]

[tasks.rust-tests]
dependencies = ["copy-capnp"]
command = "cargo"
args = ["test", "--", "--nocapture"]

[tasks.rust-type-check]
dependencies = ["copy-capnp"]
command = "cargo"
args = ["check"]

[tasks.python-type-check]
script_runner = "@shell"
script = '''
mypy $PYTHON_FILES
'''

[tasks.python-format-check]
script = '''
black --line-length=120 --check --diff $PYTHON_FILES
'''

[tasks.python-format-all]
script = '''
black --line-length=120 $PYTHON_FILES
'''

[tasks.python-format]
alias="python-format-all"

[tasks.python-lint]
script_runner = "@shell"
script = '''
pylint --output-format=parseable $PYTHON_FILES
'''

[tasks.format-all]
dependencies = ["python-format-all", "rust-format"]

[tasks.format-check]
dependencies = ["python-format-check", "rust-format-check"]

[tasks.lint]
dependencies = ["python-lint", "rust-lint"]

[tasks.types]
dependencies = ["python-type-check", "rust-type-check"]

[tasks.tests]
dependencies = ["rust-tests"]

2 changes: 2 additions & 0 deletions conda.yml
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
name: console_pp
dependencies:
- python=3.8
- pip:
- poetry==1.1.4
3 changes: 1 addition & 2 deletions console_backend/build.rs
Original file line number Diff line number Diff line change
@@ -1,12 +1,11 @@
extern crate capnpc;

fn main() {

let output_dir = std::env::var("OUT_DIR").unwrap();

::capnpc::CompilerCommand::new()
.file("console_backend.capnp")
.output_path(output_dir)
.run()
.unwrap();
}
}
1 change: 1 addition & 0 deletions console_backend/console_backend/.gitignore
Original file line number Diff line number Diff line change
@@ -1 +1,2 @@
*.pyd
*.so
17 changes: 5 additions & 12 deletions console_backend/setup.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import sys
import platform

from setuptools import setup
from setuptools_rust import RustExtension
from setuptools import setup # type: ignore
from setuptools_rust import RustExtension # type: ignore


def get_py_version_cfgs():
Expand All @@ -20,22 +20,15 @@ def get_py_version_cfgs():


def make_rust_extension(module_name):
return RustExtension(
module_name, "Cargo.toml", rustc_flags=get_py_version_cfgs(), debug=True
)
return RustExtension(module_name, "Cargo.toml", rustc_flags=get_py_version_cfgs(), debug=True)


setup(
name="console-backend",
version="0.1.0",
classifiers=[
"Programming Language :: Python",
"Programming Language :: Rust",
],
classifiers=["Programming Language :: Python", "Programming Language :: Rust",],
packages=["console_backend"],
rust_extensions=[
make_rust_extension("console_backend.server"),
],
rust_extensions=[make_rust_extension("console_backend.server"),],
include_package_data=True,
zip_safe=False,
)
4 changes: 2 additions & 2 deletions console_backend/src/lib.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
pub mod server;

pub mod console_backend_capnp {
include!(concat!(env!("OUT_DIR"), "/console_backend_capnp.rs"));
}
include!(concat!(env!("OUT_DIR"), "/console_backend_capnp.rs"));
}
Loading