All Projects → clux → Muslrust

clux / Muslrust

Licence: mit
Docker environment for building musl based static rust binaries

Programming Languages

rust
11053 projects

Projects that are alternatives of or similar to Muslrust

Baur
baur manages builds and artifacts in mono repositories
Stars: ✭ 285 (-37.5%)
Mutual labels:  build
Angular Bazel Example
MOVED to the bazel nodejs monorepo 👉
Stars: ✭ 354 (-22.37%)
Mutual labels:  build
Url
Parse, build and manipulate URL's
Stars: ✭ 396 (-13.16%)
Mutual labels:  build
Psdeploy
Simple PowerShell based deployments
Stars: ✭ 302 (-33.77%)
Mutual labels:  build
Node Build Monitor
A Build Monitor written in Node.js, which supports several build services and can be easily extended.
Stars: ✭ 336 (-26.32%)
Mutual labels:  build
Appify
Create a macOS Application from an executable (like a Go binary)
Stars: ✭ 372 (-18.42%)
Mutual labels:  build
Oryx
Build your repo automatically.
Stars: ✭ 283 (-37.94%)
Mutual labels:  build
Cpp Reflection
C++ Reflection Parser / Runtime Skeleton
Stars: ✭ 440 (-3.51%)
Mutual labels:  build
Platform Espressif32
Espressif 32: development platform for PlatformIO
Stars: ✭ 333 (-26.97%)
Mutual labels:  build
Buildtimeanalyzer For Xcode
Build Time Analyzer for Swift
Stars: ✭ 3,958 (+767.98%)
Mutual labels:  build
U3d
U3d is a cross-platform set of tools to interact with Unity3D from command line.
Stars: ✭ 309 (-32.24%)
Mutual labels:  build
Tensorflow Windows Wheel
Tensorflow prebuilt binary for Windows
Stars: ✭ 3,428 (+651.75%)
Mutual labels:  build
Fury
A new build tool for JVM languages
Stars: ✭ 384 (-15.79%)
Mutual labels:  build
Ant
Apache Ant is a Java-based build tool.
Stars: ✭ 296 (-35.09%)
Mutual labels:  build
Opencv Mingw Build
👀 MinGW 32bit and 64bit version of OpenCV compiled on Windows. Including OpenCV 3.3.1, 3.4.1, 3.4.1-x64, 3.4.5, 3.4.6, 3.4.7, 3.4.8-x64, 3.4.9, 4.0.0-alpha-x64, 4.0.0-rc-x64, 4.0.1-x64, 4.1.0, 4.1.0-x64, 4.1.1-x64, 4.5.0-with-contrib
Stars: ✭ 401 (-12.06%)
Mutual labels:  build
Bazel
a fast, scalable, multi-language and extensible build system
Stars: ✭ 17,790 (+3801.32%)
Mutual labels:  build
Unity Actions
Github actions for testing and building Unity projects
Stars: ✭ 358 (-21.49%)
Mutual labels:  build
Invoke Build
Build Automation in PowerShell
Stars: ✭ 453 (-0.66%)
Mutual labels:  build
Assemble
Community
Stars: ✭ 3,995 (+776.1%)
Mutual labels:  build
Samurai
ninja-compatible build tool written in C
Stars: ✭ 390 (-14.47%)
Mutual labels:  build

muslrust

build status docker pulls docker image info docker tag

A plain docker environment for building static binaries compiled with rust and linked against musl instead of glibc. Built nightly on travis.

This is useful if you require external C dependencies, and/or need a CI image to compile a musl binary. Locally, you could do rustup target add x86_64-unknown-linux-musl if you don't need C dependencies.

This container comes with a bunch of statically compiled C libraries using musl-gcc so that we can statically link against these as well.

For embedded targets, consider cross as a more general solution.

Usage

Pull and run from a rust project root:

docker pull clux/muslrust
docker run -v $PWD:/volume --rm -t clux/muslrust cargo build

You should have a static executable in the target folder:

ldd target/x86_64-unknown-linux-musl/debug/EXECUTABLE
        not a dynamic executable

From there on, you can include it in a blank docker image, distroless/static, or alpine (if you absolutely need kubectl exec), and you can end up with say:

Docker builds

Latest is always the last built nightly pushed by travis. To pin against specific builds, see the available tags on the docker hub.

C Libraries

The following system libraries are compiled against musl-gcc:

We try to keep these up to date.

If it weren't for pq, we could ditch zlib as the flate2 crate bundles miniz.c as the default implementation, and this just works. Similarly, curl is only needed for people using the C bindings to curl over hyper.

If you need extra dependencies, you can follow the builder pattern approach by portier-broker

Developing

Clone, tweak, build, and run tests:

git clone [email protected]:clux/muslrust.git && cd muslrust
make build
make test

Before we push a new version of muslrust we ensure that we can use and statically link:

  • [x] serde
  • [x] diesel (postgres and sqlite - see note below for postgres)
  • [x] hyper
  • [x] curl
  • [x] openssl
  • [x] flate2
  • [x] rand
  • [ ] rocket (nightly only - some gaps)

SSL Verification

You need to point openssl at the location of your certificates explicitly to have https requests not return certificate errors.

export SSL_CERT_FILE=/etc/ssl/certs/ca-certificates.crt
export SSL_CERT_DIR=/etc/ssl/certs

You can also hardcode this in your binary, or, more sensibly set it in your running docker image. The openssl-probe crate can be also be used to detect where these reside.

Diesel and PQ builds

Works without fork now. See the test/dieselpgcrate for how to get this working.

For stuff like infer_schema! to work you need to explicitly pass on -e DATABASE_URL=$DATABASE_URL to the docker run. It's probably easier to just make diesel print-schema > src/schema.rs part of your migration setup though.

Note that diesel compiles with openssl statically since 1.34.0, so you need to include the openssl crate before diesel due to pq-sys#25:

extern crate openssl;
#[macro_use] extern crate diesel;

This is true even if you connect without sslmode=require.

Caching Cargo Locally

Repeat builds locally are always from scratch (thus slow) without a cached cargo directory. You can set up a docker volume by just adding -v cargo-cache:/root/.cargo/registry to the docker run command.

You'll have an extra volume that you can inspect with docker volume inspect cargo-cache.

Suggested developer usage is to add the following function to your ~/.bashrc:

musl-build() {
  docker run \
    -v cargo-cache:/root/.cargo/registry \
    -v "$PWD:/volume" \
    --rm -it clux/muslrust cargo build --release
}

Then use in your project:

$ cd myproject
$ musl-build
    Finished release [optimized] target(s) in 0.0 secs

Second time around this will be quick, and you can even mix it with native cargo build calls without screwing with your cache.

Debugging in blank containers

If you are running a plain alpine/scratch container with your musl binary in there, then you might need to compile with debug symbols, and set ENV RUST_BACKTRACE=full in your Dockerfile.

In alpine, if even this doesn't work (or fails to give you line numbers), try installing the rust package (via apk). This should not be necessary anymore though!

For easily grabbing backtraces from rust docker apps; try adding sentry. It seems to be able to grab backtraces regardless of compile options/evars.

Using muslrust on CI

Due to the current best compatibility with docker caching strategies, recommended CI is Circle. See webapp-rs, operator-rs, or raftcat for complete life-cycle rust cloud applications running in alpine containers built on CI (first two are demos, second one has more stuff).

Extra Rustup components

You can install extra components distributed via Rustup like normal:

rustup component add clippy

Binaries distributed via Cargo

If you need to install a binary crate such as ripgrep on a CI build image, you need to build it against the GNU toolchain (see #37):

CARGO_BUILD_TARGET=x86_64-unknown-linux-gnu cargo install ripgrep

SELinux

On SELinux enabled systems like Fedora, you will need to configure selinux labes. E.g. adding the :Z or :z flags where appropriate: -v $PWD:/volume:Z.

Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].