{"id":15051097,"url":"https://github.com/joseluisq/rust-linux-darwin-builder","last_synced_at":"2025-04-10T02:20:58.624Z","repository":{"id":47393186,"uuid":"230994554","full_name":"joseluisq/rust-linux-darwin-builder","owner":"joseluisq","description":"Use the same Docker image to cross-compile Rust x86_64/ARM64 programs for Linux and macOS (osxcross).","archived":false,"fork":false,"pushed_at":"2024-03-29T13:51:59.000Z","size":226,"stargazers_count":104,"open_issues_count":6,"forks_count":15,"subscribers_count":4,"default_branch":"master","last_synced_at":"2024-04-22T14:23:34.352Z","etag":null,"topics":["aarch64","amd64","arm64","arm64v8","darwin","darwin-builder","debian","debian-bookworm","debian-bullseye","debian-linux","docker-image","linux","linux-image","macos","musl-gcc","musl-libc","osxcross","rust-lang","x86-64"],"latest_commit_sha":null,"homepage":"","language":"Dockerfile","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"apache-2.0","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/joseluisq.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE-APACHE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null}},"created_at":"2019-12-30T23:39:15.000Z","updated_at":"2024-08-13T23:40:17.339Z","dependencies_parsed_at":"2023-02-16T10:01:51.419Z","dependency_job_id":"f978f8f5-a92c-4989-bc8d-075c8504f1ce","html_url":"https://github.com/joseluisq/rust-linux-darwin-builder","commit_stats":{"total_commits":110,"total_committers":6,"mean_commits":"18.333333333333332","dds":"0.10909090909090913","last_synced_commit":"cc8f47698e09e4fd678e8855fac7cba8b0e46cea"},"previous_names":[],"tags_count":57,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/joseluisq%2Frust-linux-darwin-builder","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/joseluisq%2Frust-linux-darwin-builder/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/joseluisq%2Frust-linux-darwin-builder/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/joseluisq%2Frust-linux-darwin-builder/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/joseluisq","download_url":"https://codeload.github.com/joseluisq/rust-linux-darwin-builder/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":248143105,"owners_count":21054707,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["aarch64","amd64","arm64","arm64v8","darwin","darwin-builder","debian","debian-bookworm","debian-bullseye","debian-linux","docker-image","linux","linux-image","macos","musl-gcc","musl-libc","osxcross","rust-lang","x86-64"],"created_at":"2024-09-24T21:30:53.741Z","updated_at":"2025-04-10T02:20:58.595Z","avatar_url":"https://github.com/joseluisq.png","language":"Dockerfile","funding_links":[],"categories":[],"sub_categories":[],"readme":"\u003cdiv\u003e\n  \u003cdiv align=\"center\"\u003e\n    \u003cimg src=\"https://www.rust-lang.org/logos/rust-logo-blk.svg\" height=\"130\" width=\"130\" /\u003e\n  \u003c/div\u003e\n\n  \u003ch1 align=\"center\"\u003eRust Linux / Darwin Builder\u003c/h1\u003e\n\n  \u003ch4 align=\"center\"\u003e\n    Use the same Docker image to cross-compile Rust programs for Linux (musl libc) and macOS (osxcross)\n  \u003c/h4\u003e\n\n\u003cdiv align=\"center\"\u003e\n\n  [![Build Status](https://api.cirrus-ci.com/github/joseluisq/rust-linux-darwin-builder.svg)](https://cirrus-ci.com/github/joseluisq/rust-linux-darwin-builder) [![Docker Image Version (tag latest semver)](https://img.shields.io/docker/v/joseluisq/rust-linux-darwin-builder/1)](https://hub.docker.com/r/joseluisq/rust-linux-darwin-builder/) [![Docker Image Size (tag)](https://img.shields.io/docker/image-size/joseluisq/rust-linux-darwin-builder/1)](https://hub.docker.com/r/joseluisq/rust-linux-darwin-builder/tags) [![Docker Image](https://img.shields.io/docker/pulls/joseluisq/rust-linux-darwin-builder.svg)](https://hub.docker.com/r/joseluisq/rust-linux-darwin-builder/)\n\n\u003c/div\u003e\n\n\u003c/div\u003e\n\n## Overview\n\nThis is a __Linux Docker image__ based on [ekidd/rust-musl-builder](https://hub.docker.com/r/ekidd/rust-musl-builder) but using the latest __Debian [12-slim](https://hub.docker.com/_/debian/tags?page=1\u0026name=12-slim)__ ([Bookworm](https://www.debian.org/News/2023/20230610)).\n\nIt contains essential tools for cross-compile [Rust](https://www.rust-lang.org/) projects such as __Linux__ static binaries via [musl-libc / musl-gcc](https://doc.rust-lang.org/edition-guide/rust-2018/platform-and-target-support/musl-support-for-fully-static-binaries.html) (`x86_64-unknown-linux-musl`) and __macOS__ binaries (`x86_64-apple-darwin`) via [osxcross](https://github.com/tpoechtrager/osxcross) just using the same Linux image.\n\nThe Docker image is [multi-arch](https://www.docker.com/blog/multi-arch-build-and-images-the-simple-way/) (`amd64` and `arm64`) so you can use them in native environments.\nAlso, it is possible to cross-compile `arm64` Linux or Darwin apps from the `x86_64` Docker image variant.\n\n## Usage\n\n### Compiling an application inside a Docker container\n\nBy default, the working directory is `/root/src`.\n\n### x86_64 (amd64)\n\nBelow are the default toolchains included in the Docker image.\n\n#### x86_64-unknown-linux-musl\n\n```sh\ndocker run --rm \\\n    --volume \"${PWD}/sample\":/root/src \\\n    --workdir /root/src \\\n      joseluisq/rust-linux-darwin-builder:1.84.1 \\\n        sh -c \"cargo build --release --target x86_64-unknown-linux-musl\"\n```\n\n#### x86_64-unknown-linux-gnu\n\n```sh\ndocker run --rm \\\n    --volume \"${PWD}/sample\":/root/src \\\n    --workdir /root/src \\\n      joseluisq/rust-linux-darwin-builder:1.84.1 \\\n        sh -c \"cargo build --release --target x86_64-unknown-linux-gnu\"\n```\n\n#### x86_64-apple-darwin\n\n```sh\ndocker run --rm \\\n    --volume \"${PWD}/sample\":/root/src \\\n    --workdir /root/src \\\n      joseluisq/rust-linux-darwin-builder:1.84.1 \\\n        sh -c \"cargo build --release --target x86_64-apple-darwin\"\n```\n\n### aarch64 (arm64)\n\n#### aarch64-unknown-linux-gnu\n\n```sh\ndocker run --rm \\\n    --volume \"${PWD}/sample\":/root/src \\\n    --workdir /root/src \\\n      joseluisq/rust-linux-darwin-builder:1.84.1 \\\n        sh -c \"cargo build --release --target aarch64-unknown-linux-gnu\"\n```\n\n#### aarch64-unknown-linux-musl\n\n```sh\ndocker run --rm \\\n    --volume \"${PWD}/sample\":/root/src \\\n    --workdir /root/src \\\n      joseluisq/rust-linux-darwin-builder:1.84.1 \\\n        sh -c \"cargo build --release --target aarch64-unknown-linux-musl\"\n```\n\n#### aarch64-apple-darwin\n\n```sh\ndocker run --rm \\\n    --volume \"${PWD}/sample\":/root/src \\\n    --workdir /root/src \\\n      joseluisq/rust-linux-darwin-builder:1.84.1 \\\n        sh -c \"cargo build --release --target aarch64-apple-darwin\"\n```\n\n### Cargo Home advice\n\nIt's known that the [`CARGO_HOME`](https://doc.rust-lang.org/cargo/guide/cargo-home.html#cargo-home) points to `$HOME/.cargo` by default (`/root/.cargo` in this case). However, if you want to use a custom Cargo home directory then make sure to copy the Cargo `config` file to the particular directory like `cp \"$HOME/.cargo/config\" \"$CARGO_HOME/\"` before to cross-compile your program. Otherwise, you could face a linking error when for example you want to cross-compile to an `x86_64-apple-darwin` target.\n\n### Dockerfile\n\nYou can also use the image as a base for your Dockerfile:\n\n```Dockerfile\nFROM joseluisq/rust-linux-darwin-builder:1.84.1\n```\n\n### OSXCross\n\nYou can also use o32-clang(++) and o64-clang(++) as a normal compiler.\n\n__Notes:__\n\n- The current *11.3 SDK* does not support i386 anymore. Use \u003c= 10.13 SDK if you rely on i386 support.\n- The current *11.3 SDK* does not support libstdc++ anymore. Use \u003c= 10.13 SDK if you rely on libstdc++ support.\n\nExamples:\n\n```sh\nExample usage:\n\nExample 1: CC=o32-clang ./configure --host=i386-apple-darwin22.4\nExample 2: CC=i386-apple-darwin22.4-clang ./configure --host=i386-apple-darwin22.4\nExample 3: o64-clang -Wall test.c -o test\nExample 4: x86_64-apple-darwin22.4-strip -x test\n\n!!! Use aarch64-apple-darwin22.4-* instead of arm64-* when dealing with Automake !!!\n!!! CC=aarch64-apple-darwin22.4-clang ./configure --host=aarch64-apple-darwin22.4 !!!\n!!! CC=\"aarch64-apple-darwin22.4-clang -arch arm64e\" ./configure --host=aarch64-apple-darwin22.4 !!!\n```\n\n### Cross-compilation example\n\nBelow is a simple example of using a `Makefile` to cross-compile a Rust app.\n\nNotes:\n\n- A [hello world](./tests/hello-world) app is used.\n- A custom directory is used below as a working directory instead of `/root/src`.\n\nCreate a Makefile:\n\n```sh\ncompile:\n\t@docker run --rm -it \\\n\t\t-v $(PWD):/app/src \\\n\t\t-w /app/src \\\n\t\t\tjoseluisq/rust-linux-darwin-builder:1.84.1 \\\n\t\t\t\tmake cross-compile\n.PHONY: compile\n\ncross-compile:\n\t@echo\n\t@echo \"1. Cross compiling example...\"\n\t@rustc -vV\n\t@echo\n\t@echo \"2. Compiling application (linux-musl x86_64)...\"\n\t@cargo build --manifest-path=tests/hello-world/Cargo.toml --release --target x86_64-unknown-linux-musl\n\t@du -sh tests/hello-world/target/x86_64-unknown-linux-musl/release/helloworld\n\t@echo\n\t@echo \"3. Compiling application (apple-darwin x86_64)...\"\n\t@cargo build --manifest-path=tests/hello-world/Cargo.toml --release --target x86_64-apple-darwin\n\t@du -sh tests/hello-world/target/x86_64-apple-darwin/release/helloworld\n.PHONY: cross-compile\n```\n\nJust run the makefile `compile` target, then you will see two release binaries `x86_64-unknown-linux-musl` and `x86_64-apple-darwin`.\n\n```sh\nmake compile\n# rustc 1.84.1 (e71f9a9a9 2025-01-27)\n# binary: rustc\n# commit-hash: e71f9a9a98b0faf423844bf0ba7438f29dc27d58\n# commit-date: 2025-01-27\n# host: x86_64-unknown-linux-gnu\n# release: 1.84.1\n# LLVM version: 19.1.5\n\n# 2. Compiling application (linux-musl x86_64)...\n#     Finished release [optimized] target(s) in 0.01s\n# 1.2M\ttests/hello-world/target/x86_64-unknown-linux-musl/release/helloworld\n\n# 3. Compiling application (apple-darwin x86_64)...\n#     Finished release [optimized] target(s) in 0.01s\n# 240K\ttests/hello-world/target/x86_64-apple-darwin/release/helloworld\n```\n\nFor more details take a look at [Cross-compiling Rust from Linux to macOS](https://wapl.es/rust/2019/02/17/rust-cross-compile-linux-to-macos.html) by James Waples.\n\n### Macos ARM64\n\nSee [joseluisq/rust-linux-darwin-builder#7](https://github.com/joseluisq/rust-linux-darwin-builder/issues/7)\n\n### Building *-sys crates\n\nIf some of your crates require C bindings and you run into a compilation or linking error, try to use Clang for C/C++ builds.\n\nFor example to cross-compile to Macos:\n\n```sh\nCC=o64-clang \\\nCXX=o64-clang++ \\\n\tcargo build --target x86_64-apple-darwin\n  # Or\n\tcargo build --target aarch64-apple-darwin\n```\n\n### OpenSSL release advice\n\n\u003e _Until `v1.42.0` of this project, one old OpenSSL release `v1.0.2` was used._ \u003cbr\u003e\n\u003e _Now, since `v1.43.x` or greater, OpenSSL `v1.1.1` (LTS) is used which is supported until `2023-09-11`. \u003cbr\u003e\n\u003e View more at https://www.openssl.org/policies/releasestrat.html._\n\n## Contributions\n\nUnless you explicitly state otherwise, any contribution intentionally submitted for inclusion in current work by you, as defined in the Apache-2.0 license, shall be dual licensed as described below, without any additional terms or conditions.\n\nFeel free to send some [Pull request](https://github.com/joseluisq/rust-linux-darwin-builder/pulls) or file an [issue](https://github.com/joseluisq/rust-linux-darwin-builder/issues).\n\n## License\n\nThis work is primarily distributed under the terms of both the [MIT license](LICENSE-MIT) and the [Apache License (Version 2.0)](LICENSE-APACHE).\n\n© 2019-present [Jose Quintana](https://github.com/joseluisq)\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fjoseluisq%2Frust-linux-darwin-builder","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fjoseluisq%2Frust-linux-darwin-builder","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fjoseluisq%2Frust-linux-darwin-builder/lists"}