Skip to content

Commit f7247d1

Browse files
timonvoJorge Aparicio
authored andcommitted
Add ARM MUSL targets.
The targets are: - `arm-unknown-linux-musleabi` - `arm-unknown-linux-musleabihf` - `armv7-unknown-linux-musleabihf` These mirror the existing `gnueabi` targets. All of these targets produce fully static binaries, similar to the x86 MUSL targets. For now these targets can only be used with `--rustbuild` builds, as rust-lang/compiler-rt#22 only made the necessary compiler-rt changes in the CMake configs, not the plain GNU Make configs. I've tested these targets GCC 5.3.0 compiled again musl-1.1.12 (downloaded from http://musl.codu.org/). An example `./configure` invocation is: ``` ./configure \ --enable-rustbuild --target=arm-unknown-linux-musleabi \ --musl-root="$MUSL_ROOT" ``` where `MUSL_ROOT` points to the `arm-linux-musleabi` prefix. Usually that path will be of the form `/foobar/arm-linux-musleabi/arm-linux-musleabi`. Usually the cross-compile toolchain will live under `/foobar/arm-linux-musleabi/bin`. That path should either by added to your `PATH` variable, or you should add a section to your `config.toml` as follows: ``` [target.arm-unknown-linux-musleabi] cc = "/foobar/arm-linux-musleabi/bin/arm-linux-musleabi-gcc" cxx = "/foobar/arm-linux-musleabi/bin/arm-linux-musleabi-g++" ``` As a prerequisite you'll also have to put a cross-compiled static `libunwind.a` library in `$MUSL_ROOT/lib`. This is similar to [how the x86_64 MUSL targets are built] (https://doc.rust-lang.org/book/advanced-linking.html).
1 parent 57cad57 commit f7247d1

15 files changed

+210
-9
lines changed

configure

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1192,7 +1192,7 @@ do
11921192
;;
11931193

11941194

1195-
x86_64-*-musl)
1195+
x86_64-*-musl | arm-*-musleabi)
11961196
if [ ! -f $CFG_MUSL_ROOT/lib/libc.a ]
11971197
then
11981198
err "musl libc $CFG_MUSL_ROOT/lib/libc.a not found"

mk/cfg/arm-unknown-linux-musleabi.mk

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
# This file is intentially left empty to indicate that, while this target is
2+
# supported, it's not supported using plain GNU Make builds. Use a --rustbuild
3+
# instead.
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
# This file is intentially left empty to indicate that, while this target is
2+
# supported, it's not supported using plain GNU Make builds. Use a --rustbuild
3+
# instead.
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
# This file is intentially left empty to indicate that, while this target is
2+
# supported, it's not supported using plain GNU Make builds. Use a --rustbuild
3+
# instead.

src/bootstrap/compile.rs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -92,8 +92,7 @@ pub fn std_link(build: &Build,
9292
}
9393
add_to_sysroot(&out_dir, &libdir);
9494

95-
if target.contains("musl") &&
96-
(target.contains("x86_64") || target.contains("i686")) {
95+
if target.contains("musl") && !target.contains("mips") {
9796
copy_third_party_objects(build, target, &libdir);
9897
}
9998
}

src/bootstrap/sanity.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -109,7 +109,7 @@ pub fn check(build: &mut Build) {
109109
}
110110

111111
// Make sure musl-root is valid if specified
112-
if target.contains("musl") && (target.contains("x86_64") || target.contains("i686")) {
112+
if target.contains("musl") && !target.contains("mips") {
113113
match build.config.musl_root {
114114
Some(ref root) => {
115115
if fs::metadata(root.join("lib/libc.a")).is_err() {

src/liballoc_jemalloc/build.rs

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -73,7 +73,16 @@ fn main() {
7373
.replace("\\", "/"))
7474
.current_dir(&build_dir)
7575
.env("CC", compiler.path())
76-
.env("EXTRA_CFLAGS", cflags)
76+
.env("EXTRA_CFLAGS", cflags.clone())
77+
// jemalloc generates Makefile deps using GCC's "-MM" flag. This means
78+
// that GCC will run the preprocessor, and only the preprocessor, over
79+
// jemalloc's source files. If we don't specify CPPFLAGS, then at least
80+
// on ARM that step fails with a "Missing implementation for 32-bit
81+
// atomic operations" error. This is because no "-march" flag will be
82+
// passed to GCC, and then GCC won't define the
83+
// "__GCC_HAVE_SYNC_COMPARE_AND_SWAP_4" macro that jemalloc needs to
84+
// select an atomic operation implementation.
85+
.env("CPPFLAGS", cflags.clone())
7786
.env("AR", &ar)
7887
.env("RANLIB", format!("{} s", ar.display()));
7988

src/liballoc_jemalloc/lib.rs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,9 @@ use libc::{c_int, c_void, size_t};
3636
#[cfg_attr(target_os = "android", link(name = "gcc"))]
3737
#[cfg_attr(all(not(windows),
3838
not(target_os = "android"),
39-
not(target_env = "musl")),
39+
not(target_env = "musl"),
40+
not(target_env = "musleabi"),
41+
not(target_env = "musleabihf")),
4042
link(name = "pthread"))]
4143
#[cfg(not(cargobuild))]
4244
extern "C" {}
Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
// Copyright 2016 The Rust Project Developers. See the COPYRIGHT
2+
// file at the top-level directory of this distribution and at
3+
// http://rust-lang.org/COPYRIGHT.
4+
//
5+
// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
6+
// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
7+
// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
8+
// option. This file may not be copied, modified, or distributed
9+
// except according to those terms.
10+
11+
use target::Target;
12+
13+
pub fn target() -> Target {
14+
let mut base = super::musl_base::opts();
15+
16+
// Most of these settings are copied from the arm_unknown_linux_gnueabi
17+
// target.
18+
base.features = "+v6".to_string();
19+
Target {
20+
// It's important we use "gnueabi" and not "musleabi" here. LLVM uses it
21+
// to determine the calling convention and float ABI, and it doesn't
22+
// support the "musleabi" value.
23+
llvm_target: "arm-unknown-linux-gnueabi".to_string(),
24+
target_endian: "little".to_string(),
25+
target_pointer_width: "32".to_string(),
26+
data_layout: "e-m:e-p:32:32-i64:64-v128:64:128-a:0:32-n32-S64".to_string(),
27+
arch: "arm".to_string(),
28+
target_os: "linux".to_string(),
29+
target_env: "musleabi".to_string(),
30+
target_vendor: "unknown".to_string(),
31+
options: base,
32+
}
33+
}
Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
// Copyright 2016 The Rust Project Developers. See the COPYRIGHT
2+
// file at the top-level directory of this distribution and at
3+
// http://rust-lang.org/COPYRIGHT.
4+
//
5+
// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
6+
// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
7+
// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
8+
// option. This file may not be copied, modified, or distributed
9+
// except according to those terms.
10+
11+
use target::Target;
12+
13+
pub fn target() -> Target {
14+
let mut base = super::musl_base::opts();
15+
16+
// Most of these settings are copied from the arm_unknown_linux_gnueabihf
17+
// target.
18+
base.features = "+v6,+vfp2".to_string();
19+
Target {
20+
// It's important we use "gnueabihf" and not "musleabihf" here. LLVM
21+
// uses it to determine the calling convention and float ABI, and it
22+
// doesn't support the "musleabihf" value.
23+
llvm_target: "arm-unknown-linux-gnueabihf".to_string(),
24+
target_endian: "little".to_string(),
25+
target_pointer_width: "32".to_string(),
26+
data_layout: "e-m:e-p:32:32-i64:64-v128:64:128-a:0:32-n32-S64".to_string(),
27+
arch: "arm".to_string(),
28+
target_os: "linux".to_string(),
29+
target_env: "musleabi".to_string(),
30+
target_vendor: "unknown".to_string(),
31+
options: base,
32+
}
33+
}

0 commit comments

Comments
 (0)