Skip to content

Commit c9c7908

Browse files
committed
Auto merge of #28593 - gandro:rumprun, r=alexcrichton
This adds a new target, `x86_64-rumprun-netbsd`, and related changes to `std`. Rumprun is a unikernel platform that provides a POSIX-y interface. For the most part, rumprun uses NetBSD's libc and drivers, therefore `target_os` is `netbsd`. However, being a unikernel, rumprun does not support process management, signals or virtual memory, so related functions might fail at runtime. For this reason, stack guards are disabled in `std`. To support conditional compilation, `target_env` is set to `rumprun`. Maybe `target_vendor` would be technically more fitting, but it doesn't seem to be worth the hassle. Code for rumprun is always cross-compiled, it uses always static linking and needs a custom linker. The target makes use of the newly introduced `no_default_libs` flag, as the rumprun linker will otherwise not use the correct search path.
2 parents e266651 + c099cfa commit c9c7908

File tree

9 files changed

+85
-6
lines changed

9 files changed

+85
-6
lines changed

configure

+6
Original file line numberDiff line numberDiff line change
@@ -1295,6 +1295,12 @@ $ pacman -R cmake && pacman -S mingw-w64-x86_64-cmake
12951295
putvar CFG_MSVC_LIB_PATH_${bits}
12961296
;;
12971297

1298+
*-rumprun-netbsd)
1299+
step_msg "targeting rumprun-netbsd, disabling jemalloc"
1300+
CFG_DISABLE_JEMALLOC=1
1301+
putvar CFG_DISABLE_JEMALLOC
1302+
;;
1303+
12981304
*)
12991305
;;
13001306
esac

mk/cfg/x86_64-rumprun-netbsd.mk

+24
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
# x86_64-rumprun-netbsd configuration
2+
CROSS_PREFIX_x86_64-rumprun-netbsd=x86_64-rumprun-netbsd-
3+
CC_x86_64-rumprun-netbsd=gcc
4+
CXX_x86_64-rumprun-netbsd=g++
5+
CPP_x86_64-rumprun-netbsd=gcc -E
6+
AR_x86_64-rumprun-netbsd=ar
7+
CFG_INSTALL_ONLY_RLIB_x86_64-rumprun-netbsd = 1
8+
CFG_LIB_NAME_x86_64-rumprun-netbsd=lib$(1).so
9+
CFG_STATIC_LIB_NAME_x86_64-rumprun-netbsd=lib$(1).a
10+
CFG_LIB_GLOB_x86_64-rumprun-netbsd=lib$(1)-*.so
11+
CFG_JEMALLOC_CFLAGS_x86_64-rumprun-netbsd := -m64
12+
CFG_GCCISH_CFLAGS_x86_64-rumprun-netbsd := -Wall -Werror -g -fPIC -m64
13+
CFG_GCCISH_CXXFLAGS_x86_64-rumprun-netbsd :=
14+
CFG_GCCISH_LINK_FLAGS_x86_64-rumprun-netbsd :=
15+
CFG_GCCISH_DEF_FLAG_x86_64-rumprun-netbsd :=
16+
CFG_LLC_FLAGS_x86_64-rumprun-netbsd :=
17+
CFG_INSTALL_NAME_x86_64-rumprun-netbsd =
18+
CFG_EXE_SUFFIX_x86_64-rumprun-netbsd =
19+
CFG_WINDOWSY_x86_64-rumprun-netbsd :=
20+
CFG_UNIXY_x86_64-rumprun-netbsd := 1
21+
CFG_LDPATH_x86_64-rumprun-netbsd :=
22+
CFG_RUN_x86_64-rumprun-netbsd=$(2)
23+
CFG_RUN_TARG_x86_64-rumprun-netbsd=$(call CFG_RUN_x86_64-rumprun-netbsd,,$(2))
24+
CFG_GNU_TRIPLE_x86_64-rumprun-netbsd := x86_64-rumprun-netbsd

src/liblibc/lib.rs

+5-1
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@
2424
html_playground_url = "https://play.rust-lang.org/",
2525
issue_tracker_base_url = "https://github.com/rust-lang/rust/issues/")]
2626
#![cfg_attr(test, feature(test))]
27+
#![feature(cfg_target_vendor)]
2728

2829
//! Bindings for the C standard library and other platform libraries
2930
//!
@@ -143,7 +144,10 @@ pub use funcs::bsd43::*;
143144

144145
// On NaCl, these libraries are static. Thus it would be a Bad Idea to link them
145146
// in when creating a test crate.
146-
#[cfg(not(any(windows, target_env = "musl", all(target_os = "nacl", test))))]
147+
#[cfg(not(any(windows,
148+
target_env = "musl",
149+
all(target_os = "nacl", test),
150+
all(target_os = "netbsd", target_vendor = "rumprun"))))]
147151
#[link(name = "c")]
148152
#[link(name = "m")]
149153
extern {}

src/librustc_back/target/mod.rs

+1
Original file line numberDiff line numberDiff line change
@@ -411,6 +411,7 @@ impl Target {
411411
x86_64_unknown_bitrig,
412412
x86_64_unknown_openbsd,
413413
x86_64_unknown_netbsd,
414+
x86_64_rumprun_netbsd,
414415

415416
x86_64_apple_darwin,
416417
i686_apple_darwin,
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
// Copyright 2014-2015 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::netbsd_base::opts();
15+
base.pre_link_args.push("-m64".to_string());
16+
base.linker = "x86_64-rumprun-netbsd-gcc".to_string();
17+
base.ar = "x86_64-rumprun-netbsd-ar".to_string();
18+
19+
base.dynamic_linking = false;
20+
base.has_rpath = false;
21+
base.position_independent_executables = false;
22+
base.disable_redzone = true;
23+
base.no_default_libraries = false;
24+
25+
Target {
26+
llvm_target: "x86_64-rumprun-netbsd".to_string(),
27+
target_endian: "little".to_string(),
28+
target_pointer_width: "64".to_string(),
29+
arch: "x86_64".to_string(),
30+
target_os: "netbsd".to_string(),
31+
target_env: "".to_string(),
32+
target_vendor: "rumprun".to_string(),
33+
options: base,
34+
}
35+
}

src/libstd/lib.rs

+1
Original file line numberDiff line numberDiff line change
@@ -204,6 +204,7 @@
204204
#![feature(associated_consts)]
205205
#![feature(borrow_state)]
206206
#![feature(box_syntax)]
207+
#![feature(cfg_target_vendor)]
207208
#![feature(char_from_unchecked)]
208209
#![feature(char_internals)]
209210
#![feature(clone_from_slice)]

src/libstd/sys/common/libunwind.rs

+9-1
Original file line numberDiff line numberDiff line change
@@ -108,10 +108,18 @@ extern {}
108108
#[link(name = "unwind", kind = "static")]
109109
extern {}
110110

111-
#[cfg(any(target_os = "android", target_os = "netbsd", target_os = "openbsd"))]
111+
#[cfg(any(target_os = "android", target_os = "openbsd"))]
112112
#[link(name = "gcc")]
113113
extern {}
114114

115+
#[cfg(all(target_os = "netbsd", not(target_vendor = "rumprun")))]
116+
#[link(name = "gcc")]
117+
extern {}
118+
119+
#[cfg(all(target_os = "netbsd", target_vendor = "rumprun"))]
120+
#[link(name = "unwind")]
121+
extern {}
122+
115123
#[cfg(target_os = "dragonfly")]
116124
#[link(name = "gcc_pic")]
117125
extern {}

src/libstd/sys/unix/stack_overflow.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ impl Drop for Handler {
3434
#[cfg(any(target_os = "linux",
3535
target_os = "macos",
3636
target_os = "bitrig",
37-
target_os = "netbsd",
37+
all(target_os = "netbsd", not(target_vendor = "rumprun")),
3838
target_os = "openbsd"))]
3939
mod imp {
4040
use super::Handler;
@@ -143,7 +143,7 @@ mod imp {
143143
#[cfg(not(any(target_os = "linux",
144144
target_os = "macos",
145145
target_os = "bitrig",
146-
target_os = "netbsd",
146+
all(target_os = "netbsd", not(target_vendor = "rumprun")),
147147
target_os = "openbsd")))]
148148
mod imp {
149149
use ptr;

src/libstd/sys/unix/thread.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -174,7 +174,7 @@ impl Drop for Thread {
174174
#[cfg(all(not(target_os = "linux"),
175175
not(target_os = "macos"),
176176
not(target_os = "bitrig"),
177-
not(target_os = "netbsd"),
177+
not(all(target_os = "netbsd", not(target_vendor = "rumprun"))),
178178
not(target_os = "openbsd")))]
179179
pub mod guard {
180180
pub unsafe fn current() -> Option<usize> { None }
@@ -185,7 +185,7 @@ pub mod guard {
185185
#[cfg(any(target_os = "linux",
186186
target_os = "macos",
187187
target_os = "bitrig",
188-
target_os = "netbsd",
188+
all(target_os = "netbsd", not(target_vendor = "rumprun")),
189189
target_os = "openbsd"))]
190190
#[allow(unused_imports)]
191191
pub mod guard {

0 commit comments

Comments
 (0)