Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Optimize binary size #15

Merged
merged 26 commits into from
Mar 2, 2024
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
42 changes: 29 additions & 13 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ name: ci

on:
push:
pull_request:
workflow_dispatch:

concurrency:
Expand All @@ -16,7 +15,7 @@ jobs:
GO111MODULE: "on"
steps:
- name: Checkout code
uses: actions/checkout@v3
uses: actions/checkout@v4

- name: Install Go
uses: actions/setup-go@v4
Expand All @@ -27,12 +26,18 @@ jobs:
run: go get ./...

- name: Build
run: go build -v .
run: go build -ldflags="-s -w" -gcflags=all="-l -B" -trimpath -buildvcs=false -v .

- name: Run UPX
uses: crazy-max/ghaction-upx@v3
with:
files: goqoa.exe
args: --brute

- name: Go Test
run: go test -v ./...

- uses: actions/upload-artifact@v3
- uses: actions/upload-artifact@v4
with:
name: windows
path: goqoa.exe
Expand All @@ -44,7 +49,7 @@ jobs:
CGO_ENABLED: 1
steps:
- name: Checkout code
uses: actions/checkout@v3
uses: actions/checkout@v4

- name: Install Go
uses: actions/setup-go@v4
Expand All @@ -55,12 +60,12 @@ jobs:
run: go get ./...

- name: Build
run: go build -o goqoa-mac -v .
run: go build -ldflags="-s -w" -gcflags=all="-l -B" -trimpath -buildvcs=false -o goqoa-mac -v .

- name: Go Test
run: go test -v ./...

- uses: actions/upload-artifact@v3
- uses: actions/upload-artifact@v4
with:
name: mac
path: goqoa-mac
Expand All @@ -72,7 +77,7 @@ jobs:
CGO_ENABLED: 1
steps:
- name: Checkout code
uses: actions/checkout@v3
uses: actions/checkout@v4

- name: Install Go
uses: actions/setup-go@v4
Expand All @@ -83,20 +88,31 @@ jobs:
run: |
go get ./...
sudo apt-get update
sudo apt-get install -y libasound2-dev libmp3lame-dev
sudo apt-get install -y libasound2-dev

- name: Build
run: go build -o goqoa-linux -v .
run: |
go build -ldflags="-s -w" -gcflags=all="-l -B" -trimpath -buildvcs=false -o goqoa-linux -v .
upx --best goqoa-linux

- name: Go Test
run: go test -v ./...

- name: Cache large spec pack
uses: actions/cache@v3
with:
key: qoa_test_samples_2023_02_18.zip
path: qoa_test_samples_2023_02_18.zip

- name: Download large spec pack
run: wget --timestamping https://qoaformat.org/samples/qoa_test_samples_2023_02_18.zip

- name: Spec Test
run: |
sudo cp goqoa-linux /usr/bin/goqoa
bash check_spec.sh

- uses: actions/upload-artifact@v3
- uses: actions/upload-artifact@v4
with:
name: linux
path: goqoa-linux
Expand All @@ -113,8 +129,8 @@ jobs:
runs-on: ubuntu-latest
steps:
- name: Checkout code
uses: actions/checkout@v3
- uses: actions/download-artifact@v3
uses: actions/checkout@v4
- uses: actions/checkout@v4
- name: Release
uses: softprops/action-gh-release@v1
with:
Expand Down
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -35,9 +35,9 @@ The easiest way is a pre-built binary on the [Releases](https://github.com/brahe
Otherwise, install prerequisites for your platform:

# Fedora
yum install gcc alsa-lib-devel lame-devel
yum install gcc alsa-lib-devel
# Debian
apt-get install gcc pkg-config libasound2-dev libmp3lame-dev
apt-get install gcc pkg-config libasound2-dev

Then, install directly with Go:

Expand Down
8 changes: 5 additions & 3 deletions check_spec.sh
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ size_compare() {
size2=$(stat -c %s "$2")

if [ "$size1" != "$size2" ]; then
echo "Checksums do not match!"
echo "Sizes do not match!"
echo "$1: $size1"
echo "$2: $size2"
exit 1
Expand All @@ -37,18 +37,20 @@ fi
selected_songs=$(unzip -Z1 "$spec_zip" '*.wav' -x '*.qoa.wav' | shuf -n "$num_songs")

for song in $selected_songs; do
echo "Checking $song..."
song_filename=$(basename "$song")
song_name="${song_filename%.*}"

unzip -j -qq $spec_zip "*$song_name*" -d "$temp_dir"

goqoa -q convert "$temp_dir/$song_name.wav" "$temp_dir/my-$song_name.qoa"
goqoa convert "$temp_dir/$song_name.wav" "$temp_dir/my-$song_name.qoa"
size_compare "$temp_dir/$song_name.qoa" "$temp_dir/my-$song_name.qoa"

goqoa -h
goqoa -q convert "$temp_dir/my-$song_name.qoa" "$temp_dir/my-$song_name.qoa.wav"
size_compare "$temp_dir/$song_name.qoa.wav" "$temp_dir/my-$song_name.qoa.wav"

echo -e "$song_name\tOK"
echo "OK"
done

rm -rf "$temp_dir" &>/dev/null
4 changes: 2 additions & 2 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -8,15 +8,15 @@ require (
github.com/go-audio/audio v1.0.0
github.com/go-audio/wav v1.1.0
github.com/jfreymuth/oggvorbis v1.0.5
github.com/spf13/cobra v1.8.0
github.com/mewkiz/flac v1.0.10
github.com/spf13/cobra v1.8.0
github.com/stretchr/testify v1.8.4
github.com/tosone/minimp3 v1.0.2
)

require (
github.com/davecgh/go-spew v1.1.1 // indirect
github.com/ebitengine/purego v0.5.0 // indirect
github.com/ebitengine/purego v0.6.0 // indirect
github.com/go-audio/riff v1.0.0 // indirect
github.com/icza/bitio v1.1.0 // indirect
github.com/inconshreveable/mousetrap v1.1.0 // indirect
Expand Down
4 changes: 2 additions & 2 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,8 @@ github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c
github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
github.com/ebitengine/oto/v3 v3.1.0 h1:9tChG6rizyeR2w3vsygTTTVVJ9QMMyu00m2yBOCch6U=
github.com/ebitengine/oto/v3 v3.1.0/go.mod h1:IK1QTnlfZK2GIB6ziyECm433hAdTaPpOsGMLhEyEGTg=
github.com/ebitengine/purego v0.5.0 h1:JrMGKfRIAM4/QVKaesIIT7m/UVjTj5GYhRSQYwfVdpo=
github.com/ebitengine/purego v0.5.0/go.mod h1:ah1In8AOtksoNK6yk5z1HTJeUkC1Ez4Wk2idgGslMwQ=
github.com/ebitengine/purego v0.6.0 h1:Yo9uBc1x+ETQbfEaf6wcBsjrQfCEnh/gaGUg7lguEJY=
github.com/ebitengine/purego v0.6.0/go.mod h1:ah1In8AOtksoNK6yk5z1HTJeUkC1Ez4Wk2idgGslMwQ=
github.com/go-audio/audio v1.0.0 h1:zS9vebldgbQqktK4H0lUqWrG8P0NxCJVqcj7ZpNnwd4=
github.com/go-audio/audio v1.0.0/go.mod h1:6uAu0+H2lHkwdGsAY+j2wHPNPpPoeg5AaEFh9FlA+Zs=
github.com/go-audio/riff v1.0.0 h1:d8iCGbDvox9BfLagY94fBynxSPHO80LmZCaOsmKxokA=
Expand Down
4 changes: 2 additions & 2 deletions pkg/qoa/qoa_test.go
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
package qoa

import (
"bytes"
"fmt"
"log"
"os"
"reflect"
"testing"

"github.com/go-audio/wav"
Expand All @@ -28,7 +28,7 @@ func TestEncodeHeader(t *testing.T) {

qoa.encodeHeader(header)

if !reflect.DeepEqual(header, expectedHeader) {
if !bytes.Equal(header, expectedHeader) {
t.Errorf("Header encoding mismatch.\nExpected: %#v\nGot: %#v", expectedHeader, header)
}
}
Expand Down
Loading