8.2 KiB
Building from Source
Pre-requisites
- Go
- GolangCI - A meta-linter which runs several linters in parallel
- To install, follow the local installation instructions
- Yarn - Yarn package manager
Environment
Windows
- Download and install Go for Windows
- Download and extract MinGW64 (scroll down and select x86_64-posix-seh, don't use the autoinstaller, it doesn't work)
- Search for "Advanced System Settings" and open the System Properties dialog.
- Click the
Environment Variables
button - Under System Variables find
Path
. Edit and addC:\MinGW\bin
(replace with the correct path to where you extracted MingW64).
- Click the
NOTE: The make
command in Windows will be mingw32-make
with MinGW. For example, make pre-ui
will be mingw32-make pre-ui
.
macOS
- If you don't have it already, install the Homebrew package manager.
- Install dependencies:
brew install go git yarn gcc make node ffmpeg
Linux
Arch Linux
- Install dependencies:
sudo pacman -S go git yarn gcc make nodejs ffmpeg --needed
Ubuntu
- Install dependencies:
sudo apt-get install golang git yarnpkg gcc nodejs ffmpeg -y
OpenBSD
- Install dependencies
doas pkg_add gmake go git yarn node cmake
- Compile a custom ffmpeg from ports. The default ffmpeg in OpenBSD's packages is not compiled with WebP support, which is required by Stash.
- If you've already installed ffmpeg, uninstall it:
doas pkg_delete ffmpeg
- If you haven't already, fetch the ports tree and verify.
- Find the ffmpeg port in
/usr/ports/graphics/ffmpeg
, and patch the Makefile to include libwebp- Add
webp
toWANTLIB
- Add
graphics/libwebp
to the list inLIB_DEPENDS
- Add
-lwebp -lwebpdecoder -lwebpdemux -lwebpmux
toLIBavcodec_EXTRALIBS
- Add
--enable-libweb
to the list inCONFIGURE_ARGS
- If you've already built ffmpeg from ports before, you may need to also increment
REVISION
- Run
doas make install
- Add
- Follow the instructions below to build a release, but replace the final step
make build-release
withgmake flags-release stash
, to avoid the PIE buildmode.
- If you've already installed ffmpeg, uninstall it:
NOTE: The make
command in OpenBSD will be gmake
. For example, make pre-ui
will be gmake pre-ui
.
Commands
make pre-ui
- Installs the UI dependencies. This only needs to be run once after cloning the repository, or if the dependencies are updated.make generate
- Generates Go and UI GraphQL files. Requiresmake pre-ui
to have been run.make generate-stash-box-client
- Generate Go files for the Stash-box client code.make ui
- Builds the UI. Requiresmake pre-ui
to have been run.make stash
- Builds thestash
binary (make sure to build the UI as well... see below)make stash-macapp
- Builds theStash.app
macOS app (only works when on macOS, for cross-compilation see below)make phasher
- Builds thephasher
binarymake build
- Builds both thestash
andphasher
binaries, alias formake stash phasher
make build-release
- Builds release versions (debug information removed) of both thestash
andphasher
binaries, alias formake flags-release flags-pie build
make docker-build
- Locally builds and tags a complete 'stash/build' docker imagemake docker-cuda-build
- Locally builds and tags a complete 'stash/cuda-build' docker imagemake validate
- Runs all of the tests and checks required to submit a PRmake lint
- Runsgolangci-lint
on the backendmake it
- Runs all unit and integration testsmake fmt
- Formats the Go source codemake fmt-ui
- Formats the UI source codemake server-start
- Runs a development stash server in the.local
directorymake server-clean
- Removes the.local
directory and all of its contentsmake ui-start
- Runs the UI in development mode. Requires a running Stash server to connect to - the server URL can be changed from the default ofhttp://localhost:9999
using the environment variableVITE_APP_PLATFORM_URL
, but keep in mind that authentication cannot be used since the session authorization cookie cannot be sent cross-origin. The UI runs on port3000
or the next available port.
When building, you can optionally prepend flags-*
targets to the target list in your make
command to use different build flags:
flags-release
(e.g.make flags-release stash
) - Remove debug information from the binary.flags-pie
(e.g.make flags-pie build
) - Build a PIE (Position Independent Executable) binary. This provides increased security, but it is unsupported on some systems (notably 32-bit ARM and OpenBSD).flags-static
(e.g.make flags-static phasher
) - Build a statically linked binary (the default is a dynamically linked binary).flags-static-pie
(e.g.make flags-static-pie stash
) - Build a statically linked PIE binary (usingflags-static
andflags-pie
separately will not work).flags-static-windows
(e.g.make flags-static-windows build
) - Identical toflags-static-pie
, but does not enable thenetgo
build tag, which is not needed for static builds on Windows.
Local development quickstart
- Run
make pre-ui
to install UI dependencies - Run
make generate
to create generated files - In one terminal, run
make server-start
to run the server code - In a separate terminal, run
make ui-start
to run the UI in development mode - Open the UI in a browser:
http://localhost:3000/
Changes to the UI code can be seen by reloading the browser page.
Changes to the backend code require a server restart (CTRL-C
in the server terminal, followed by make server-start
again) to be seen.
On first launch:
- On the "Stash Setup Wizard" screen, choose a directory with some files to test with
- Press "Next" to use the default locations for the database and generated content
- Press the "Confirm" and "Finish" buttons to get into the UI
- On the side menu, navigate to "Tasks -> Library -> Scan" and press the "Scan" button
- You're all set! Set any other configurations you'd like and test your code changes.
To start fresh with new configuration:
- Stop the server (
CTRL-C
in the server terminal) - Run
make server-clean
to clear all config, database, and generated files (under.local
) - Run
make server-start
to restart the server - Follow the "On first launch" steps above
Building a release
Simply run make
or make release
, or equivalently:
- Run
make pre-ui
to install UI dependencies - Run
make generate
to create generated files - Run
make ui
to build the frontend - Run
make build-release
to build a release executable for your current platform
Cross-compiling
This project uses a modification of the CI-GoReleaser Docker container for cross-compilation, defined in docker/compiler/Dockerfile
.
To cross-compile the app yourself:
- Run
make pre-ui
,make generate
andmake ui
outside the container, to generate files and build the UI. - Pull the latest compiler image from Docker Hub:
docker pull stashapp/compiler
- Run
docker run --rm --mount type=bind,source="$(pwd)",target=/stash -w /stash -it stashapp/compiler /bin/bash
to open a shell inside the container. - From inside the container, run
make build-cc-all
to build for all platforms, or runmake build-cc-{platform}
to build for a specific platform (have a look at theMakefile
for the list of targets). - You will find the compiled binaries in
dist/
.
NOTE: Since the container is run as UID 0 (root), the resulting binaries (and the dist/
folder itself, if it had to be created) will be owned by root.
Profiling
Stash can be profiled using the --cpuprofile <output profile filename>
command line flag.
The resulting file can then be used with pprof as follows:
go tool pprof <path to binary> <path to profile filename>
With graphviz
installed and in the path, a call graph can be generated with:
go tool pprof -svg <path to binary> <path to profile filename> > <output svg file>