From 2e6166e807cd3c7e13aefb59b02adc0221c052fa Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Hannes=20K=C3=B6rber?= Date: Fri, 27 May 2022 23:37:54 +0200 Subject: [PATCH] Link binary statically with musl --- Cargo.lock | 10 +++++++ Cargo.toml | 12 +++++++- Justfile | 15 ++++++---- docs/src/SUMMARY.md | 2 +- docs/src/getting_started.md | 22 --------------- docs/src/installation.md | 56 +++++++++++++++++++++++++++++++++++++ 6 files changed, 88 insertions(+), 29 deletions(-) delete mode 100644 docs/src/getting_started.md create mode 100644 docs/src/installation.md diff --git a/Cargo.lock b/Cargo.lock index a18aa39..2ab7172 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -609,6 +609,15 @@ version = "0.1.5" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "ff011a302c396a5197692431fc1948019154afc178baf7d8e37367442a4601cf" +[[package]] +name = "openssl-src" +version = "111.20.0+1.1.1o" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "92892c4f87d56e376e469ace79f1128fdaded07646ddf73aa0be4706ff712dec" +dependencies = [ + "cc", +] + [[package]] name = "openssl-sys" version = "0.9.73" @@ -618,6 +627,7 @@ dependencies = [ "autocfg", "cc", "libc", + "openssl-src", "pkg-config", "vcpkg", ] diff --git a/Cargo.toml b/Cargo.toml index 249c5af..29dc95e 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -2,6 +2,7 @@ name = "git-repo-manager" version = "0.7.0" edition = "2021" + authors = [ "Hannes Körber ", ] @@ -73,7 +74,8 @@ version = "=1.0.81" [dependencies.isahc] version = "=1.7.2" -features = ["json"] +default-features = false +features = ["json", "http2", "text-decoding"] [dependencies.parse_link_header] version = "=0.3.2" @@ -83,3 +85,11 @@ version = "=0.1.1" [dev-dependencies.tempdir] version = "=0.3.7" + +[features] +static-build = [ + "git2/vendored-openssl", + "git2/vendored-libgit2", + "isahc/static-curl", + "isahc/static-ssl", +] diff --git a/Justfile b/Justfile index 4c6e46a..a9d3975 100644 --- a/Justfile +++ b/Justfile @@ -1,5 +1,7 @@ set positional-arguments +target := "x86_64-unknown-linux-musl" + check: test cargo check cargo fmt --check @@ -16,23 +18,26 @@ lint-fix: cargo clippy --no-deps --fix release: - cargo build --release + cargo build --release --target {{target}} test-binary-docker: env \ GITHUB_API_BASEURL=http://rest:5000/github \ GITLAB_API_BASEURL=http://rest:5000/gitlab \ - cargo build --profile e2e-tests + cargo build --target {{target}} --profile e2e-tests --features=static-build test-binary: env \ GITHUB_API_BASEURL=http://localhost:5000/github \ GITLAB_API_BASEURL=http://localhost:5000/gitlab \ - cargo build --profile e2e-tests + cargo build --target {{target}} --profile e2e-tests install: cargo install --path . +install-static: + cargo install --target {{target}} --features=static-build --path . + test: test-unit test-integration test-e2e test-unit: @@ -47,7 +52,7 @@ test-e2e-docker +tests=".": test-binary-docker && docker-compose build \ && docker-compose run \ --rm \ - -v $PWD/../target/e2e-tests/grm:/grm \ + -v $PWD/../target/{{target}}/e2e-tests/grm:/grm \ pytest \ "GRM_BINARY=/grm python3 ALTERNATE_DOMAIN=alternate-rest -m pytest -p no:cacheprovider --color=yes "$@"" \ && docker-compose rm --stop -f @@ -57,7 +62,7 @@ test-e2e +tests=".": test-binary && docker-compose rm --stop -f \ && docker-compose build \ && docker-compose up -d rest \ - && GRM_BINARY={{justfile_directory()}}/target/e2e-tests/grm ALTERNATE_DOMAIN=127.0.0.1 python3 -m pytest -p no:cacheprovider --color=yes {{tests}} \ + && GRM_BINARY={{justfile_directory()}}/target/{{target}}/e2e-tests/grm ALTERNATE_DOMAIN=127.0.0.1 python3 -m pytest -p no:cacheprovider --color=yes {{tests}} \ && docker-compose rm --stop -f update-dependencies: update-cargo-dependencies diff --git a/docs/src/SUMMARY.md b/docs/src/SUMMARY.md index cd7b635..259d759 100644 --- a/docs/src/SUMMARY.md +++ b/docs/src/SUMMARY.md @@ -1,7 +1,7 @@ # Summary - [Overview](./overview.md) -- [Getting started](./getting_started.md) +- [Installation](./installation.md) - [Repository trees](./repos.md) - [Git Worktrees](./worktrees.md) - [Forge Integrations](./forge_integration.md) diff --git a/docs/src/getting_started.md b/docs/src/getting_started.md deleted file mode 100644 index c630fbd..0000000 --- a/docs/src/getting_started.md +++ /dev/null @@ -1,22 +0,0 @@ -# Quickstart - -## Installation - -Building GRM currently requires the nightly Rust toolchain. The easiest way -is using [`rustup`](https://rustup.rs/). Make sure that rustup is properly installed. - -Make sure that the nightly toolchain is installed: - -``` -$ rustup toolchain install nightly -``` - -```bash -$ cargo +nightly install --git https://github.com/hakoerber/git-repo-manager.git --branch master -``` - -If you're brave, you can also run the development build: - -```bash -$ cargo +nightly install --git https://github.com/hakoerber/git-repo-manager.git --branch develop -``` diff --git a/docs/src/installation.md b/docs/src/installation.md new file mode 100644 index 0000000..da97400 --- /dev/null +++ b/docs/src/installation.md @@ -0,0 +1,56 @@ +# Installation + +## Installation + +Building GRM currently requires the nightly Rust toolchain. The easiest way +is using [`rustup`](https://rustup.rs/). Make sure that rustup is properly installed. + +Make sure that the nightly toolchain is installed: + +``` +$ rustup toolchain install nightly +``` + +Then, install the build dependencies: + +| Distribution | Command | +| ------------- | ------------------------------------------------------------------------------ | +| Archlinux | `pacman -S --needed gcc openssl pkg-config` | +| Ubuntu/Debian | `apt-get install --no-install-recommends pkg-config gcc libssl-dev zlib1g-dev` | + +Then, it's a simple command to install the latest stable version: + +```bash +$ cargo +nightly install git-repo-manager +``` + +If you're brave, you can also run the development build: + +```bash +$ cargo +nightly install --git https://github.com/hakoerber/git-repo-manager.git --branch develop +``` + +## Static build + +Note that by default, you will get a dynamically linked executable. +Alternatively, you can also build a statically linked binary. For this, you +will need `musl` and a few other build dependencies installed installed: + +| Distribution | Command | +| ------------- | --------------------------------------------------------------------------- | +| Archlinux | `pacman -S --needed gcc musl perl make` | +| Ubuntu/Debian | `apt-get install --no-install-recommends gcc musl-tools libc-dev perl make` | + +(`perl` and `make` are required for the OpenSSL build script) + +The, add the musl target via `rustup`: + +``` +$ rustup +nightly target add x86_64-unknown-linux-musl +``` + +Then, use a modified build command to get a statically linked binary: + +``` +$ cargo +nightly install git-repo-manager --target x86_64-unknown-linux-musl --features=static-build +```