Skip to content

Commit

Permalink
Merge pull request #8 from RusPiRo/feature/lazy_init
Browse files Browse the repository at this point in the history
introduce lazy initialization
  • Loading branch information
2ndTaleStudio authored Nov 8, 2020
2 parents 6314b4a + 64d0c76 commit 0565f8e
Show file tree
Hide file tree
Showing 10 changed files with 441 additions and 183 deletions.
4 changes: 3 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,6 @@
**/*.rs.bk
**/release
.vscode
*.lock
*.lock
*.log
*.ld
121 changes: 96 additions & 25 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,51 +3,122 @@
branches:
only:
- master
- release

language: rust

rust:
# build nightly only for the time beeing
- nightly

matrix:
fast_finish: true
# increase build speed by caching installed cargo dependencies
cache: cargo

# define the stages and their order
stages:
- compile
- test
- publish_dry
- name: prepare_release
if: branch = master AND type != pull_request
- name: deploy
if: branch = release AND type != pull_request
- name: publish
if: branch = release AND type != pull_request

jobs:
include:
- name: "build 64Bit"
- stage: compile
name: "Compile The Crate"
install:
- sudo apt-get install gcc-aarch64-linux-gnu
- sudo apt-get install -y gcc-aarch64-linux-gnu
- cargo install cargo-xbuild
- cargo install cargo-make
- rustup target add aarch64-unknown-linux-gnu
- rustup target add aarch64-unknown-none
- rustup component add rust-src
- rustup component add llvm-tools-preview
# if we not build a PR we remove the patch of the dependencies to their github repo's
- 'if [ "$TRAVIS_PULL_REQUEST" == "false" ]; then sed -i "/^\[patch\.crates-io\]$/ {N; s/^.*//g}" Cargo.toml; fi'
script: cargo make --profile a64-travis pi3
- 'if [ "$TRAVIS_PULL_REQUEST" == "false" ]; then sed -i "/\[patch\.crates-io\]/,$ s/^ruspiro-.*\(git\|path\).*//g" Cargo.toml; fi'
script: cargo make --profile travis pi3

- name: "build 32Bit"
- stage: test
name: "Run Doc Tests"
install:
- sudo apt-get install gcc-arm-linux-gnueabihf
- cargo install cargo-xbuild
- cargo install cargo-make
- rustup target add armv7-unknown-linux-gnueabihf
- rustup component add rust-src
- rustup component add llvm-tools-preview
# if we not build a PR we remove the patch of the dependencies to their github repo's
- 'if [ "$TRAVIS_PULL_REQUEST" == "false" ]; then sed -i "/^\[patch\.crates-io\]$/ {N; s/^.*//g}" Cargo.toml; fi'
script: cargo make --profile a32 pi3

- name: "unit tests"
- 'if [ "$TRAVIS_PULL_REQUEST" == "false" ]; then sed -i "/{^\[patch\.crates-io\] /{:a;N;/\Z}/!ba};/^ruspiro-.*\(git\|path\).*/d" Cargo.toml; fi'
script: cargo make doctest --profile dummy
- stage: test
name: "Run Unit Tests"
install:
- cargo install cargo-make
# if we not build a PR we remove the patch of the dependencies to their github repo's
- 'if [ "$TRAVIS_PULL_REQUEST" == "false" ]; then sed -i "/^\[patch\.crates-io\]$/ {N; s/^.*//g}" Cargo.toml; fi'
script: cargo test --tests
- 'if [ "$TRAVIS_PULL_REQUEST" == "false" ]; then sed -i "/{^\[patch\.crates-io\] /{:a;N;/\Z}/!ba};/^ruspiro-.*\(git\|path\).*/d" Cargo.toml; fi'
script: cargo make unittest --profile dummy

- name: "doc tests"
- stage: publish_dry
name: "Run Cargo Publish Dry-Run"
install:
# if we not build a PR we remove the patch of the dependencies to their github repo's
- 'if [ "$TRAVIS_PULL_REQUEST" == "false" ]; then sed -i "/^\[patch\.crates-io\]$/ {N; s/^.*//g}" Cargo.toml; fi'
- cat Cargo.toml
script: cargo test --doc
- sudo apt-get install -y gcc-aarch64-linux-gnu
- cargo install cargo-xbuild
- cargo install cargo-make
- rustup target add aarch64-unknown-none
- rustup component add rust-src
- rustup component add llvm-tools-preview
script: cargo make publish_dry --profile travis

- stage: prepare_release
name: "Create PR against the release branch"
script:
- 'curl -H ''Authorization: Token ''"$GIT_API_TOKEN"'''' -X POST -H ''Content-type: application/json'' --data ''{"title":"Prepare Release and crates.io publishing", "head":"master", "base":"release", "draft":false, "body":"Automatic PR to the release branch as preperation to publish the library"}'' https://api.github.com/repos/$TRAVIS_REPO_SLUG/pulls > /dev/null'


- stage: deploy
name: "Create GitHub release"
script: echo "creating github release"
before_deploy:
# extract current crate version from argo.toml
- export CRATE_VERSION=v`sed -En 's/^version.*=.*\"(.*)\".*$/\1/p' < Cargo.toml`
# retrieve last release version from github
- export LAST_VERSION="$(curl --silent "https://api.github.com/repos/$TRAVIS_REPO_SLUG/releases/latest" | grep '"tag_name":' | sed -E 's/.*"([^"]+)".*/\1/')"
# use default version if none yet published (required for proper release note extraction)
- export LAST_VERSION=${LAST_VERSION:-v0.0.0}
- echo $CRATE_VERSION
- echo $LAST_VERSION
- git config --local user.name "2ndTaleStudio"
- git config --local user.email "43264484+2ndTaleStudio@users.noreply.github.com"
# create the TAG required for the release
- git tag $CRATE_VERSION -m "$CRATE_VERSION"
# extract the release notes of the current release from the changelog
- sed -En '/##.*:.*:.*'"$LAST_VERSION"'/q;p' CHANGELOG.md > RELEASENOTES.md
- sed -i -e 's/^# Changelog/# Release Notes/g' RELEASENOTES.md
deploy:
provider: releases
# use dpl v2 version for deployments to support the release_notes_file option
edge: true
api_key: "$GIT_API_TOKEN"
name: "$CRATE_VERSION"
release_notes_file: "RELEASENOTES.md"
file: "RELEASENOTES.md"
skip_cleanup: true
on:
branch: release

- stage: publish
name: "Run Cargo Publish"
install:
- sudo apt-get install -y gcc-aarch64-linux-gnu
- cargo install cargo-xbuild
- cargo install cargo-make
- rustup target add aarch64-unknown-none
- rustup component add rust-src
- rustup component add llvm-tools-preview
# extract current crate version from argo.toml
- export CRATE_VERSION=`sed -En 's/^version.*=.*\"(.*)\".*$/\1/p' < Cargo.toml`
# before actually publishing replace the final version for doc and repository in the Crago.toml
- sed -i -e 's/||VERSION||/'$CRATE_VERSION'/g' Cargo.toml
# also update the version in the lib.rs doc root url
- sed -i -e 's/||VERSION||/'$CRATE_VERSION'/g' src/lib.rs
# and the README.md
- sed -i -e 's/||VERSION||/'$CRATE_VERSION'/g' README.md
# publish with token and dirty flag as we just updated some files and won't commit them back to the branch
script: cargo make publish --profile travis --env CRATES_TOKEN="$CRATES_TOKEN" > /dev/null
21 changes: 17 additions & 4 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,18 @@
# Changelog
## :banana: v0.4.3
- ### :detective: Fixes
- remove `asm!` macro usages and replace with `llvm_asm!`
- use `cargo make` to stabilize cross-platform builds

## :peach: v0.4.0

- ### :bulb: Features

- Introduce the ability to lazylie initialize the value stored inside the `Singleton` using a closure. The initialization is evaluated on first access to the `Singleton` contents.

- ### :wrench: Maintenance

- Enable proper and stable pipeline to support release and publishing process

## :banana: v0.3.1

- ### :detective: Fixes

- remove `asm!` macro usages and replace with `llvm_asm!`
- use `cargo make` to stabilize cross-platform builds
13 changes: 8 additions & 5 deletions Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
[package]
name = "ruspiro-singleton"
authors = ["André Borrmann <pspwizard@gmx.de>"]
version = "0.3.1" # remember to update html_root_url
version = "0.4.0" # remember to update html_root_url
description = "Simple and easy to use singleton pattern"
license = "Apache-2.0"
repository = "https://github.com/RusPiRo/ruspiro-singleton/tree/v0.3.1"
documentation = "https://docs.rs/ruspiro-singleton/0.3.1"
repository = "https://github.com/RusPiRo/ruspiro-singleton/tree/v||VERSION||"
documentation = "https://docs.rs/ruspiro-singleton/||VERSION||"
readme = "README.md"
keywords = ["RusPiRo", "singleton", "raspberrypi"]
categories = ["no-std", "embedded"]
Expand All @@ -18,10 +18,13 @@ maintenance = { status = "actively-developed" }

[lib]

[dev-dependencies]

[dependencies]
ruspiro-lock = "0.3"
ruspiro-lock = "0.4.0"

[features]
ruspiro_pi3 = [ ]

[patch.crates-io]
ruspiro-lock = { git = "https://github.com/RusPiRo/ruspiro-lock.git" }
ruspiro-lock = { git = "https://github.com/RusPiRo/ruspiro-lock.git" }
File renamed without changes.
21 changes: 21 additions & 0 deletions LICENSE-MIT
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
MIT License

Copyright (c) 2019 André Borrmann <pspwizard@gmx.de>

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
79 changes: 56 additions & 23 deletions Makefile.toml
Original file line number Diff line number Diff line change
@@ -1,41 +1,74 @@
#***********************************************************************************************************************
# cargo make tasks to build the example for the Raspberry Pi
#***********************************************************************************************************************
[env.a64]

# AARCH64 specific profile environment varialbles
[env.development]
CC = "aarch64-none-elf-gcc"
AR = "aarch64-none-elf-ar"
OC = "aarch64-none-elf-objcopy"
CFLAGS = "-march=armv8-a -Wall -O3 -nostdlib -nostartfiles -ffreestanding -mtune=cortex-a53"
RUSTFLAGS = "-C linker=${CC} -C target-cpu=cortex-a53 -C link-arg=-nostartfiles -C link-arg=-T./link64.ld"
BUILD_TARGET = "aarch64-unknown-linux-gnu"

[env.a32]
CC = "arm-none-eabi-gcc"
AR = "arm-none-eabi-ar"
OC = "arm-none-eabi-objcopy"
CFLAGS = "-mcpu=cortex-a53 -march=armv7-a -mfpu=neon -mfloat-abi=softfp -Wall -O3 -nostdlib -nostartfiles"
RUSTFLAGS = "-C linker=${CC} -C target-cpu=cortex-a53 -C link-arg=-nostartfiles"
BUILD_TARGET = "armv7a-none-eabi"

# Travis CI need a different CC/AR alltogether as the aarch64-none-elf is not available there as it seems
[env.a64-travis]
BUILD_TARGET = "aarch64-unknown-none"

# AARCH64 specific Travis CI env. variables. "aarch64-none-elf" is not available there as it seems
[env.travis]
CC = "aarch64-linux-gnu-gcc"
AR = "aarch64-linux-gnu-ar"
OC = "aarch64-linux-gnu-objcopy"
CFLAGS = "-march=armv8-a -Wall -O3 -nostdlib -nostartfiles -ffreestanding -mtune=cortex-a53"
RUSTFLAGS = "-C linker=${CC} -C target-cpu=cortex-a53 -C link-arg=-nostartfiles"
BUILD_TARGET = "aarch64-unknown-linux-gnu"
RUSTFLAGS = "-C linker=${CC} -C target-cpu=cortex-a53 -C link-arg=-nostartfiles -C link-arg=-T./link64.ld"
BUILD_TARGET = "aarch64-unknown-none"

[tasks.xbuild]
command = "cargo"
args = ["xbuild", "--target", "${BUILD_TARGET}", "--release", "--features", "${FEATURES}"]
args = ["build", "--target", "${BUILD_TARGET}", "--release", "--features", "${FEATURES}"]

[tasks.pi3]
env = { FEATURES = "" }
run_task = [
{ name = "xbuild" }
]
env = { FEATURES = "ruspiro_pi3" }
run_task = "xbuild"

[tasks.clippy]
env = { FEATURES = "ruspiro_pi3" }
command = "cargo"
args = ["clippy", "--target", "${BUILD_TARGET}", "--features", "${FEATURES}"]

[tasks.doc]
env = { FEATURES = "ruspiro_pi3" }
command = "cargo"
args = ["doc", "--target", "${BUILD_TARGET}", "--features", "${FEATURES}", "--open"]

[tasks.unittest]
env = { FEATURES = "ruspiro_pi3" }
command = "cargo"
args = ["test", "--tests", "--features", "${FEATURES}"]


[tasks.doctest]
env = { FEATURES = "ruspiro_pi3" }
command = "cargo"
args = ["test", "--doc", "--features", "${FEATURES}"]

[tasks.publish_dry]
env = { FEATURES = "ruspiro_pi3" }
command = "cargo"
args = ["publish", "--dry-run", "--target", "${BUILD_TARGET}", "--features", "${FEATURES}"]

[tasks.publish]
env = { FEATURES = "ruspiro_pi3" }
command = "cargo"
args = ["publish", "--token", "${CRATES_TOKEN}", "--allow-dirty", "--target", "${BUILD_TARGET}", "--features", "${FEATURES}"]

[tasks.clean]
command = "cargo"
args = ["clean"]
args = ["clean"]

[tasks.qemu-test-objcopy]
command = "aarch64-none-elf-objcopy"
args = ["-O", "binary", "${CARGO_MAKE_TASK_ARGS}", "./target/kernel-test.img"]

[tasks.qemu-test]
script = [
"qemu-system-aarch64 -semihosting -display none -M raspi3 -kernel ./target/kernel-test.img -serial null -serial stdio -d int,mmu -D qemu-test.log"
]
dependencies = [
"qemu-test-objcopy"
]
Loading

0 comments on commit 0565f8e

Please sign in to comment.