Skip to content

Commit 7b026f0

Browse files
author
Jorge Aparicio
committed
add support for mips(el)-unknown-linux-musl
This target covers MIPS devices that run the trunk version of OpenWRT. The x86_64-unknown-linux-musl target always links statically to C libraries. For the mips(el)-unknown-linux-musl target, we opt for dynamic linking (like most of other targets do) to keep binary size down. As for the C compiler flags used in the build system, we use the same flags used for the mips(el)-unknown-linux-gnu target.
1 parent 0f196bc commit 7b026f0

File tree

10 files changed

+115
-5
lines changed

10 files changed

+115
-5
lines changed

.gitmodules

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,4 +16,5 @@
1616
url = https://github.com/rust-lang/rust-installer.git
1717
[submodule "src/liblibc"]
1818
path = src/liblibc
19-
url = https://github.com/rust-lang-nursery/libc.git
19+
url = https://github.com/japaric/libc.git
20+
branch = mips-musl

configure

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1178,7 +1178,7 @@ do
11781178
;;
11791179

11801180

1181-
*-musl)
1181+
x86_64-*-musl)
11821182
if [ ! -f $CFG_MUSL_ROOT/lib/libc.a ]
11831183
then
11841184
err "musl libc $CFG_MUSL_ROOT/lib/libc.a not found"

mk/cfg/mips-unknown-linux-musl.mk

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
# mips-unknown-linux-musl configuration
2+
CC_mips-unknown-linux-musl=mips-openwrt-linux-gcc
3+
CXX_mips-unknown-linux-musl=mips-openwrt-linux-g++
4+
CPP_mips-unknown-linux-musl=mips-openwrt-linux-gcc -E
5+
AR_mips-unknown-linux-musl=mips-openwrt-linux-ar
6+
CFG_LIB_NAME_mips-unknown-linux-musl=lib$(1).so
7+
CFG_STATIC_LIB_NAME_mips-unknown-linux-musl=lib$(1).a
8+
CFG_LIB_GLOB_mips-unknown-linux-musl=lib$(1)-*.so
9+
CFG_LIB_DSYM_GLOB_mips-unknown-linux-musl=lib$(1)-*.dylib.dSYM
10+
CFG_JEMALLOC_CFLAGS_mips-unknown-linux-musl := -mips32r2 -msoft-float -mabi=32 $(CFLAGS)
11+
CFG_GCCISH_CFLAGS_mips-unknown-linux-musl := -Wall -g -fPIC -mips32r2 -msoft-float -mabi=32 $(CFLAGS)
12+
CFG_GCCISH_CXXFLAGS_mips-unknown-linux-musl := -fno-rtti $(CXXFLAGS)
13+
CFG_GCCISH_LINK_FLAGS_mips-unknown-linux-musl := -shared -fPIC -g -mips32r2 -msoft-float -mabi=32
14+
CFG_GCCISH_DEF_FLAG_mips-unknown-linux-musl := -Wl,--export-dynamic,--dynamic-list=
15+
CFG_LLC_FLAGS_mips-unknown-linux-musl :=
16+
CFG_INSTALL_NAME_mips-unknown-linux-musl =
17+
CFG_EXE_SUFFIX_mips-unknown-linux-musl =
18+
CFG_WINDOWSY_mips-unknown-linux-musl :=
19+
CFG_UNIXY_mips-unknown-linux-musl := 1
20+
CFG_LDPATH_mips-unknown-linux-musl :=
21+
CFG_RUN_mips-unknown-linux-musl=
22+
CFG_RUN_TARG_mips-unknown-linux-musl=
23+
RUSTC_FLAGS_mips-unknown-linux-musl := -C target-cpu=mips32r2 -C target-feature="+mips32r2" -C soft-float
24+
CFG_GNU_TRIPLE_mips-unknown-linux-musl := mips-unknown-linux-musl

mk/cfg/mipsel-unknown-linux-musl.mk

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
# mipsel-unknown-linux-musl configuration
2+
CC_mipsel-unknown-linux-musl=mipsel-openwrt-linux-gcc
3+
CXX_mipsel-unknown-linux-musl=mipsel-openwrt-linux-g++
4+
CPP_mipsel-unknown-linux-musl=mipsel-openwrt-linux-gcc
5+
AR_mipsel-unknown-linux-musl=mipsel-openwrt-linux-ar
6+
CFG_LIB_NAME_mipsel-unknown-linux-musl=lib$(1).so
7+
CFG_STATIC_LIB_NAME_mipsel-unknown-linux-musl=lib$(1).a
8+
CFG_LIB_GLOB_mipsel-unknown-linux-musl=lib$(1)-*.so
9+
CFG_LIB_DSYM_GLOB_mipsel-unknown-linux-musl=lib$(1)-*.dylib.dSYM
10+
CFG_JEMALLOC_CFLAGS_mipsel-unknown-linux-musl := -mips32 -mabi=32 $(CFLAGS)
11+
CFG_GCCISH_CFLAGS_mipsel-unknown-linux-musl := -Wall -g -fPIC -mips32 -mabi=32 $(CFLAGS)
12+
CFG_GCCISH_CXXFLAGS_mipsel-unknown-linux-musl := -fno-rtti $(CXXFLAGS)
13+
CFG_GCCISH_LINK_FLAGS_mipsel-unknown-linux-musl := -shared -fPIC -g -mips32
14+
CFG_GCCISH_DEF_FLAG_mipsel-unknown-linux-musl := -Wl,--export-dynamic,--dynamic-list=
15+
CFG_LLC_FLAGS_mipsel-unknown-linux-musl :=
16+
CFG_INSTALL_NAME_mipsel-unknown-linux-musl =
17+
CFG_EXE_SUFFIX_mipsel-unknown-linux-musl :=
18+
CFG_WINDOWSY_mipsel-unknown-linux-musl :=
19+
CFG_UNIXY_mipsel-unknown-linux-musl := 1
20+
CFG_LDPATH_mipsel-unknown-linux-musl :=
21+
CFG_RUN_mipsel-unknown-linux-musl=
22+
CFG_RUN_TARG_mipsel-unknown-linux-musl=
23+
RUSTC_FLAGS_mipsel-unknown-linux-musl := -C target-cpu=mips32 -C target-feature="+mips32"
24+
CFG_GNU_TRIPLE_mipsel-unknown-linux-musl := mipsel-unknown-linux-musl

src/liblibc

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
// Copyright 2014 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+
Target {
15+
llvm_target: "mips-unknown-linux-musl".to_string(),
16+
target_endian: "big".to_string(),
17+
target_pointer_width: "32".to_string(),
18+
arch: "mips".to_string(),
19+
target_os: "linux".to_string(),
20+
target_env: "musl".to_string(),
21+
target_vendor: "unknown".to_string(),
22+
options: super::linux_base::opts()
23+
}
24+
}
Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
// Copyright 2014 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+
Target {
15+
llvm_target: "mipsel-unknown-linux-musl".to_string(),
16+
target_endian: "little".to_string(),
17+
target_pointer_width: "32".to_string(),
18+
arch: "mips".to_string(),
19+
target_os: "linux".to_string(),
20+
target_env: "musl".to_string(),
21+
target_vendor: "unknown".to_string(),
22+
23+
options: super::linux_base::opts()
24+
}
25+
}

src/librustc_back/target/mod.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -420,6 +420,8 @@ impl Target {
420420
armv7_unknown_linux_gnueabihf,
421421
aarch64_unknown_linux_gnu,
422422
x86_64_unknown_linux_musl,
423+
mips_unknown_linux_musl,
424+
mipsel_unknown_linux_musl,
423425

424426
i686_linux_android,
425427
arm_linux_androideabi,

src/libstd/os/linux/raw.rs

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -93,11 +93,20 @@ mod arch {
9393
use os::raw::{c_long, c_ulong};
9494
use os::unix::raw::{gid_t, uid_t};
9595

96+
#[cfg(target_env = "musl")]
97+
#[stable(feature = "raw_ext", since = "1.1.0")] pub type blkcnt_t = i64;
98+
#[cfg(not(target_env = "musl"))]
9699
#[stable(feature = "raw_ext", since = "1.1.0")] pub type blkcnt_t = i32;
97100
#[stable(feature = "raw_ext", since = "1.1.0")] pub type blksize_t = i32;
101+
#[cfg(target_env = "musl")]
102+
#[stable(feature = "raw_ext", since = "1.1.0")] pub type ino_t = u64;
103+
#[cfg(not(target_env = "musl"))]
98104
#[stable(feature = "raw_ext", since = "1.1.0")] pub type ino_t = u32;
99105
#[stable(feature = "raw_ext", since = "1.1.0")] pub type nlink_t = u32;
106+
#[cfg(target_env = "musl")]
100107
#[stable(feature = "raw_ext", since = "1.1.0")] pub type off_t = i32;
108+
#[cfg(not(target_env = "musl"))]
109+
#[stable(feature = "raw_ext", since = "1.1.0")] pub type off_t = i64;
101110
#[stable(feature = "raw_ext", since = "1.1.0")] pub type time_t = i32;
102111

103112
#[repr(C)]

src/libstd/sys/common/libunwind.rs

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -101,9 +101,10 @@ pub type _Unwind_Exception_Cleanup_Fn =
101101
exception: *mut _Unwind_Exception);
102102

103103
#[cfg_attr(any(all(target_os = "linux", not(target_env = "musl")),
104-
target_os = "freebsd"),
104+
target_os = "freebsd",
105+
all(target_os = "linux", target_env = "musl", not(target_arch = "x86_64"))),
105106
link(name = "gcc_s"))]
106-
#[cfg_attr(all(target_os = "linux", target_env = "musl", not(test)),
107+
#[cfg_attr(all(target_os = "linux", target_env = "musl", target_arch = "x86_64", not(test)),
107108
link(name = "unwind", kind = "static"))]
108109
#[cfg_attr(any(target_os = "android", target_os = "openbsd"),
109110
link(name = "gcc"))]

0 commit comments

Comments
 (0)