Skip to content

Commit

Permalink
adding justfile for more effective builds
Browse files Browse the repository at this point in the history
  • Loading branch information
iamdb committed Nov 18, 2023
1 parent 2077daf commit 690e498
Show file tree
Hide file tree
Showing 8 changed files with 218 additions and 185 deletions.
55 changes: 9 additions & 46 deletions .github/workflows/pull-request.yml
Original file line number Diff line number Diff line change
Expand Up @@ -11,23 +11,18 @@ on:
- "**.ts"
branches:
- main
env:
CLICOLOR_FORCE: 1
jobs:
pre-merge:
name: Pre-merge checks
runs-on: ${{ matrix.os }}
strategy:
fail-fast: true
matrix:
os: [ubuntu-latest, macos-latest]
target: [x86_64-unknown-linux-gnu, x86_64-apple-darwin]
rust: [stable]
exclude:
- os: ubuntu-latest
target: x86_64-apple-darwin
- os: macos-latest
target: x86_64-unknown-linux-gnu
arch: [x86_64, aarch64]
runs-on: ubuntu-latest
container:
image: rust:1-bookworm
env:
PKG_CONFIG_PATH: /usr/lib/${{ matrix.arch }}-linux-gnu/pkgconfig/:${PKG_CONFIG_PATH}
env:
RUST_BACKTRACE: full
steps:
Expand All @@ -36,38 +31,6 @@ jobs:
- uses: Swatinem/rust-cache@v2
with:
shared-key: ${{ runner.target }}-rust-cache
- name: Install ${{ matrix.target }} packages (ubuntu-latest)
if: matrix.target == 'x86_64-unknown-linux-gnu'
run: |
sudo apt-get update
sudo apt-get install -y libunwind-dev libgstreamer1.0-dev
- name: Install packages (macos-latest)
if: matrix.os == 'macos-latest'
run: |
brew install gstreamer
- name: Install Rust Toolchain
uses: actions-rs/toolchain@v1
with:
profile: minimal
toolchain: stable
target: ${{ matrix.target }}
components: rustfmt, clippy
override: true
- name: Install Cargo Plugins
uses: actions-rs/cargo@v1
with:
command: install
args: cargo-make cargo-insta sqlx-cli
- name: Create db file
run: "touch /tmp/data.db && cd hifirs && cargo sqlx database reset -y"
env:
DATABASE_URL: "sqlite:///tmp/data.db"
- name: Run CI Flow
uses: actions-rs/cargo@v1
env:
QOBUZ_USERNAME: ${{secrets.QOBUZ_USERNAME}}
QOBUZ_PASSWORD: ${{secrets.QOBUZ_PASSWORD}}
DATABASE_URL: "sqlite:///tmp/data.db"
with:
command: make
args: ci-flow
- uses: extractions/setup-just@v1
- name: Build player
run: just build-player ${{ matrix.arch }}-unknown-linux-gnu
26 changes: 4 additions & 22 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -1,32 +1,14 @@
FROM node:18-bullseye as www
FROM rust:1-bookworm as build

RUN mkdir /app
ARG PKG_CONFIG_PATH="/usr/lib/x86_64-linux-gnu/pkgconfig/:${PKG_CONFIG_PATH}"

WORKDIR /app

COPY www .

RUN npm install && npm run build

FROM rust:1-bullseye as build

RUN apt-get update && apt-get install -y curl libgstreamer1.0-dev

ENV PKG_CONFIG_PATH_x86_64_unknown_linux_gnu="/usr/lib/x86_64-linux-gnu/pkgconfig"
ENV DATABASE_URL "sqlite:///tmp/data.db"

RUN curl -L --proto '=https' --tlsv1.2 -sSf https://raw.githubusercontent.com/cargo-bins/cargo-binstall/main/install-from-binstall-release.sh | bash
RUN cargo binstall --no-confirm sqlx-cli
RUN curl --proto '=https' --tlsv1.2 -sSf https://just.systems/install.sh | bash -s -- --to /bin

WORKDIR /app

COPY . .

COPY --from=www /app/build /app/www/build

RUN touch /tmp/data.db && cd hifirs && cargo sqlx database reset -y

RUN cargo build --bin hifi-rs --release --target x86_64-unknown-linux-gnu
RUN just build-player x86_64-unknown-linux-gnu

RUN mv target/x86_64-unknown-linux-gnu/release/hifi-rs /usr/local/bin

Expand Down
36 changes: 7 additions & 29 deletions Dockerfile.arm64
Original file line number Diff line number Diff line change
@@ -1,42 +1,20 @@
FROM node:18-bullseye as www
FROM rust:1-bookworm as build

RUN mkdir /app

WORKDIR /app

COPY www .

RUN npm install && npm run build

FROM rust:1-bullseye as build

RUN dpkg --add-architecture arm64
RUN apt-get update && apt-get install -y curl libgstreamer1.0-dev:arm64 g++-aarch64-linux-gnu libc6-dev-arm64-cross libglib2.0-dev:arm64

RUN rustup target add aarch64-unknown-linux-gnu
RUN rustup toolchain install stable-aarch64-unknown-linux-gnu

ENV PKG_CONFIG_ALLOW_CROSS=1
ENV PKG_CONFIG_PATH="/usr/lib/aarch64-linux-gnu/pkgconfig/:${PKG_CONFIG_PATH}"
ENV CARGO_TARGET_AARCH64_UNKNOWN_LINUX_GNU_LINKER=aarch64-linux-gnu-gcc \
ARG CARGO_TARGET_AARCH64_UNKNOWN_LINUX_GNU_LINKER=aarch64-linux-gnu-gcc \
AR_aarch64_unknown_linux_gnu=aarch64-linux-gnu-ar \
CC_aarch64_unknown_linux_gnu=aarch64-linux-gnu-gcc \
CXX_aarch64_unknown_linux_gnu=aarch64-linux-gnu-g++
ENV DATABASE_URL "sqlite:///tmp/data.db"
CXX_aarch64_unknown_linux_gnu=aarch64-linux-gnu-g++

RUN curl -L --proto '=https' --tlsv1.2 -sSf https://raw.githubusercontent.com/cargo-bins/cargo-binstall/main/install-from-binstall-release.sh | bash
ARG PKG_CONFIG_ALLOW_CROSS=1
ARG PKG_CONFIG_PATH="/usr/lib/aarch64-linux-gnu/pkgconfig/:${PKG_CONFIG_PATH}"

RUN cargo binstall --no-confirm sqlx-cli
RUN touch /tmp/data.db && cargo sqlx database reset --source ./hifirs/migrations -y
RUN curl --proto '=https' --tlsv1.2 -sSf https://just.systems/install.sh | bash -s -- --to /bin

WORKDIR /app

COPY . .

COPY --from=www /app/build /app/www/build


RUN cargo build --bin hifi-rs --release --target aarch64-unknown-linux-gnu
RUN just build-player aarch64-unknown-linux-gnu

RUN mv target/aarch64-unknown-linux-gnu/release/hifi-rs /usr/local/bin

Expand Down
2 changes: 1 addition & 1 deletion build_arm64.sh
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#!/bin/sh

docker build -f Dockerfile.arm64 -t hifirs .
docker build --no-cache -f Dockerfile.arm64 -t hifirs .
docker cp $(docker create hifirs:latest):hifi-rs .
1 change: 0 additions & 1 deletion hifirs/build.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,5 +2,4 @@
fn main() {
// trigger recompilation when a new migration is added
println!("cargo:rerun-if-changed=migrations");
println!("cargo:rustc-link-search=static=/usr/lib/x86_64-linux-gnu/");
}
14 changes: 4 additions & 10 deletions hifirs/src/player/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -258,11 +258,7 @@ pub fn duration() -> Option<ClockTime> {
#[instrument]
/// Seek to a specified time in the current track.
pub async fn seek(time: ClockTime, flags: Option<SeekFlags>) -> Result<()> {
let flags = if let Some(flags) = flags {
flags
} else {
SeekFlags::FLUSH | SeekFlags::TRICKMODE_KEY_UNITS
};
let flags = flags.unwrap_or(SeekFlags::FLUSH | SeekFlags::TRICKMODE_KEY_UNITS);

PLAYBIN.seek_simple(flags, time)?;
Ok(())
Expand Down Expand Up @@ -379,7 +375,9 @@ pub async fn skip(new_position: u32, force: bool) -> Result<()> {
}
}

ready().await?;
if !is_ready() {
ready().await?;
}

if let Some(next_track_to_play) = state.skip_track(new_position).await {
let list = state.track_list();
Expand Down Expand Up @@ -531,25 +529,21 @@ async fn prep_next_track() -> Result<()> {
pub fn notify_receiver() -> BroadcastReceiver {
BROADCAST_CHANNELS.rx.clone()
}

#[instrument]
/// Returns the current track list loaded in the player.
pub async fn current_tracklist() -> TrackListValue {
QUEUE.get().unwrap().read().await.track_list()
}

#[instrument]
/// Returns the current track loaded in the player.
pub async fn current_track() -> Option<Track> {
QUEUE.get().unwrap().read().await.current_track().cloned()
}

#[instrument]
/// Returns true if the player is currently buffering data.
pub fn is_buffering() -> bool {
IS_BUFFERING.load(Ordering::Relaxed)
}

#[instrument]
/// Search the service.
pub async fn search(query: &str) -> SearchResults {
Expand Down
118 changes: 118 additions & 0 deletions justfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,118 @@
detected_target := if os() == "linux" {
if arch() == "x86_64" {
"x86_64-unknown-linux-gnu"
} else if arch() == "aarch64" {
"aarch64-unknown-linux-gnu"
} else {
error("unknown os and/or arch")
}
} else if os() == "macos" {
if arch() == "x86_64" {
"x86_64-apple-darwin"
} else if arch() == "aarch64" {
"aarch64-apple-darwin"
} else {
error("unsupported os and/or arch")
}
} else {
error("unsupported os and/or arch")
}

default:
@just --list

build-player target=detected_target $DATABASE_URL="sqlite:///tmp/data.db":
just install-deps {{target}}
just build-www
just add-target {{target}}
just install-toolchain "stable" {{target}}
just install-sqlx
just reset-database
just build-bin hifi-rs {{target}}

build-all-bins target=detected_target:
just build --bins --release {{target}}

build-bin bin target=detected_target:
@echo Building for target {{target}}
cargo build --bin={{bin}} --release --target={{target}}

build-www:
@echo Building web ui...
cd www && npm install && npm run build

install-deps target=detected_target:
#!/usr/bin/env sh
if ! just check-deps; then
{{ if target == "x86_64-unknown-linux-gnu" { "just install-deps-linux-x86_64" } else if target == "aarch64-unknown-linux-gnu" { "just install-deps-linux-aarch64" } else { error("unsupported arch") } }}
echo "Dependencies installed successfully for {{target}}"
fi
check-rustup:
#!/usr/bin/env sh
if ! [ -x "$(command -v rustup)" ]; then
echo 'Error: rustup is not installed.' >&2
exit 1
fi
add-target target=detected_target:
rustup target add {{target}}
install-toolchain kind="stable" target=detected_target:
rustup toolchain install {{kind}}-{{target}}
install-sqlx:
cargo install sqlx-cli
reset-database:
touch $(echo $DATABASE_URL | sed -e "s/sqlite:\/\///g") && cargo sqlx database reset --source {{invocation_directory()}}/hifirs/migrations -y
check-deps:
#!/usr/bin/env sh
echo "Checking for required dependecies..."
if ! [ -x "$(command -v pkg-config)" ]; then
echo 'pkg-config not installed'
exit 1
fi
if $(pkg-config --atleast-version "1.18" gstreamer-1.0); then
echo "Dependencies found!"
else
exit 1
fi
[linux]
install-deps-linux-x86_64:
#!/usr/bin/env sh
echo Installing dependencies for x86_64-unknown-linux-gnu
if [ -x "$(command -v apt-get)" ]; then
apt-get update && DEBIAN_FRONTEND=noninteractive apt-get install -qq libunwind-dev libgstreamer1.0-dev libgstreamer-plugins-base1.0-dev nodejs npm
elif [ -x "$(command -v pacman)" ]; then
sudo pacman -S gstreamer gst-plugins-base-libs nodejs
elif [ -x "$(command -v dnf)" ]; then
dnf install gstreamer1-devel gstreamer1-plugins-base-devel nodejs18
else
echo "distro not supported for x86_64-unknown-linux-gnu"
exit 1
fi
[linux]
install-deps-linux-aarch64:
#!/usr/bin/env sh
echo Installing dependencies for aarch64-unknown-linux-gnu
if [ -x "$(command -v apt-get)" ]; then
dpkg --add-architecture arm64
apt-get update && DEBIAN_FRONTEND=noninteractive apt-get -qq install curl libgstreamer1.0-dev:arm64 g++-aarch64-linux-gnu libc6-dev-arm64-cross libglib2.0-dev:arm64 nodejs npm
else
echo "distro not supported for aarch64-unknown-linux-gnu"
exit 1
fi
[macos]
install-deps-macos:
#!/usr/bin/env sh
if [ -x "$(command -v brew)" ]; then
brew install gstreamer
else
echo "Homebrew command not found."
fi
Loading

0 comments on commit 690e498

Please sign in to comment.