Skip to content

Commit f21e302

Browse files
committed
add cosmopolitan libc support
1 parent 55d4364 commit f21e302

File tree

36 files changed

+1117
-144
lines changed

36 files changed

+1117
-144
lines changed
Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
use crate::spec::{
2+
Cc, FramePointer, LinkerFlavor, Lld, RelocModel, StackProbeType, TargetOptions, cvs,
3+
};
4+
5+
pub(crate) fn opts() -> TargetOptions {
6+
TargetOptions {
7+
os: "cosmo".into(),
8+
families: cvs!["unix"],
9+
plt_by_default: false,
10+
requires_uwtable: false,
11+
dynamic_linking: false,
12+
executables: true,
13+
exe_suffix: ".com.dbg".into(),
14+
emit_debug_gdb_scripts: false,
15+
crt_static_default: true,
16+
crt_static_respected: true,
17+
allows_weak_linkage: true,
18+
has_rpath: false,
19+
has_thread_local: false,
20+
trap_unreachable: true,
21+
position_independent_executables: false,
22+
static_position_independent_executables: false,
23+
relocation_model: RelocModel::Static,
24+
disable_redzone: true,
25+
frame_pointer: FramePointer::Always,
26+
requires_lto: false,
27+
eh_frame_header: false,
28+
no_default_libraries: true,
29+
max_atomic_width: Some(64),
30+
linker_flavor: LinkerFlavor::Gnu(Cc::Yes, Lld::No),
31+
stack_probes: StackProbeType::None,
32+
..Default::default()
33+
}
34+
}

compiler/rustc_target/src/spec/base/mod.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ pub(crate) mod android;
33
pub mod apple;
44
pub(crate) mod avr;
55
pub(crate) mod bpf;
6+
pub(crate) mod cosmo;
67
pub(crate) mod cygwin;
78
pub(crate) mod dragonfly;
89
pub(crate) mod freebsd;

compiler/rustc_target/src/spec/mod.rs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2092,6 +2092,9 @@ supported_targets! {
20922092
("x86_64-lynx-lynxos178", x86_64_lynx_lynxos178),
20932093

20942094
("x86_64-pc-cygwin", x86_64_pc_cygwin),
2095+
2096+
("x86_64-unknown-cosmo", x86_64_unknown_cosmo),
2097+
("aarch64-unknown-cosmo", aarch64_unknown_cosmo),
20952098
}
20962099

20972100
/// Cow-Vec-Str: Cow<'static, [Cow<'static, str>]>
Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
use crate::spec::{Cc, LinkerFlavor, Lld, Target, TargetMetadata, base};
2+
3+
pub(crate) fn target() -> Target {
4+
let mut base = base::cosmo::opts();
5+
6+
base.linker = Some("aarch64-unknown-cosmo-cc".into());
7+
base.features = "+reserve-x28".into();
8+
9+
base.add_pre_link_args(LinkerFlavor::Gnu(Cc::Yes, Lld::No), &["-static"]);
10+
11+
Target {
12+
llvm_target: "aarch64-unknown-cosmo".into(),
13+
metadata: TargetMetadata {
14+
description: Some("64-bit Cosmopolitan Libc".into()),
15+
tier: Some(3),
16+
host_tools: Some(true),
17+
std: Some(true),
18+
},
19+
pointer_width: 64,
20+
data_layout:
21+
"e-m:e-p270:32:32-p271:32:32-p272:64:64-i8:8:32-i16:16:32-i64:64-i128:128-n32:64-S128-Fn32".into(),
22+
arch: "aarch64".into(),
23+
options: base,
24+
}
25+
}
Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
use crate::spec::{Cc, LinkerFlavor, Lld, Target, TargetMetadata, base};
2+
3+
pub(crate) fn target() -> Target {
4+
let mut base = base::cosmo::opts();
5+
6+
base.cpu = "x86-64".into();
7+
base.linker = Some("x86_64-unknown-cosmo-cc".into());
8+
9+
base.add_pre_link_args(
10+
LinkerFlavor::Gnu(Cc::Yes, Lld::No),
11+
&["-m64", "-static", "-pg", "-mnop-mcount"],
12+
);
13+
14+
Target {
15+
llvm_target: "x86_64-unknown-cosmo".into(),
16+
metadata: TargetMetadata {
17+
description: Some("64-bit Cosmopolitan Libc".into()),
18+
tier: Some(3),
19+
host_tools: Some(true),
20+
std: Some(true),
21+
},
22+
pointer_width: 64,
23+
data_layout:
24+
"e-m:e-p270:32:32-p271:32:32-p272:64:64-i64:64-i128:128-f80:128-n8:16:32:64-S128".into(),
25+
arch: "x86_64".into(),
26+
options: base,
27+
}
28+
}
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+

library/Cargo.lock

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -142,8 +142,6 @@ dependencies = [
142142
[[package]]
143143
name = "libc"
144144
version = "0.2.172"
145-
source = "registry+https://github.com/rust-lang/crates.io-index"
146-
checksum = "d750af042f7ef4f724306de029d18836c26c1765a54a6a3f094cbd23a7267ffa"
147145
dependencies = [
148146
"rustc-std-workspace-core",
149147
]

library/Cargo.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -51,3 +51,4 @@ rustc-std-workspace-core = { path = 'rustc-std-workspace-core' }
5151
rustc-std-workspace-alloc = { path = 'rustc-std-workspace-alloc' }
5252
rustc-std-workspace-std = { path = 'rustc-std-workspace-std' }
5353
compiler_builtins = { path = "compiler-builtins/compiler-builtins" }
54+
libc = { path = 'TODO change to fork' }

library/core/src/ffi/primitives.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -109,6 +109,7 @@ mod c_char_definition {
109109
not(windows),
110110
not(target_vendor = "apple"),
111111
not(target_os = "vita"),
112+
not(target_os = "cosmo"),
112113
any(
113114
target_arch = "aarch64",
114115
target_arch = "arm",

library/std/Cargo.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -169,4 +169,5 @@ check-cfg = [
169169
'cfg(target_has_reliable_f16_math)',
170170
'cfg(target_has_reliable_f128)',
171171
'cfg(target_has_reliable_f128_math)',
172+
# 'cfg(target_os = "cosmo")',
172173
]

library/std/build.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,7 @@ fn main() {
5252
|| target_os == "rtems"
5353
|| target_os == "nuttx"
5454
|| target_os == "cygwin"
55+
|| target_os == "cosmo"
5556

5657
// See src/bootstrap/src/core/build_steps/synthetic_targets.rs
5758
|| env::var("RUSTC_BOOTSTRAP_SYNTHETIC_TARGET").is_ok()

library/std/src/fs/tests.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -491,7 +491,7 @@ fn file_test_io_read_write_at() {
491491
}
492492

493493
#[test]
494-
#[cfg(unix)]
494+
#[cfg(all(unix, not(target_os = "cosmo")))]
495495
fn set_get_unix_permissions() {
496496
use crate::os::unix::fs::PermissionsExt;
497497

library/std/src/io/copy/tests.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -126,7 +126,7 @@ mod io_benches {
126126
use crate::io::prelude::*;
127127

128128
#[bench]
129-
#[cfg_attr(target_os = "emscripten", ignore)] // no /dev
129+
#[cfg_attr(any(target_os = "emscripten", target_os = "cosmo"), ignore)] // no /dev
130130
fn bench_copy_buf_reader(b: &mut Bencher) {
131131
let mut file_in = File::open("/dev/zero").expect("opening /dev/zero failed");
132132
// use dyn to avoid specializations unrelated to readbuf

0 commit comments

Comments
 (0)