Skip to content

Commit 8c685f1

Browse files
committed
docs: improve descriptions and examples
1 parent 9745977 commit 8c685f1

File tree

2 files changed

+93
-29
lines changed

2 files changed

+93
-29
lines changed

LICENSE-MIT

Lines changed: 18 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -1,23 +1,20 @@
1-
Permission is hereby granted, free of charge, to any
2-
person obtaining a copy of this software and associated
3-
documentation files (the "Software"), to deal in the
4-
Software without restriction, including without
5-
limitation the rights to use, copy, modify, merge,
6-
publish, distribute, sublicense, and/or sell copies of
7-
the Software, and to permit persons to whom the Software
8-
is furnished to do so, subject to the following
9-
conditions:
1+
The MIT License (MIT)
102

11-
The above copyright notice and this permission notice
12-
shall be included in all copies or substantial portions
13-
of the Software.
3+
Copyright (c) 2019-present Jose Quintana <https://git.io/joseluisq>
144

15-
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF
16-
ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED
17-
TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A
18-
PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT
19-
SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
20-
CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
21-
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR
22-
IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
23-
DEALINGS IN THE SOFTWARE.
5+
Permission is hereby granted, free of charge, to any person obtaining a copy of
6+
this software and associated documentation files (the "Software"), to deal in
7+
the Software without restriction, including without limitation the rights to
8+
use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of
9+
the Software, and to permit persons to whom the Software is furnished to do so,
10+
subject to the following conditions:
11+
12+
The above copyright notice and this permission notice shall be included in all
13+
copies or substantial portions of the Software.
14+
15+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
17+
FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
18+
COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
19+
IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
20+
CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.

README.md

Lines changed: 75 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
1-
# Rust Linux / Darwin Builder [![Docker Image](https://img.shields.io/docker/pulls/joseluisq/rust-linux-darwin-builder.svg)](https://hub.docker.com/r/joseluisq/rust-linux-darwin-builder/)
1+
# 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/) [![Build Status](https://travis-ci.com/joseluisq/rust-linux-darwin-builder.svg?branch=master)](https://travis-ci.com/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/)
22

33
> Use same Docker image for compiling [Rust](https://www.rust-lang.org/) programs for Linux ([musl libc](https://doc.rust-lang.org/edition-guide/rust-2018/platform-and-target-support/musl-support-for-fully-static-binaries.html)) & macOS ([osxcross](https://github.com/tpoechtrager/osxcross)).
44
55
## Overview
66

7-
This is a __Linux Docker image__ that extends from [ekidd/rust-musl-builder](https://hub.docker.com/r/ekidd/rust-musl-builder) containing all necessary tools for 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.
7+
This is a __Linux Docker image__ based on [ekidd/rust-musl-builder](https://hub.docker.com/r/ekidd/rust-musl-builder) but using [debian:buster-slim](https://hub.docker.com/_/debian?tab=tags&page=1&name=buster-slim). It contains essential tools for 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.
88

99
## Usage
1010

@@ -17,7 +17,7 @@ docker run --rm \
1717
--user rust:rust \
1818
--volume "${PWD}/sample":/home/rust/sample \
1919
--workdir /home/rust/sample \
20-
joseluisq/rust-linux-darwin-builder:1.40.0 \
20+
joseluisq/rust-linux-darwin-builder:1.42.0 \
2121
sh -c "cargo build --release"
2222
```
2323

@@ -28,18 +28,85 @@ docker run --rm \
2828
--user rust:rust \
2929
--volume "${PWD}/sample":/home/rust/sample \
3030
--workdir /home/rust/sample \
31-
joseluisq/rust-linux-darwin-builder:1.40.0 \
31+
joseluisq/rust-linux-darwin-builder:1.42.0 \
3232
sh -c "cargo build --release --target x86_64-apple-darwin"
3333
```
3434

35-
*__Note:__ This example is also available under [./sample](./sample) directory.*
36-
3735
### Dockerfile
3836

3937
You can also use the image as a base for your own Dockerfile:
4038

4139
```Dockerfile
42-
FROM joseluisq/rust-linux-darwin-builder:1.40.0
40+
FROM joseluisq/rust-linux-darwin-builder:1.42.0
41+
```
42+
43+
### Custom directories
44+
45+
By default this image uses a `rust` user and the default working directory is `/home/rust`.
46+
If you want to use a different directory, change the corresponding owner and group as well.
47+
48+
```sh
49+
sudo chown -R rust:rust /custom/directory
50+
```
51+
52+
#### Cross-compilation example
53+
54+
Below a simple example using a `Makefile` for cross-compiling a Rust app.
55+
56+
Notes:
57+
58+
- A [hello world](./tests/hello-world) app is used.
59+
- A custom directory is used below as working directory (instead of `/home/rust`).
60+
- If you want to use the default `/home/rust` as working directory, owner and group change is not necessary.
61+
62+
Create a Makefile:
63+
64+
```sh
65+
compile:
66+
@docker run --rm -it \
67+
-v $(PWD):/drone/src \
68+
-w /drone/src \
69+
joseluisq/rust-linux-darwin-builder:1.42.0 \
70+
make cross-compile
71+
.PHONY: compile
72+
73+
cross-compile:
74+
@sudo chown -R rust:rust ./
75+
@echo
76+
@echo "1. Cross compiling example..."
77+
@rustc -vV
78+
@echo
79+
@echo "2. Compiling application (linux-musl x86_64)..."
80+
@cargo build --manifest-path=tests/hello-world/Cargo.toml --release --target x86_64-unknown-linux-musl
81+
@du -sh tests/hello-world/target/x86_64-unknown-linux-musl/release/helloworld
82+
@echo
83+
@echo "3. Compiling application (apple-darwin x86_64)..."
84+
@cargo build --manifest-path=tests/hello-world/Cargo.toml --release --target x86_64-apple-darwin
85+
@du -sh tests/hello-world/target/x86_64-apple-darwin/release/helloworld
86+
.PHONY: cross-compile
87+
```
88+
89+
Just run the makefile `compile` target, then you will see two release binaries `x86_64-unknown-linux-musl` and `x86_64-apple-darwin`).
90+
91+
```sh
92+
make compile
93+
# 1. Cross compiling example...
94+
95+
# rustc 1.42.0 (b8cedc004 2020-03-09)
96+
# binary: rustc
97+
# commit-hash: b8cedc00407a4c56a3bda1ed605c6fc166655447
98+
# commit-date: 2020-03-09
99+
# host: x86_64-unknown-linux-gnu
100+
# release: 1.42.0
101+
# LLVM version: 9.0
102+
103+
# 2. Compiling application (linux-musl x86_64)...
104+
# Finished release [optimized] target(s) in 0.01s
105+
# 1.2M tests/hello-world/target/x86_64-unknown-linux-musl/release/helloworld
106+
107+
# 3. Compiling application (apple-darwin x86_64)...
108+
# Finished release [optimized] target(s) in 0.01s
109+
# 240K tests/hello-world/target/x86_64-apple-darwin/release/helloworld
43110
```
44111

45112
## Contributions
@@ -52,4 +119,4 @@ Feel free to send some [Pull request](https://github.com/joseluisq/rust-linux-da
52119

53120
This work is primarily distributed under the terms of both the [MIT license](LICENSE-MIT) and the [Apache License (Version 2.0)](LICENSE-APACHE).
54121

55-
© 2019 [Jose Quintana](https://git.io/joseluisq)
122+
© 2019-present [Jose Quintana](https://git.io/joseluisq)

0 commit comments

Comments
 (0)