diff --git a/Cargo.lock b/Cargo.lock index 73d276d177648..0b7eac57a6337 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -102,7 +102,7 @@ version = "0.2.11" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "9a7d5b8723950951411ee34d271d99dddcc2035a16ab25310ea2c8cfd4369652" dependencies = [ - "libc", + "libc 0.2.66", "termion", "winapi 0.3.8", ] @@ -128,7 +128,7 @@ dependencies = [ "backtrace-sys", "cfg-if", "compiler_builtins", - "libc", + "libc 0.2.66", "rustc-demangle", "rustc-std-workspace-core", ] @@ -141,7 +141,7 @@ checksum = "7de8aba10a69c8e8d7622c5710229485ec32e9d55fdad160ea559c086fdcd118" dependencies = [ "cc", "compiler_builtins", - "libc", + "libc 0.2.66", "rustc-std-workspace-core", ] @@ -211,7 +211,7 @@ dependencies = [ "getopts", "ignore", "lazy_static 1.4.0", - "libc", + "libc 0.2.66", "num_cpus", "pretty_assertions", "serde", @@ -323,7 +323,7 @@ dependencies = [ "jobserver", "lazy_static 1.4.0", "lazycell", - "libc", + "libc 0.2.66", "libgit2-sys", "log", "memchr", @@ -561,14 +561,14 @@ version = "0.2.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "1fed34f46747aa73dfaa578069fd8279d2818ade2b55f38f22a9401c7f4083e2" dependencies = [ - "libc", + "libc 0.2.66", ] [[package]] name = "compiler_builtins" -version = "0.1.25" +version = "0.1.27" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "438ac08ddc5efe81452f984a9e33ba425b00b31d1f48e6acd9e2210aa28cc52e" +checksum = "38f18416546abfbf8d801c555a0e99524453e7214f9cc9107ad49de3d5948ccc" dependencies = [ "cc", "rustc-std-workspace-core", @@ -582,7 +582,7 @@ dependencies = [ "env_logger 0.7.1", "getopts", "lazy_static 1.4.0", - "libc", + "libc 0.2.66", "log", "miow 0.3.3", "regex", @@ -602,7 +602,7 @@ dependencies = [ "diff", "filetime", "getopts", - "libc", + "libc 0.2.66", "log", "miow 0.3.3", "regex", @@ -663,7 +663,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "4e2640d6d0bf22e82bed1b73c6aef8d5dd31e5abe6666c57e6d45e2649f4f887" dependencies = [ "core-foundation-sys 0.6.2", - "libc", + "libc 0.2.66", ] [[package]] @@ -673,7 +673,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "57d24c7a13c43e870e37c1556b74555437870a04514f7685f5b354e090567171" dependencies = [ "core-foundation-sys 0.7.0", - "libc", + "libc 0.2.66", ] [[package]] @@ -802,7 +802,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "06aa71e9208a54def20792d877bc663d6aae0732b9852e612c4a933177c31283" dependencies = [ "curl-sys", - "libc", + "libc 0.2.66", "openssl-probe", "openssl-sys", "schannel", @@ -817,7 +817,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "0c38ca47d60b86d0cc9d42caa90a0885669c2abc9791f871c81f58cdf39e979b" dependencies = [ "cc", - "libc", + "libc 0.2.66", "libnghttp2-sys", "libz-sys", "openssl-sys", @@ -936,7 +936,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "937756392ec77d1f2dd9dc3ac9d69867d109a2121479d72c364e42f4cab21e2d" dependencies = [ "cfg-if", - "libc", + "libc 0.2.66", "redox_users", "winapi 0.3.8", ] @@ -948,7 +948,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "f283302e035e61c23f2b86b3093e8c6273a4c3125742d6087e96ade001ca5e63" dependencies = [ "compiler_builtins", - "libc", + "libc 0.2.66", "rustc-std-workspace-core", ] @@ -1089,7 +1089,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "1ff6d4dab0aa0c8e6346d46052e93b13a16cf847b54ed357087c35011048cc7d" dependencies = [ "cfg-if", - "libc", + "libc 0.2.66", "redox_syscall", "winapi 0.3.8", ] @@ -1102,7 +1102,7 @@ checksum = "ad3c5233c9a940c8719031b423d7e6c16af66e031cb0420b0896f5245bf181d3" dependencies = [ "cfg-if", "crc32fast", - "libc", + "libc 0.2.66", "libz-sys", "miniz_oxide", ] @@ -1152,7 +1152,7 @@ version = "0.4.3" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "9564fc758e15025b46aa6643b1b77d047d1a56a1aea6e01002ac0c7026876213" dependencies = [ - "libc", + "libc 0.2.66", "winapi 0.3.8", ] @@ -1256,7 +1256,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "7abc8dd8451921606d809ba32e95b6111925cd2906060d2dcc29c070220503eb" dependencies = [ "cfg-if", - "libc", + "libc 0.2.66", "wasi", ] @@ -1267,7 +1267,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "b7da16ceafe24cedd9ba02c4463a2b506b6493baf4317c79c5acb553134a3c15" dependencies = [ "bitflags", - "libc", + "libc 0.2.66", "libgit2-sys", "log", "openssl-probe", @@ -1382,7 +1382,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "725cf19794cf90aa94e65050cb4191ff5d8fa87a498383774c47b332e3af952e" dependencies = [ "compiler_builtins", - "libc", + "libc 0.2.66", "rustc-std-workspace-core", ] @@ -1604,7 +1604,7 @@ version = "0.1.4" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "b2b3ea6ff95e175473f8ffe6a7eb7c00d054240321b84c57051175fe3c1e075e" dependencies = [ - "libc", + "libc 0.2.66", ] [[package]] @@ -1654,7 +1654,7 @@ checksum = "7bef0d4ce37578dfd80b466e3d8324bd9de788e249f1accebb0c472ea4b52bdc" dependencies = [ "cc", "fs_extra", - "libc", + "libc 0.2.66", ] [[package]] @@ -1663,7 +1663,7 @@ version = "0.1.21" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "5c71313ebb9439f74b00d9d2dcec36440beaf57a6aa0623068441dd7cd81a7f2" dependencies = [ - "libc", + "libc 0.2.66", ] [[package]] @@ -1804,6 +1804,14 @@ dependencies = [ "rustc-std-workspace-core", ] +[[package]] +name = "libc" +version = "0.2.68" +source = "git+https://github.com/leo60228/libc.git?branch=bindgen-newlib#89d63e017296edc1a97f6e7cf8ff3726599b467b" +dependencies = [ + "rustc-std-workspace-core", +] + [[package]] name = "libgit2-sys" version = "0.12.0+0.99.0" @@ -1811,7 +1819,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "05dff41ac39e7b653f5f1550886cf00ba52f8e7f57210b633cdeedb3de5b236c" dependencies = [ "cc", - "libc", + "libc 0.2.66", "libssh2-sys", "libz-sys", "openssl-sys", @@ -1825,7 +1833,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "02254d44f4435dd79e695f2c2b83cd06a47919adea30216ceaf0c57ca0a72463" dependencies = [ "cc", - "libc", + "libc 0.2.66", ] [[package]] @@ -1835,7 +1843,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "36aa6e813339d3a063292b77091dfbbb6152ff9006a459895fa5bebed7d34f10" dependencies = [ "cc", - "libc", + "libc 0.2.66", "libz-sys", "openssl-sys", "pkg-config", @@ -1849,7 +1857,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "2eb5e43362e38e2bca2fd5f5134c4d4564a23a5c28e9b95411652021a8675ebe" dependencies = [ "cc", - "libc", + "libc 0.2.66", "pkg-config", "vcpkg", ] @@ -1922,7 +1930,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "16b5c59c57cc4d39e7999f50431aa312ea78af7c93b23fbb0c3567bd672e7f35" dependencies = [ "cc", - "libc", + "libc 0.2.66", "pkg-config", ] @@ -2058,7 +2066,7 @@ version = "0.7.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "6585fd95e7bb50d6cc31e20d4cf9afb4e2ba16c5846fc76793f11218da9c475b" dependencies = [ - "libc", + "libc 0.2.66", "winapi 0.3.8", ] @@ -2119,7 +2127,7 @@ dependencies = [ "iovec", "kernel32-sys", "lazycell", - "libc", + "libc 0.2.66", "log", "miow 0.2.1", "net2", @@ -2146,7 +2154,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "966257a94e196b11bb43aca423754d87429960a768de9414f3691d6957abf125" dependencies = [ "iovec", - "libc", + "libc 0.2.66", "mio", ] @@ -2202,7 +2210,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "4b2df1a4c22fd44a62147fd8f13dd0f95c9d8ca7b2610299b2a2f9cf8964274e" dependencies = [ "lazy_static 1.4.0", - "libc", + "libc 0.2.66", "log", "openssl", "openssl-probe", @@ -2220,7 +2228,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "42550d9fb7b6684a6d404d9fa7250c2eb2646df731d1c06afc06dcee9e1bcf88" dependencies = [ "cfg-if", - "libc", + "libc 0.2.66", "winapi 0.3.8", ] @@ -2257,7 +2265,7 @@ version = "1.10.1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "bcef43580c035376c0705c42792c294b66974abbfd2789b511784023f71f3273" dependencies = [ - "libc", + "libc 0.2.66", ] [[package]] @@ -2297,7 +2305,7 @@ dependencies = [ "cfg-if", "foreign-types", "lazy_static 1.4.0", - "libc", + "libc 0.2.66", "openssl-sys", ] @@ -2324,7 +2332,7 @@ checksum = "1024c0a59774200a555087a6da3f253a9095a5f344e353b212ac4c8b8e450986" dependencies = [ "autocfg 1.0.0", "cc", - "libc", + "libc 0.2.66", "openssl-src", "pkg-config", "vcpkg", @@ -2360,7 +2368,7 @@ version = "0.0.0" dependencies = [ "compiler_builtins", "core", - "libc", + "libc 0.2.66", ] [[package]] @@ -2371,7 +2379,7 @@ dependencies = [ "cfg-if", "compiler_builtins", "core", - "libc", + "libc 0.2.66", "unwind", ] @@ -2422,7 +2430,7 @@ checksum = "b876b1b9e7ac6e1a74a6da34d25c42e17e8862aa409cbbbdcfc8d86c6f3bc62b" dependencies = [ "cfg-if", "cloudabi", - "libc", + "libc 0.2.66", "redox_syscall", "rustc_version", "smallvec 0.6.10", @@ -2437,7 +2445,7 @@ checksum = "7582838484df45743c8434fbff785e8edf260c28748353d44bc0da32e0ceabf1" dependencies = [ "cfg-if", "cloudabi", - "libc", + "libc 0.2.66", "redox_syscall", "smallvec 1.0.0", "winapi 0.3.8", @@ -2744,7 +2752,7 @@ checksum = "ae9d223d52ae411a33cf7e54ec6034ec165df296ccd23533d671a28252b6f66a" dependencies = [ "cloudabi", "fuchsia-zircon", - "libc", + "libc 0.2.66", "rand_chacha 0.1.0", "rand_core 0.3.0", "rand_hc 0.1.0", @@ -2762,7 +2770,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "6a6b1679d49b24bbfe0c803429aa1874472f50d9b363131f0e89fc356b544d03" dependencies = [ "getrandom", - "libc", + "libc 0.2.66", "rand_chacha 0.2.1", "rand_core 0.5.1", "rand_hc 0.2.0", @@ -2844,7 +2852,7 @@ checksum = "7b75f676a1e053fc562eafbb47838d67c84801e38fc1ba459e8f180deabd5071" dependencies = [ "cloudabi", "fuchsia-cprng", - "libc", + "libc 0.2.66", "rand_core 0.4.0", "rdrand", "winapi 0.3.8", @@ -3629,7 +3637,7 @@ version = "0.0.0" dependencies = [ "bitflags", "flate2", - "libc", + "libc 0.2.66", "log", "measureme", "rustc-demangle", @@ -3659,7 +3667,7 @@ dependencies = [ "bitflags", "cc", "jobserver", - "libc", + "libc 0.2.66", "log", "memmap", "num_cpus", @@ -3694,7 +3702,7 @@ dependencies = [ "indexmap", "jobserver", "lazy_static 1.4.0", - "libc", + "libc 0.2.66", "log", "measureme", "parking_lot 0.10.0", @@ -3714,7 +3722,7 @@ version = "0.0.0" dependencies = [ "env_logger 0.7.1", "lazy_static 1.4.0", - "libc", + "libc 0.2.66", "log", "rustc_ast", "rustc_ast_pretty", @@ -3869,7 +3877,7 @@ dependencies = [ name = "rustc_interface" version = "0.0.0" dependencies = [ - "libc", + "libc 0.2.66", "log", "once_cell", "rustc-rayon", @@ -3945,7 +3953,7 @@ version = "0.0.0" dependencies = [ "build_helper", "cc", - "libc", + "libc 0.2.66", ] [[package]] @@ -3963,7 +3971,7 @@ name = "rustc_metadata" version = "0.0.0" dependencies = [ "flate2", - "libc", + "libc 0.2.66", "log", "memmap", "rustc_ast", @@ -4502,7 +4510,7 @@ checksum = "eee63d0f4a9ec776eeb30e220f0bc1e092c3ad744b2a379e3993070364d3adc2" dependencies = [ "core-foundation 0.6.3", "core-foundation-sys 0.6.2", - "libc", + "libc 0.2.66", "security-framework-sys", ] @@ -4633,7 +4641,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "1f272d1b7586bec132ed427f532dd418d8beca1ca7f2caf7df35569b1415a4b4" dependencies = [ "arc-swap", - "libc", + "libc 0.2.66", ] [[package]] @@ -4677,7 +4685,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "e8b74de517221a2cb01a53349cf54182acdc31a074727d3079068448c0676d85" dependencies = [ "cfg-if", - "libc", + "libc 0.2.66", "redox_syscall", "winapi 0.3.8", ] @@ -4701,7 +4709,7 @@ dependencies = [ "fortanix-sgx-abi", "hashbrown 0.6.2", "hermit-abi", - "libc", + "libc 0.2.68", "panic_abort", "panic_unwind", "profiler_builtins", @@ -4862,7 +4870,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "b3196bfbffbba3e57481b6ea32249fbaf590396a52505a2615adbb79d9d826d3" dependencies = [ "filetime", - "libc", + "libc 0.2.66", "redox_syscall", "xattr", ] @@ -4874,7 +4882,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "7a6e24d9338a0a5be79593e2fa15a648add6138caa803e2d5bc782c371732ca9" dependencies = [ "cfg-if", - "libc", + "libc 0.2.66", "rand 0.7.3", "redox_syscall", "remove_dir_all", @@ -4926,7 +4934,7 @@ version = "1.5.1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "689a3bdfaab439fd92bc87df5c4c78417d3cbe537487274e9b0b2dce76e92096" dependencies = [ - "libc", + "libc 0.2.66", "redox_syscall", "redox_termios", ] @@ -4937,7 +4945,7 @@ version = "0.1.1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "1706be6b564323ce7092f5f7e6b118a14c8ef7ed0e69c8c5329c914a9f101295" dependencies = [ - "libc", + "libc 0.2.66", "winapi 0.3.8", ] @@ -4947,7 +4955,7 @@ version = "0.0.0" dependencies = [ "core", "getopts", - "libc", + "libc 0.2.66", "panic_abort", "panic_unwind", "proc_macro", @@ -4962,7 +4970,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "ee72ec31009a42b53de9a6b7d8f462b493ab3b1e4767bda1fcdbb52127f13b6c" dependencies = [ "getopts", - "libc", + "libc 0.2.66", "term 0.6.0", ] @@ -5029,7 +5037,7 @@ version = "0.1.42" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "db8dcfca086c1143c9270ac42a2bbd8a7ee477b78ac8e45b19abfb0cbede4b6f" dependencies = [ - "libc", + "libc 0.2.66", "redox_syscall", "winapi 0.3.8", ] @@ -5144,7 +5152,7 @@ dependencies = [ "crossbeam-queue", "futures", "lazy_static 1.4.0", - "libc", + "libc 0.2.66", "log", "mio", "mio-named-pipes", @@ -5189,7 +5197,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "dd6dc5276ea05ce379a16de90083ec80836440d5ef8a6a39545a3207373b8296" dependencies = [ "futures", - "libc", + "libc 0.2.66", "mio", "mio-uds", "signal-hook", @@ -5276,7 +5284,7 @@ dependencies = [ "bytes", "futures", "iovec", - "libc", + "libc 0.2.66", "log", "mio", "mio-uds", @@ -5463,7 +5471,7 @@ dependencies = [ "cfg-if", "compiler_builtins", "core", - "libc", + "libc 0.2.66", ] [[package]] @@ -5665,7 +5673,7 @@ version = "0.2.2" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "244c3741f4240ef46274860397c7c74e50eb23624996930e484c16679633a54c" dependencies = [ - "libc", + "libc 0.2.66", ] [[package]] diff --git a/src/.gitignore b/src/.gitignore new file mode 100644 index 0000000000000..0a9ce4f3e2c93 --- /dev/null +++ b/src/.gitignore @@ -0,0 +1 @@ +libc diff --git a/src/bootstrap/bootstrap.py b/src/bootstrap/bootstrap.py index d5efed61b541e..a72cfc5797e73 100644 --- a/src/bootstrap/bootstrap.py +++ b/src/bootstrap/bootstrap.py @@ -447,8 +447,6 @@ def fix_executable(fname): if not os.path.exists("/etc/NIXOS"): return - if os.path.exists("/lib"): - return # At this point we're pretty sure the user is running NixOS nix_os_msg = "info: you seem to be running NixOS. Attempting to patch" diff --git a/src/liballoc/Cargo.toml b/src/liballoc/Cargo.toml index d1119f7b7c0a7..a32d548603305 100644 --- a/src/liballoc/Cargo.toml +++ b/src/liballoc/Cargo.toml @@ -12,7 +12,7 @@ path = "lib.rs" [dependencies] core = { path = "../libcore" } -compiler_builtins = { version = "0.1.10", features = ['rustc-dep-of-std'] } +compiler_builtins = { version = "=0.1.27", features = ['rustc-dep-of-std'] } [dev-dependencies] rand = "0.7" diff --git a/src/libpanic_abort/Cargo.toml b/src/libpanic_abort/Cargo.toml index 2bee0b716c750..7ed5916b18d83 100644 --- a/src/libpanic_abort/Cargo.toml +++ b/src/libpanic_abort/Cargo.toml @@ -13,4 +13,4 @@ doc = false [dependencies] core = { path = "../libcore" } libc = { version = "0.2", default-features = false } -compiler_builtins = "0.1.0" +compiler_builtins = "=0.1.27" diff --git a/src/libpanic_unwind/Cargo.toml b/src/libpanic_unwind/Cargo.toml index 47cd09f1b0510..113797bea2018 100644 --- a/src/libpanic_unwind/Cargo.toml +++ b/src/libpanic_unwind/Cargo.toml @@ -15,5 +15,5 @@ alloc = { path = "../liballoc" } core = { path = "../libcore" } libc = { version = "0.2", default-features = false } unwind = { path = "../libunwind" } -compiler_builtins = "0.1.0" +compiler_builtins = "=0.1.27" cfg-if = "0.1.8" diff --git a/src/libprofiler_builtins/Cargo.toml b/src/libprofiler_builtins/Cargo.toml index 0d36bd0b39d76..c871998ce29c5 100644 --- a/src/libprofiler_builtins/Cargo.toml +++ b/src/libprofiler_builtins/Cargo.toml @@ -14,7 +14,7 @@ doc = false [dependencies] core = { path = "../libcore" } -compiler_builtins = { version = "0.1.0", features = ['rustc-dep-of-std'] } +compiler_builtins = { version = "=0.1.27", features = ['rustc-dep-of-std'] } [build-dependencies] cc = "1.0.1" diff --git a/src/librustc_session/Cargo.toml b/src/librustc_session/Cargo.toml index 814073bb4f7be..9d8cfee660fbb 100644 --- a/src/librustc_session/Cargo.toml +++ b/src/librustc_session/Cargo.toml @@ -9,7 +9,7 @@ name = "rustc_session" path = "lib.rs" [dependencies] -getopts = "0.2" +getopts = "*" log = "0.4" rustc_errors = { path = "../librustc_errors" } rustc_feature = { path = "../librustc_feature" } diff --git a/src/librustc_target/spec/aarch64_unknown_horizon_libnx.rs b/src/librustc_target/spec/aarch64_unknown_horizon_libnx.rs new file mode 100644 index 0000000000000..710df77f7fa38 --- /dev/null +++ b/src/librustc_target/spec/aarch64_unknown_horizon_libnx.rs @@ -0,0 +1,35 @@ +use super::{LinkerFlavor, PanicStrategy, Target, TargetOptions}; + +pub fn target() -> Result { + let opts = TargetOptions { + linker: Some("aarch64-none-elf-gcc".to_owned()), + features: "+a53,+strict-align,+crc".to_string(), + executables: true, + relocation_model: "pic".to_string(), + disable_redzone: true, + linker_is_gnu: true, + max_atomic_width: Some(128), + panic_strategy: PanicStrategy::Unwind, + abi_blacklist: super::arm_base::abi_blacklist(), + target_family: Some("unix".to_string()), + position_independent_executables: true, + has_elf_tls: false, + trap_unreachable: true, + emit_debug_gdb_scripts: true, + requires_uwtable: true, + ..Default::default() + }; + Ok(Target { + llvm_target: "aarch64-unknown-none".to_string(), + target_endian: "little".to_string(), + target_pointer_width: "64".to_string(), + target_c_int_width: "32".to_string(), + target_os: "horizon".to_string(), + target_env: "newlib".to_string(), + target_vendor: "libnx".to_string(), + data_layout: "e-m:e-i8:8:32-i16:16:32-i64:64-i128:128-n32:64-S128".to_string(), + arch: "aarch64".to_string(), + linker_flavor: LinkerFlavor::Gcc, + options: opts, + }) +} diff --git a/src/librustc_target/spec/mod.rs b/src/librustc_target/spec/mod.rs index 1bc2bf12fad9e..176e8b7e2b611 100644 --- a/src/librustc_target/spec/mod.rs +++ b/src/librustc_target/spec/mod.rs @@ -512,6 +512,8 @@ supported_targets! { ("powerpc-wrs-vxworks", powerpc_wrs_vxworks), ("powerpc-wrs-vxworks-spe", powerpc_wrs_vxworks_spe), ("powerpc64-wrs-vxworks", powerpc64_wrs_vxworks), + + ("aarch64-unknown-horizon-libnx", aarch64_unknown_horizon_libnx), } /// Everything `rustc` knows about how to compile for a specific target. diff --git a/src/libstd/Cargo.toml b/src/libstd/Cargo.toml index ceb39c01c6723..9f0a486327c5b 100644 --- a/src/libstd/Cargo.toml +++ b/src/libstd/Cargo.toml @@ -19,15 +19,17 @@ cfg-if = { version = "0.1.8", features = ['rustc-dep-of-std'] } panic_unwind = { path = "../libpanic_unwind", optional = true } panic_abort = { path = "../libpanic_abort" } core = { path = "../libcore" } -libc = { version = "0.2.51", default-features = false, features = ['rustc-dep-of-std'] } -compiler_builtins = { version = "0.1.16" } +#libc = { version = "0.2.51", default-features = false, features = ['rustc-dep-of-std'] } +libc = { git = "https://github.com/leo60228/libc.git", branch = "bindgen-newlib", default-features = false, features = ['rustc-dep-of-std'] } +compiler_builtins = { version = "=0.1.27" } profiler_builtins = { path = "../libprofiler_builtins", optional = true } unwind = { path = "../libunwind" } hashbrown = { version = "0.6.2", default-features = false, features = ['rustc-dep-of-std'] } [dependencies.backtrace_rs] package = "backtrace" -version = "0.3.46" +git = "https://github.com/Tarnadas/backtrace-rs.git" +branch = "horizon" default-features = false # without the libstd `backtrace` feature, stub out everything features = [ "rustc-dep-of-std" ] # enable build support for integrating into libstd diff --git a/src/libstd/os/libnx/fs.rs b/src/libstd/os/libnx/fs.rs new file mode 100644 index 0000000000000..bd2b6bb6050c9 --- /dev/null +++ b/src/libstd/os/libnx/fs.rs @@ -0,0 +1,312 @@ +#![stable(feature = "metadata_ext", since = "1.1.0")] + +use crate::fs::Metadata; +use crate::sys_common::AsInner; + +#[allow(deprecated)] +use crate::os::libnx::raw; + +/// OS-specific extensions to [`fs::Metadata`]. +/// +/// [`fs::Metadata`]: ../../../../std/fs/struct.Metadata.html +#[stable(feature = "metadata_ext", since = "1.1.0")] +pub trait MetadataExt { + /// Gain a reference to the underlying `stat` structure which contains + /// the raw information returned by the OS. + /// + /// The contents of the returned [`stat`] are **not** consistent across + /// Unix platforms. The `os::unix::fs::MetadataExt` trait contains the + /// cross-Unix abstractions contained within the raw stat. + /// + /// [`stat`]: ../../../../std/os/linux/raw/struct.stat.html + /// + /// # Examples + /// + /// ```no_run + /// use std::fs; + /// use std::io; + /// use std::os::linux::fs::MetadataExt; + /// + /// fn main() -> io::Result<()> { + /// let meta = fs::metadata("some_file")?; + /// let stat = meta.as_raw_stat(); + /// Ok(()) + /// } + /// ``` + #[stable(feature = "metadata_ext", since = "1.1.0")] + #[rustc_deprecated(since = "1.8.0", reason = "other methods of this trait are now preferred")] + #[allow(deprecated)] + fn as_raw_stat(&self) -> &raw::stat; + + /// Returns the device ID on which this file resides. + /// + /// # Examples + /// + /// ```no_run + /// use std::fs; + /// use std::io; + /// use std::os::linux::fs::MetadataExt; + /// + /// fn main() -> io::Result<()> { + /// let meta = fs::metadata("some_file")?; + /// println!("{}", meta.st_dev()); + /// Ok(()) + /// } + /// ``` + #[stable(feature = "metadata_ext2", since = "1.8.0")] + fn st_dev(&self) -> u64; + /// Returns the inode number. + /// + /// # Examples + /// + /// ```no_run + /// use std::fs; + /// use std::io; + /// use std::os::linux::fs::MetadataExt; + /// + /// fn main() -> io::Result<()> { + /// let meta = fs::metadata("some_file")?; + /// println!("{}", meta.st_ino()); + /// Ok(()) + /// } + /// ``` + #[stable(feature = "metadata_ext2", since = "1.8.0")] + fn st_ino(&self) -> u64; + /// Returns the file type and mode. + /// + /// # Examples + /// + /// ```no_run + /// use std::fs; + /// use std::io; + /// use std::os::linux::fs::MetadataExt; + /// + /// fn main() -> io::Result<()> { + /// let meta = fs::metadata("some_file")?; + /// println!("{}", meta.st_mode()); + /// Ok(()) + /// } + /// ``` + #[stable(feature = "metadata_ext2", since = "1.8.0")] + fn st_mode(&self) -> u32; + /// Returns the number of hard links to file. + /// + /// # Examples + /// + /// ```no_run + /// use std::fs; + /// use std::io; + /// use std::os::linux::fs::MetadataExt; + /// + /// fn main() -> io::Result<()> { + /// let meta = fs::metadata("some_file")?; + /// println!("{}", meta.st_nlink()); + /// Ok(()) + /// } + /// ``` + #[stable(feature = "metadata_ext2", since = "1.8.0")] + fn st_nlink(&self) -> u64; + /// Returns the user ID of the file owner. + /// + /// # Examples + /// + /// ```no_run + /// use std::fs; + /// use std::io; + /// use std::os::linux::fs::MetadataExt; + /// + /// fn main() -> io::Result<()> { + /// let meta = fs::metadata("some_file")?; + /// println!("{}", meta.st_uid()); + /// Ok(()) + /// } + /// ``` + #[stable(feature = "metadata_ext2", since = "1.8.0")] + fn st_uid(&self) -> u32; + /// Returns the group ID of the file owner. + /// + /// # Examples + /// + /// ```no_run + /// use std::fs; + /// use std::io; + /// use std::os::linux::fs::MetadataExt; + /// + /// fn main() -> io::Result<()> { + /// let meta = fs::metadata("some_file")?; + /// println!("{}", meta.st_gid()); + /// Ok(()) + /// } + /// ``` + #[stable(feature = "metadata_ext2", since = "1.8.0")] + fn st_gid(&self) -> u32; + /// Returns the device ID that this file represents. Only relevant for special file. + /// + /// # Examples + /// + /// ```no_run + /// use std::fs; + /// use std::io; + /// use std::os::linux::fs::MetadataExt; + /// + /// fn main() -> io::Result<()> { + /// let meta = fs::metadata("some_file")?; + /// println!("{}", meta.st_rdev()); + /// Ok(()) + /// } + /// ``` + #[stable(feature = "metadata_ext2", since = "1.8.0")] + fn st_rdev(&self) -> u64; + /// Returns the size of the file (if it is a regular file or a symbolic link) in bytes. + /// + /// The size of a symbolic link is the length of the pathname it contains, + /// without a terminating null byte. + /// + /// # Examples + /// + /// ```no_run + /// use std::fs; + /// use std::io; + /// use std::os::linux::fs::MetadataExt; + /// + /// fn main() -> io::Result<()> { + /// let meta = fs::metadata("some_file")?; + /// println!("{}", meta.st_size()); + /// Ok(()) + /// } + /// ``` + #[stable(feature = "metadata_ext2", since = "1.8.0")] + fn st_size(&self) -> u64; + /// Returns the last access time of the file, in seconds since Unix Epoch. + /// + /// # Examples + /// + /// ```no_run + /// use std::fs; + /// use std::io; + /// use std::os::linux::fs::MetadataExt; + /// + /// fn main() -> io::Result<()> { + /// let meta = fs::metadata("some_file")?; + /// println!("{}", meta.st_atime()); + /// Ok(()) + /// } + /// ``` + #[stable(feature = "metadata_ext2", since = "1.8.0")] + fn st_atime(&self) -> i64; + /// Returns the last modification time of the file, in seconds since Unix Epoch. + /// + /// # Examples + /// + /// ```no_run + /// use std::fs; + /// use std::io; + /// use std::os::linux::fs::MetadataExt; + /// + /// fn main() -> io::Result<()> { + /// let meta = fs::metadata("some_file")?; + /// println!("{}", meta.st_mtime()); + /// Ok(()) + /// } + /// ``` + #[stable(feature = "metadata_ext2", since = "1.8.0")] + fn st_mtime(&self) -> i64; + /// Returns the last status change time of the file, in seconds since Unix Epoch. + /// + /// # Examples + /// + /// ```no_run + /// use std::fs; + /// use std::io; + /// use std::os::linux::fs::MetadataExt; + /// + /// fn main() -> io::Result<()> { + /// let meta = fs::metadata("some_file")?; + /// println!("{}", meta.st_ctime()); + /// Ok(()) + /// } + /// ``` + #[stable(feature = "metadata_ext2", since = "1.8.0")] + fn st_ctime(&self) -> i64; + /// Returns the "preferred" blocksize for efficient filesystem I/O. + /// + /// # Examples + /// + /// ```no_run + /// use std::fs; + /// use std::io; + /// use std::os::linux::fs::MetadataExt; + /// + /// fn main() -> io::Result<()> { + /// let meta = fs::metadata("some_file")?; + /// println!("{}", meta.st_blksize()); + /// Ok(()) + /// } + /// ``` + #[stable(feature = "metadata_ext2", since = "1.8.0")] + fn st_blksize(&self) -> u64; + /// Returns the number of blocks allocated to the file, 512-byte units. + /// + /// # Examples + /// + /// ```no_run + /// use std::fs; + /// use std::io; + /// use std::os::linux::fs::MetadataExt; + /// + /// fn main() -> io::Result<()> { + /// let meta = fs::metadata("some_file")?; + /// println!("{}", meta.st_blocks()); + /// Ok(()) + /// } + /// ``` + #[stable(feature = "metadata_ext2", since = "1.8.0")] + fn st_blocks(&self) -> u64; +} + +#[stable(feature = "metadata_ext", since = "1.1.0")] +impl MetadataExt for Metadata { + #[allow(deprecated)] + fn as_raw_stat(&self) -> &raw::stat { + unsafe { &*(self.as_inner().as_inner() as *const libc::stat as *const raw::stat) } + } + fn st_dev(&self) -> u64 { + self.as_inner().as_inner().st_dev as u64 + } + fn st_ino(&self) -> u64 { + self.as_inner().as_inner().st_ino as u64 + } + fn st_mode(&self) -> u32 { + self.as_inner().as_inner().st_mode as u32 + } + fn st_nlink(&self) -> u64 { + self.as_inner().as_inner().st_nlink as u64 + } + fn st_uid(&self) -> u32 { + self.as_inner().as_inner().st_uid as u32 + } + fn st_gid(&self) -> u32 { + self.as_inner().as_inner().st_gid as u32 + } + fn st_rdev(&self) -> u64 { + self.as_inner().as_inner().st_rdev as u64 + } + fn st_size(&self) -> u64 { + self.as_inner().as_inner().st_size as u64 + } + fn st_atime(&self) -> i64 { + self.as_inner().as_inner().st_atime as i64 + } + fn st_mtime(&self) -> i64 { + self.as_inner().as_inner().st_mtime as i64 + } + fn st_ctime(&self) -> i64 { + self.as_inner().as_inner().st_ctime as i64 + } + fn st_blksize(&self) -> u64 { + self.as_inner().as_inner().st_blksize as u64 + } + fn st_blocks(&self) -> u64 { + self.as_inner().as_inner().st_blocks as u64 + } +} diff --git a/src/libstd/os/libnx/mod.rs b/src/libstd/os/libnx/mod.rs new file mode 100644 index 0000000000000..1af6dd10ade6b --- /dev/null +++ b/src/libstd/os/libnx/mod.rs @@ -0,0 +1,6 @@ +//! libnx-specific definitions + +#![stable(feature = "raw_ext", since = "1.1.0")] + +pub mod fs; +pub mod raw; diff --git a/src/libstd/os/libnx/raw.rs b/src/libstd/os/libnx/raw.rs new file mode 100644 index 0000000000000..0caec97bb7b90 --- /dev/null +++ b/src/libstd/os/libnx/raw.rs @@ -0,0 +1,363 @@ +//! Linux-specific raw type definitions + +#![stable(feature = "raw_ext", since = "1.1.0")] +#![rustc_deprecated( + since = "1.8.0", + reason = "these type aliases are no longer supported by \ + the standard library, the `libc` crate on \ + crates.io should be used instead for the correct \ + definitions" +)] +#![allow(deprecated)] +#![allow(missing_debug_implementations)] + +use crate::os::raw::c_ulong; + +#[stable(feature = "raw_ext", since = "1.1.0")] +pub type dev_t = u64; +#[stable(feature = "raw_ext", since = "1.1.0")] +pub type mode_t = u32; + +#[stable(feature = "pthread_t", since = "1.8.0")] +pub type pthread_t = c_ulong; + +#[doc(inline)] +#[stable(feature = "raw_ext", since = "1.1.0")] +pub use self::arch::{blkcnt_t, blksize_t, ino_t, nlink_t, off_t, stat, time_t}; + +#[cfg(any( + target_arch = "x86", + target_arch = "le32", + target_arch = "powerpc", + target_arch = "arm", + target_arch = "asmjs", + target_arch = "wasm32" +))] +mod arch { + use crate::os::raw::{c_long, c_short, c_uint}; + + #[stable(feature = "raw_ext", since = "1.1.0")] + pub type blkcnt_t = u64; + #[stable(feature = "raw_ext", since = "1.1.0")] + pub type blksize_t = u64; + #[stable(feature = "raw_ext", since = "1.1.0")] + pub type ino_t = u64; + #[stable(feature = "raw_ext", since = "1.1.0")] + pub type nlink_t = u64; + #[stable(feature = "raw_ext", since = "1.1.0")] + pub type off_t = u64; + #[stable(feature = "raw_ext", since = "1.1.0")] + pub type time_t = i64; + + #[repr(C)] + #[derive(Clone)] + #[stable(feature = "raw_ext", since = "1.1.0")] + pub struct stat { + #[stable(feature = "raw_ext", since = "1.1.0")] + pub st_dev: u64, + #[stable(feature = "raw_ext", since = "1.1.0")] + pub __pad1: c_short, + #[stable(feature = "raw_ext", since = "1.1.0")] + pub __st_ino: u32, + #[stable(feature = "raw_ext", since = "1.1.0")] + pub st_mode: u32, + #[stable(feature = "raw_ext", since = "1.1.0")] + pub st_nlink: u32, + #[stable(feature = "raw_ext", since = "1.1.0")] + pub st_uid: u32, + #[stable(feature = "raw_ext", since = "1.1.0")] + pub st_gid: u32, + #[stable(feature = "raw_ext", since = "1.1.0")] + pub st_rdev: u64, + #[stable(feature = "raw_ext", since = "1.1.0")] + pub __pad2: c_uint, + #[stable(feature = "raw_ext", since = "1.1.0")] + pub st_size: i64, + #[stable(feature = "raw_ext", since = "1.1.0")] + pub st_blksize: i32, + #[stable(feature = "raw_ext", since = "1.1.0")] + pub st_blocks: i64, + #[stable(feature = "raw_ext", since = "1.1.0")] + pub st_atime: i32, + #[stable(feature = "raw_ext", since = "1.1.0")] + pub st_atime_nsec: c_long, + #[stable(feature = "raw_ext", since = "1.1.0")] + pub st_mtime: i32, + #[stable(feature = "raw_ext", since = "1.1.0")] + pub st_mtime_nsec: c_long, + #[stable(feature = "raw_ext", since = "1.1.0")] + pub st_ctime: i32, + #[stable(feature = "raw_ext", since = "1.1.0")] + pub st_ctime_nsec: c_long, + #[stable(feature = "raw_ext", since = "1.1.0")] + pub st_ino: u64, + } +} + +#[cfg(target_arch = "mips")] +mod arch { + use crate::os::raw::{c_long, c_ulong}; + + #[cfg(target_env = "musl")] + #[stable(feature = "raw_ext", since = "1.1.0")] + pub type blkcnt_t = i64; + #[cfg(not(target_env = "musl"))] + #[stable(feature = "raw_ext", since = "1.1.0")] + pub type blkcnt_t = u64; + #[stable(feature = "raw_ext", since = "1.1.0")] + pub type blksize_t = u64; + #[cfg(target_env = "musl")] + #[stable(feature = "raw_ext", since = "1.1.0")] + pub type ino_t = u64; + #[cfg(not(target_env = "musl"))] + #[stable(feature = "raw_ext", since = "1.1.0")] + pub type ino_t = u64; + #[stable(feature = "raw_ext", since = "1.1.0")] + pub type nlink_t = u64; + #[cfg(target_env = "musl")] + #[stable(feature = "raw_ext", since = "1.1.0")] + pub type off_t = u64; + #[cfg(not(target_env = "musl"))] + #[stable(feature = "raw_ext", since = "1.1.0")] + pub type off_t = u64; + #[stable(feature = "raw_ext", since = "1.1.0")] + pub type time_t = i64; + + #[repr(C)] + #[derive(Clone)] + #[stable(feature = "raw_ext", since = "1.1.0")] + pub struct stat { + #[stable(feature = "raw_ext", since = "1.1.0")] + pub st_dev: c_ulong, + #[stable(feature = "raw_ext", since = "1.1.0")] + pub st_pad1: [c_long; 3], + #[stable(feature = "raw_ext", since = "1.1.0")] + pub st_ino: u64, + #[stable(feature = "raw_ext", since = "1.1.0")] + pub st_mode: u32, + #[stable(feature = "raw_ext", since = "1.1.0")] + pub st_nlink: u32, + #[stable(feature = "raw_ext", since = "1.1.0")] + pub st_uid: u32, + #[stable(feature = "raw_ext", since = "1.1.0")] + pub st_gid: u32, + #[stable(feature = "raw_ext", since = "1.1.0")] + pub st_rdev: c_ulong, + #[stable(feature = "raw_ext", since = "1.1.0")] + pub st_pad2: [c_long; 2], + #[stable(feature = "raw_ext", since = "1.1.0")] + pub st_size: i64, + #[stable(feature = "raw_ext", since = "1.1.0")] + pub st_atime: i32, + #[stable(feature = "raw_ext", since = "1.1.0")] + pub st_atime_nsec: c_long, + #[stable(feature = "raw_ext", since = "1.1.0")] + pub st_mtime: i32, + #[stable(feature = "raw_ext", since = "1.1.0")] + pub st_mtime_nsec: c_long, + #[stable(feature = "raw_ext", since = "1.1.0")] + pub st_ctime: i32, + #[stable(feature = "raw_ext", since = "1.1.0")] + pub st_ctime_nsec: c_long, + #[stable(feature = "raw_ext", since = "1.1.0")] + pub st_blksize: i32, + #[stable(feature = "raw_ext", since = "1.1.0")] + pub st_blocks: i64, + #[stable(feature = "raw_ext", since = "1.1.0")] + pub st_pad5: [c_long; 14], + } +} + +#[cfg(target_arch = "hexagon")] +mod arch { + use crate::os::raw::{c_int, c_long, c_longlong, culonglong}; + + #[stable(feature = "raw_ext", since = "1.1.0")] + pub type blkcnt_t = c_longlong; + #[stable(feature = "raw_ext", since = "1.1.0")] + pub type blksize_t = c_long; + #[stable(feature = "raw_ext", since = "1.1.0")] + pub type ino_t = c_ulonglong; + #[stable(feature = "raw_ext", since = "1.1.0")] + pub type nlink_t = c_uint; + #[stable(feature = "raw_ext", since = "1.1.0")] + pub type off_t = c_longlong; + #[stable(feature = "raw_ext", since = "1.1.0")] + pub type time_t = c_long; + + #[repr(C)] + #[derive(Clone)] + #[stable(feature = "raw_ext", since = "1.1.0")] + pub struct stat { + #[stable(feature = "raw_ext", since = "1.1.0")] + pub st_dev: ::dev_t, + #[stable(feature = "raw_ext", since = "1.1.0")] + pub st_ino: ::c_ulonglong, + #[stable(feature = "raw_ext", since = "1.1.0")] + pub st_mode: ::c_uint, + #[stable(feature = "raw_ext", since = "1.1.0")] + pub st_nlink: ::c_uint, + #[stable(feature = "raw_ext", since = "1.1.0")] + pub st_uid: ::c_uint, + #[stable(feature = "raw_ext", since = "1.1.0")] + pub st_gid: ::c_uint, + #[stable(feature = "raw_ext", since = "1.1.0")] + pub st_rdev: ::c_ulonglong, + #[stable(feature = "raw_ext", since = "1.1.0")] + pub __pad1: ::c_ulong, + #[stable(feature = "raw_ext", since = "1.1.0")] + pub st_size: ::c_longlong, + #[stable(feature = "raw_ext", since = "1.1.0")] + pub st_blksize: ::blksize_t, + #[stable(feature = "raw_ext", since = "1.1.0")] + pub __pad2: ::c_int, + #[stable(feature = "raw_ext", since = "1.1.0")] + pub st_blocks: ::blkcnt_t, + #[stable(feature = "raw_ext", since = "1.1.0")] + pub st_atime: ::time_t, + #[stable(feature = "raw_ext", since = "1.1.0")] + pub st_atime_nsec: ::c_long, + #[stable(feature = "raw_ext", since = "1.1.0")] + pub st_mtime: ::time_t, + #[stable(feature = "raw_ext", since = "1.1.0")] + pub st_mtime_nsec: ::c_long, + #[stable(feature = "raw_ext", since = "1.1.0")] + pub st_ctime: ::time_t, + #[stable(feature = "raw_ext", since = "1.1.0")] + pub st_ctime_nsec: ::c_long, + #[stable(feature = "raw_ext", since = "1.1.0")] + pub __pad3: [::c_int; 2], + } +} + +#[cfg(any( + target_arch = "mips64", + target_arch = "s390x", + target_arch = "sparc64", + target_arch = "riscv64" +))] +mod arch { + pub use libc::{blkcnt_t, blksize_t, ino_t, nlink_t, off_t, stat, time_t}; +} + +#[cfg(target_arch = "aarch64")] +mod arch { + use crate::os::raw::{c_int, c_long}; + + #[stable(feature = "raw_ext", since = "1.1.0")] + pub type blkcnt_t = u64; + #[stable(feature = "raw_ext", since = "1.1.0")] + pub type blksize_t = u64; + #[stable(feature = "raw_ext", since = "1.1.0")] + pub type ino_t = u64; + #[stable(feature = "raw_ext", since = "1.1.0")] + pub type nlink_t = u64; + #[stable(feature = "raw_ext", since = "1.1.0")] + pub type off_t = u64; + #[stable(feature = "raw_ext", since = "1.1.0")] + pub type time_t = i64; + + #[repr(C)] + #[derive(Clone)] + #[stable(feature = "raw_ext", since = "1.1.0")] + pub struct stat { + #[stable(feature = "raw_ext", since = "1.1.0")] + pub st_dev: u64, + #[stable(feature = "raw_ext", since = "1.1.0")] + pub st_ino: u64, + #[stable(feature = "raw_ext", since = "1.1.0")] + pub st_mode: u32, + #[stable(feature = "raw_ext", since = "1.1.0")] + pub st_nlink: u32, + #[stable(feature = "raw_ext", since = "1.1.0")] + pub st_uid: u32, + #[stable(feature = "raw_ext", since = "1.1.0")] + pub st_gid: u32, + #[stable(feature = "raw_ext", since = "1.1.0")] + pub st_rdev: u64, + #[stable(feature = "raw_ext", since = "1.1.0")] + pub __pad1: u64, + #[stable(feature = "raw_ext", since = "1.1.0")] + pub st_size: i64, + #[stable(feature = "raw_ext", since = "1.1.0")] + pub st_blksize: i32, + #[stable(feature = "raw_ext", since = "1.1.0")] + pub __pad2: c_int, + #[stable(feature = "raw_ext", since = "1.1.0")] + pub st_blocks: i64, + #[stable(feature = "raw_ext", since = "1.1.0")] + pub st_atime: i64, + #[stable(feature = "raw_ext", since = "1.1.0")] + pub st_atime_nsec: c_long, + #[stable(feature = "raw_ext", since = "1.1.0")] + pub st_mtime: i64, + #[stable(feature = "raw_ext", since = "1.1.0")] + pub st_mtime_nsec: c_long, + #[stable(feature = "raw_ext", since = "1.1.0")] + pub st_ctime: i64, + #[stable(feature = "raw_ext", since = "1.1.0")] + pub st_ctime_nsec: c_long, + #[stable(feature = "raw_ext", since = "1.1.0")] + pub __unused: [c_int; 2], + } +} + +#[cfg(any(target_arch = "x86_64", target_arch = "powerpc64"))] +mod arch { + use crate::os::raw::{c_int, c_long}; + + #[stable(feature = "raw_ext", since = "1.1.0")] + pub type blkcnt_t = u64; + #[stable(feature = "raw_ext", since = "1.1.0")] + pub type blksize_t = u64; + #[stable(feature = "raw_ext", since = "1.1.0")] + pub type ino_t = u64; + #[stable(feature = "raw_ext", since = "1.1.0")] + pub type nlink_t = u64; + #[stable(feature = "raw_ext", since = "1.1.0")] + pub type off_t = u64; + #[stable(feature = "raw_ext", since = "1.1.0")] + pub type time_t = i64; + + #[repr(C)] + #[derive(Clone)] + #[stable(feature = "raw_ext", since = "1.1.0")] + pub struct stat { + #[stable(feature = "raw_ext", since = "1.1.0")] + pub st_dev: u64, + #[stable(feature = "raw_ext", since = "1.1.0")] + pub st_ino: u64, + #[stable(feature = "raw_ext", since = "1.1.0")] + pub st_nlink: u64, + #[stable(feature = "raw_ext", since = "1.1.0")] + pub st_mode: u32, + #[stable(feature = "raw_ext", since = "1.1.0")] + pub st_uid: u32, + #[stable(feature = "raw_ext", since = "1.1.0")] + pub st_gid: u32, + #[stable(feature = "raw_ext", since = "1.1.0")] + pub __pad0: c_int, + #[stable(feature = "raw_ext", since = "1.1.0")] + pub st_rdev: u64, + #[stable(feature = "raw_ext", since = "1.1.0")] + pub st_size: i64, + #[stable(feature = "raw_ext", since = "1.1.0")] + pub st_blksize: i64, + #[stable(feature = "raw_ext", since = "1.1.0")] + pub st_blocks: i64, + #[stable(feature = "raw_ext", since = "1.1.0")] + pub st_atime: i64, + #[stable(feature = "raw_ext", since = "1.1.0")] + pub st_atime_nsec: c_long, + #[stable(feature = "raw_ext", since = "1.1.0")] + pub st_mtime: i64, + #[stable(feature = "raw_ext", since = "1.1.0")] + pub st_mtime_nsec: c_long, + #[stable(feature = "raw_ext", since = "1.1.0")] + pub st_ctime: i64, + #[stable(feature = "raw_ext", since = "1.1.0")] + pub st_ctime_nsec: c_long, + #[stable(feature = "raw_ext", since = "1.1.0")] + pub __unused: [c_long; 3], + } +} diff --git a/src/libstd/os/mod.rs b/src/libstd/os/mod.rs index 0fa4a1d2353ca..341e7ca80b2af 100644 --- a/src/libstd/os/mod.rs +++ b/src/libstd/os/mod.rs @@ -68,5 +68,7 @@ pub mod solaris; pub mod vxworks; #[cfg(target_os = "wasi")] pub mod wasi; +#[cfg(target_vendor = "libnx")] +pub mod libnx; pub mod raw; diff --git a/src/libstd/os/raw/mod.rs b/src/libstd/os/raw/mod.rs index 47daf0cce1b37..3a59662a80c69 100644 --- a/src/libstd/os/raw/mod.rs +++ b/src/libstd/os/raw/mod.rs @@ -47,7 +47,8 @@ target_arch = "powerpc" ) ), - all(target_os = "fuchsia", target_arch = "aarch64") + all(target_os = "fuchsia", target_arch = "aarch64"), + target_os = "horizon" ))] #[stable(feature = "raw_os", since = "1.1.0")] pub type c_char = u8; @@ -90,7 +91,8 @@ pub type c_char = u8; target_arch = "powerpc" ) ), - all(target_os = "fuchsia", target_arch = "aarch64") + all(target_os = "fuchsia", target_arch = "aarch64"), + target_os = "horizon" )))] #[stable(feature = "raw_os", since = "1.1.0")] pub type c_char = i8; diff --git a/src/libstd/sys/unix/alloc.rs b/src/libstd/sys/unix/alloc.rs index 77417e4133127..a02681bba87c7 100644 --- a/src/libstd/sys/unix/alloc.rs +++ b/src/libstd/sys/unix/alloc.rs @@ -75,7 +75,7 @@ unsafe fn aligned_malloc(layout: &Layout) -> *mut u8 { libc::memalign(layout.align(), layout.size()) as *mut u8 } -#[cfg(not(any(target_os = "android", target_os = "redox", target_os = "solaris")))] +#[cfg(not(any(target_os = "android", target_os = "redox", target_os = "solaris", target_env = "newlib")))] #[inline] unsafe fn aligned_malloc(layout: &Layout) -> *mut u8 { let mut out = ptr::null_mut(); @@ -85,3 +85,9 @@ unsafe fn aligned_malloc(layout: &Layout) -> *mut u8 { let ret = libc::posix_memalign(&mut out, align, layout.size()); if ret != 0 { ptr::null_mut() } else { out as *mut u8 } } + +#[cfg(target_env = "newlib")] +#[inline] +unsafe fn aligned_malloc(layout: &Layout) -> *mut u8 { + libc::aligned_alloc(layout.align(), layout.size()) as *mut u8 +} diff --git a/src/libstd/sys/unix/args.rs b/src/libstd/sys/unix/args.rs index 09acc3f6e3ea8..3fc283c6817f8 100644 --- a/src/libstd/sys/unix/args.rs +++ b/src/libstd/sys/unix/args.rs @@ -69,7 +69,8 @@ impl DoubleEndedIterator for Args { target_os = "haiku", target_os = "l4re", target_os = "fuchsia", - target_os = "redox" + target_os = "redox", + target_vendor = "libnx" ))] mod imp { use super::Args; diff --git a/src/libstd/sys/unix/env.rs b/src/libstd/sys/unix/env.rs index 984bcfa45099b..8a8842ba48f0c 100644 --- a/src/libstd/sys/unix/env.rs +++ b/src/libstd/sys/unix/env.rs @@ -162,3 +162,14 @@ pub mod os { pub const EXE_SUFFIX: &str = ""; pub const EXE_EXTENSION: &str = ""; } + +#[cfg(target_os = "horizon")] +pub mod os { + pub const FAMILY: &str = "unix"; + pub const OS: &str = "horizon"; + pub const DLL_PREFIX: &str = "lib"; + pub const DLL_SUFFIX: &str = ".so"; + pub const DLL_EXTENSION: &str = "so"; + pub const EXE_SUFFIX: &str = ".nro"; + pub const EXE_EXTENSION: &str = "nro"; +} diff --git a/src/libstd/sys/unix/ext/fs.rs b/src/libstd/sys/unix/ext/fs.rs index 732cd677a1859..106aa52ebb2b7 100644 --- a/src/libstd/sys/unix/ext/fs.rs +++ b/src/libstd/sys/unix/ext/fs.rs @@ -689,21 +689,36 @@ impl MetadataExt for fs::Metadata { fn atime(&self) -> i64 { self.st_atime() } + #[cfg(not(target_env = "newlib"))] fn atime_nsec(&self) -> i64 { self.st_atime_nsec() } + #[cfg(target_env = "newlib")] + fn atime_nsec(&self) -> i64 { + 0 + } fn mtime(&self) -> i64 { self.st_mtime() } + #[cfg(not(target_env = "newlib"))] fn mtime_nsec(&self) -> i64 { self.st_mtime_nsec() } + #[cfg(target_env = "newlib")] + fn mtime_nsec(&self) -> i64 { + 0 + } fn ctime(&self) -> i64 { self.st_ctime() } + #[cfg(not(target_env = "newlib"))] fn ctime_nsec(&self) -> i64 { self.st_ctime_nsec() } + #[cfg(target_env = "newlib")] + fn ctime_nsec(&self) -> i64 { + 0 + } fn blksize(&self) -> u64 { self.st_blksize() } diff --git a/src/libstd/sys/unix/fd.rs b/src/libstd/sys/unix/fd.rs index 8a99836912a33..e16eba93ef830 100644 --- a/src/libstd/sys/unix/fd.rs +++ b/src/libstd/sys/unix/fd.rs @@ -1,3 +1,4 @@ +#![cfg_attr(target_env = "newlib", allow(unused_variables, dead_code))] #![unstable(reason = "not public", issue = "none", feature = "fd")] use crate::cmp; @@ -53,6 +54,7 @@ impl FileDesc { Ok(ret as usize) } + #[cfg(not(target_env = "newlib"))] pub fn read_vectored(&self, bufs: &mut [IoSliceMut<'_>]) -> io::Result { let ret = cvt(unsafe { libc::readv( @@ -64,6 +66,11 @@ impl FileDesc { Ok(ret as usize) } + #[cfg(target_env = "newlib")] + pub fn read_vectored(&self, bufs: &mut [IoSliceMut<'_>]) -> io::Result { + Err(io::Error::new(io::ErrorKind::Other, "operation not supported")) + } + pub fn read_to_end(&self, buf: &mut Vec) -> io::Result { let mut me = self; (&mut me).read_to_end(buf) @@ -73,7 +80,7 @@ impl FileDesc { #[cfg(target_os = "android")] use super::android::cvt_pread64; - #[cfg(not(target_os = "android"))] + #[cfg(not(any(target_os = "android", target_env = "newlib")))] unsafe fn cvt_pread64( fd: c_int, buf: *mut c_void, @@ -87,6 +94,21 @@ impl FileDesc { cvt(pread64(fd, buf, count, offset)) } + #[cfg(target_env = "newlib")] + unsafe fn cvt_pread64( + fd: c_int, + buf: *mut c_void, + count: usize, + offset: i64, + ) -> io::Result { + // ported from newlib, because it inexplicably was not being compiled + let cur_pos = cvt(libc::lseek(fd, 0, libc::SEEK_CUR))?; + cvt(libc::lseek(fd, offset, libc::SEEK_SET))?; + let num_read = cvt(libc::read(fd, buf, count))?; + cvt(libc::lseek(fd, cur_pos, libc::SEEK_SET))?; + Ok(num_read as _) + } + unsafe { cvt_pread64( self.fd, @@ -105,6 +127,7 @@ impl FileDesc { Ok(ret as usize) } + #[cfg(not(target_env = "newlib"))] pub fn write_vectored(&self, bufs: &[IoSlice<'_>]) -> io::Result { let ret = cvt(unsafe { libc::writev( @@ -116,11 +139,16 @@ impl FileDesc { Ok(ret as usize) } + #[cfg(target_env = "newlib")] + pub fn write_vectored(&self, bufs: &[IoSlice<'_>]) -> io::Result { + Err(io::Error::new(io::ErrorKind::Other, "operation not supported")) + } + pub fn write_at(&self, buf: &[u8], offset: u64) -> io::Result { #[cfg(target_os = "android")] use super::android::cvt_pwrite64; - #[cfg(not(target_os = "android"))] + #[cfg(not(any(target_os = "android", target_env = "newlib")))] unsafe fn cvt_pwrite64( fd: c_int, buf: *const c_void, @@ -134,6 +162,21 @@ impl FileDesc { cvt(pwrite64(fd, buf, count, offset)) } + #[cfg(target_env = "newlib")] + unsafe fn cvt_pwrite64( + fd: c_int, + buf: *const c_void, + count: usize, + offset: i64, + ) -> io::Result { + // see pread + let cur_pos = cvt(libc::lseek(fd, 0, libc::SEEK_CUR))?; + cvt(libc::lseek(fd, offset, libc::SEEK_SET))?; + let num_written = cvt(libc::write(fd, buf, count))?; + cvt(libc::lseek(fd, cur_pos, libc::SEEK_SET))?; + Ok(num_written) + } + unsafe { cvt_pwrite64( self.fd, diff --git a/src/libstd/sys/unix/fs.rs b/src/libstd/sys/unix/fs.rs index ab2a871b92df4..77c7e4b2ce629 100644 --- a/src/libstd/sys/unix/fs.rs +++ b/src/libstd/sys/unix/fs.rs @@ -154,12 +154,14 @@ cfg_has_statx! {{ stat.st_blksize = buf.stx_blksize as libc::blksize_t; stat.st_blocks = buf.stx_blocks as libc::blkcnt64_t; stat.st_atime = buf.stx_atime.tv_sec as libc::time_t; - // `i64` on gnu-x86_64-x32, `c_ulong` otherwise. - stat.st_atime_nsec = buf.stx_atime.tv_nsec as _; stat.st_mtime = buf.stx_mtime.tv_sec as libc::time_t; - stat.st_mtime_nsec = buf.stx_mtime.tv_nsec as _; stat.st_ctime = buf.stx_ctime.tv_sec as libc::time_t; - stat.st_ctime_nsec = buf.stx_ctime.tv_nsec as _; + // `i64` on gnu-x86_64-x32, `c_ulong` otherwise. + #[cfg(not(target_env = "newlib"))] { + stat.st_atime_nsec = buf.stx_atime.tv_nsec as _; + stat.st_mtime_nsec = buf.stx_mtime.tv_nsec as _; + stat.st_ctime_nsec = buf.stx_ctime.tv_nsec as _; + } let extra = StatxExtraFields { stx_mask: buf.stx_mask, @@ -289,6 +291,9 @@ impl FileAttr { pub fn modified(&self) -> io::Result { Ok(SystemTime::from(libc::timespec { tv_sec: self.stat.st_mtime as libc::time_t, + #[cfg(target_env = "newlib")] + tv_nsec: 0, + #[cfg(not(target_env = "newlib"))] tv_nsec: self.stat.st_mtime_nsec as _, })) } @@ -296,6 +301,9 @@ impl FileAttr { pub fn accessed(&self) -> io::Result { Ok(SystemTime::from(libc::timespec { tv_sec: self.stat.st_atime as libc::time_t, + #[cfg(target_env = "newlib")] + tv_nsec: 0, + #[cfg(not(target_env = "newlib"))] tv_nsec: self.stat.st_atime_nsec as _, })) } @@ -543,7 +551,8 @@ impl DirEntry { target_os = "haiku", target_os = "l4re", target_os = "fuchsia", - target_os = "redox" + target_os = "redox", + target_env = "newlib" ))] pub fn ino(&self) -> u64 { self.entry.d_ino as u64 @@ -581,7 +590,8 @@ impl DirEntry { target_os = "linux", target_os = "emscripten", target_os = "l4re", - target_os = "haiku" + target_os = "haiku", + target_env = "newlib" ))] fn name_bytes(&self) -> &[u8] { unsafe { CStr::from_ptr(self.entry.d_name.as_ptr()).to_bytes() } @@ -987,6 +997,7 @@ pub fn rmdir(p: &Path) -> io::Result<()> { Ok(()) } +#[cfg(not(target_os = "horizon"))] pub fn readlink(p: &Path) -> io::Result { let c_path = cstr(p)?; let p = c_path.as_ptr(); @@ -1014,6 +1025,12 @@ pub fn readlink(p: &Path) -> io::Result { } } +#[cfg(target_os = "horizon")] +pub fn readlink(p: &Path) -> io::Result { + Ok(p.to_path_buf()) // horizon doesn't have symlinks +} + +#[cfg(not(target_os = "horizon"))] pub fn symlink(src: &Path, dst: &Path) -> io::Result<()> { let src = cstr(src)?; let dst = cstr(dst)?; @@ -1021,6 +1038,11 @@ pub fn symlink(src: &Path, dst: &Path) -> io::Result<()> { Ok(()) } +#[cfg(target_os = "horizon")] +pub fn symlink(_src: &Path, _dst: &Path) -> io::Result<()> { + Err(io::Error::new(io::ErrorKind::Other, "not supported")) // horizon doesn't have symlinks +} + pub fn link(src: &Path, dst: &Path) -> io::Result<()> { let src = cstr(src)?; let dst = cstr(dst)?; @@ -1066,6 +1088,7 @@ pub fn lstat(p: &Path) -> io::Result { Ok(FileAttr::from_stat64(stat)) } +#[cfg(not(target_os = "horizon"))] pub fn canonicalize(p: &Path) -> io::Result { let path = CString::new(p.as_os_str().as_bytes())?; let buf; @@ -1080,6 +1103,14 @@ pub fn canonicalize(p: &Path) -> io::Result { Ok(PathBuf::from(OsString::from_vec(buf))) } +#[cfg(target_os = "horizon")] +pub fn canonicalize(p: &Path) -> io::Result { + // horizon has no symlinks or realpath + let mut cwd = crate::env::current_dir()?; + cwd.push(p); + Ok(cwd) +} + fn open_from(from: &Path) -> io::Result<(crate::fs::File, crate::fs::Metadata)> { use crate::fs::File; diff --git a/src/libstd/sys/unix/mod.rs b/src/libstd/sys/unix/mod.rs index fbcb006ecdf11..765e095eb2371 100644 --- a/src/libstd/sys/unix/mod.rs +++ b/src/libstd/sys/unix/mod.rs @@ -31,6 +31,8 @@ pub use crate::os::openbsd as platform; pub use crate::os::redox as platform; #[cfg(all(not(doc), target_os = "solaris"))] pub use crate::os::solaris as platform; +#[cfg(all(not(doc), target_vendor = "libnx"))] +pub use crate::os::libnx as platform; pub use self::rand::hashmap_random_keys; pub use libc::strlen; diff --git a/src/libstd/sys/unix/net.rs b/src/libstd/sys/unix/net.rs index b37675e0a0a00..4945dbaf9cc3b 100644 --- a/src/libstd/sys/unix/net.rs +++ b/src/libstd/sys/unix/net.rs @@ -1,3 +1,5 @@ +#![cfg_attr(target_env = "newlib", allow(unused_variables, dead_code))] + use crate::cmp; use crate::ffi::CStr; use crate::io::{self, IoSlice, IoSliceMut}; @@ -314,14 +316,25 @@ impl Socket { } pub fn set_nodelay(&self, nodelay: bool) -> io::Result<()> { - setsockopt(self, libc::IPPROTO_TCP, libc::TCP_NODELAY, nodelay as c_int) + #[cfg(not(target_env = "newlib"))] { + setsockopt(self, libc::IPPROTO_TCP, libc::TCP_NODELAY, nodelay as c_int) + } + #[cfg(target_env = "newlib")] { + Ok(()) + } } + #[cfg(not(target_env = "newlib"))] pub fn nodelay(&self) -> io::Result { let raw: c_int = getsockopt(self, libc::IPPROTO_TCP, libc::TCP_NODELAY)?; Ok(raw != 0) } + #[cfg(target_env = "newlib")] + pub fn nodelay(&self) -> io::Result { + Ok(false) + } + pub fn set_nonblocking(&self, nonblocking: bool) -> io::Result<()> { let mut nonblocking = nonblocking as libc::c_int; cvt(unsafe { libc::ioctl(*self.as_inner(), libc::FIONBIO, &mut nonblocking) }).map(drop) diff --git a/src/libstd/sys/unix/os.rs b/src/libstd/sys/unix/os.rs index 91f7d1524ccef..54efbd82dee96 100644 --- a/src/libstd/sys/unix/os.rs +++ b/src/libstd/sys/unix/os.rs @@ -1,6 +1,7 @@ //! Implementation of `std::os` functionality for unix systems #![allow(unused_imports)] // lots of cfg code here +#![cfg_attr(target_env = "newlib", allow(unused_variables, dead_code))] use crate::os::unix::prelude::*; @@ -435,6 +436,15 @@ pub fn current_exe() -> io::Result { Err(io::Error::new(ErrorKind::Other, "Not yet implemented!")) } +#[cfg(target_vendor = "libnx")] +pub fn current_exe() -> io::Result { + use crate::env; + // guaranteed by abi to be an absolute path to the executable + env::args_os().next().map(From::from).ok_or_else(|| { + io::Error::new(io::ErrorKind::Other, "no current exe available") + }) +} + pub struct Env { iter: vec::IntoIter<(OsString, OsString)>, _dont_send_or_sync_me: PhantomData<*mut ()>, @@ -544,10 +554,16 @@ pub fn unsetenv(n: &OsStr) -> io::Result<()> { } } +#[cfg(not(target_os = "horizon"))] pub fn page_size() -> usize { unsafe { libc::sysconf(libc::_SC_PAGESIZE) as usize } } +#[cfg(target_os = "horizon")] +pub fn page_size() -> usize { + 0x1000 +} + pub fn temp_dir() -> PathBuf { crate::env::var_os("TMPDIR").map(PathBuf::from).unwrap_or_else(|| { if cfg!(target_os = "android") { @@ -565,7 +581,8 @@ pub fn home_dir() -> Option { target_os = "android", target_os = "ios", target_os = "emscripten", - target_os = "redox" + target_os = "redox", + target_os = "horizon" ))] unsafe fn fallback() -> Option { None @@ -574,7 +591,8 @@ pub fn home_dir() -> Option { target_os = "android", target_os = "ios", target_os = "emscripten", - target_os = "redox" + target_os = "redox", + target_os = "horizon" )))] unsafe fn fallback() -> Option { let amt = match libc::sysconf(libc::_SC_GETPW_R_SIZE_MAX) { @@ -609,10 +627,16 @@ pub fn getpid() -> u32 { unsafe { libc::getpid() as u32 } } +#[cfg(not(target_os = "horizon"))] pub fn getppid() -> u32 { unsafe { libc::getppid() as u32 } } +#[cfg(target_os = "horizon")] +pub fn getppid() -> u32 { + 1 // horizon doesn't have a process hierarchy +} + #[cfg(target_env = "gnu")] pub fn glibc_version() -> Option<(usize, usize)> { if let Some(Ok(version_str)) = glibc_version_cstr().map(CStr::to_str) { diff --git a/src/libstd/sys/unix/pipe.rs b/src/libstd/sys/unix/pipe.rs index 2a861c878015e..69b1878b6079a 100644 --- a/src/libstd/sys/unix/pipe.rs +++ b/src/libstd/sys/unix/pipe.rs @@ -1,3 +1,5 @@ +#![cfg_attr(target_env = "newlib", allow(unused_variables, dead_code))] + use crate::io::{self, IoSlice, IoSliceMut}; use crate::mem; use crate::sync::atomic::{AtomicBool, Ordering}; diff --git a/src/libstd/sys/unix/process/mod.rs b/src/libstd/sys/unix/process/mod.rs index 553e980f08e97..41f0dc305af99 100644 --- a/src/libstd/sys/unix/process/mod.rs +++ b/src/libstd/sys/unix/process/mod.rs @@ -3,11 +3,14 @@ pub use self::process_inner::{ExitStatus, Process}; pub use crate::ffi::OsString as EnvKey; mod process_common; -#[cfg(not(target_os = "fuchsia"))] +#[cfg(not(any(target_os = "fuchsia", target_os = "horizon")))] #[path = "process_unix.rs"] mod process_inner; #[cfg(target_os = "fuchsia")] #[path = "process_fuchsia.rs"] mod process_inner; +#[cfg(target_os = "horizon")] +#[path = "process_dummy.rs"] +mod process_inner; #[cfg(target_os = "fuchsia")] mod zircon; diff --git a/src/libstd/sys/unix/process/process_common.rs b/src/libstd/sys/unix/process/process_common.rs index 859da691ad278..1bbf3673229e3 100644 --- a/src/libstd/sys/unix/process/process_common.rs +++ b/src/libstd/sys/unix/process/process_common.rs @@ -1,3 +1,5 @@ +#![cfg_attr(target_env = "newlib", allow(unused_variables, dead_code))] + use crate::os::unix::prelude::*; use crate::collections::BTreeMap; diff --git a/src/libstd/sys/unix/process/process_dummy.rs b/src/libstd/sys/unix/process/process_dummy.rs new file mode 100644 index 0000000000000..88db58559f510 --- /dev/null +++ b/src/libstd/sys/unix/process/process_dummy.rs @@ -0,0 +1,94 @@ +use crate::fmt; +use crate::io; +use crate::sys::process::process_common::*; +use crate::os::raw::c_int; + +pub use crate::ffi::OsString as EnvKey; + +fn unsupported() -> io::Result { + Err(unsupported_err()) +} + +fn unsupported_err() -> io::Error { + io::Error::new(io::ErrorKind::Other, "operation not supported") +} + +#[derive(Copy, Clone, PartialEq, Eq, PartialOrd, Ord, Debug, Hash)] +pub enum Void {} + +//////////////////////////////////////////////////////////////////////////////// +// Command +//////////////////////////////////////////////////////////////////////////////// + +impl Command { + pub fn spawn( + &mut self, + _default: Stdio, + _needs_stdin: bool, + ) -> io::Result<(Process, StdioPipes)> { + unsupported() + } + + pub fn exec(&mut self, _default: Stdio) -> io::Error { + unsupported_err() + } +} + +/// Unix exit statuses +#[derive(PartialEq, Eq, Clone, Copy, Debug)] +pub struct ExitStatus(c_int); + +impl ExitStatus { + fn exited(&self) -> bool { + libc::WIFEXITED(self.0) + } + + pub fn success(&self) -> bool { + self.code() == Some(0) + } + + pub fn code(&self) -> Option { + if self.exited() { Some(libc::WEXITSTATUS(self.0)) } else { None } + } + + pub fn signal(&self) -> Option { + if !self.exited() { Some(libc::WTERMSIG(self.0)) } else { None } + } +} + +impl From for ExitStatus { + fn from(a: c_int) -> ExitStatus { + ExitStatus(a) + } +} + +impl fmt::Display for ExitStatus { + fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { + if let Some(code) = self.code() { + write!(f, "exit code: {}", code) + } else { + let signal = self.signal().unwrap(); + write!(f, "signal: {}", signal) + } + } +} + +pub struct Process(Void); + +impl Process { + pub fn id(&self) -> u32 { + match self.0 {} + } + + pub fn kill(&mut self) -> io::Result<()> { + match self.0 {} + } + + pub fn wait(&mut self) -> io::Result { + match self.0 {} + } + + pub fn try_wait(&mut self) -> io::Result> { + match self.0 {} + } +} diff --git a/src/libstd/sys/unix/time.rs b/src/libstd/sys/unix/time.rs index 6707f790cab0a..69fe9106a13f2 100644 --- a/src/libstd/sys/unix/time.rs +++ b/src/libstd/sys/unix/time.rs @@ -339,9 +339,9 @@ mod inner { } } - #[cfg(not(target_os = "dragonfly"))] + #[cfg(not(any(target_os = "dragonfly", target_os = "horizon")))] pub type clock_t = libc::c_int; - #[cfg(target_os = "dragonfly")] + #[cfg(any(target_os = "dragonfly", target_os = "horizon"))] pub type clock_t = libc::c_ulong; fn now(clock: clock_t) -> Timespec { diff --git a/src/libstd/sys/unix/weak.rs b/src/libstd/sys/unix/weak.rs index 08cbe59617465..ff83421d6bf17 100644 --- a/src/libstd/sys/unix/weak.rs +++ b/src/libstd/sys/unix/weak.rs @@ -16,6 +16,7 @@ //! symbol, but that caused Debian to detect an unnecessarily strict versioned //! dependency on libc6 (#23628). +#[cfg(not(target_env = "newlib"))] use crate::ffi::CStr; use crate::marker; use crate::mem; @@ -53,6 +54,7 @@ impl Weak { } } +#[cfg(not(target_env = "newlib"))] unsafe fn fetch(name: &str) -> usize { let name = match CStr::from_bytes_with_nul(name.as_bytes()) { Ok(cstr) => cstr, @@ -61,6 +63,11 @@ unsafe fn fetch(name: &str) -> usize { libc::dlsym(libc::RTLD_DEFAULT, name.as_ptr()) as usize } +#[cfg(target_env = "newlib")] +unsafe fn fetch(_name: &str) -> usize { + 0 +} + #[cfg(not(target_os = "linux"))] macro_rules! syscall { (fn $name:ident($($arg_name:ident: $t:ty),*) -> $ret:ty) => ( diff --git a/src/libstd/sys_common/net.rs b/src/libstd/sys_common/net.rs index 135e8308afaea..85a4deea2bb17 100644 --- a/src/libstd/sys_common/net.rs +++ b/src/libstd/sys_common/net.rs @@ -1,3 +1,5 @@ +#![cfg_attr(target_env = "newlib", allow(unused_variables, dead_code))] + use crate::cmp; use crate::convert::{TryFrom, TryInto}; use crate::ffi::CString; @@ -21,7 +23,7 @@ cfg_if::cfg_if! { target_os = "solaris", target_os = "haiku", target_os = "l4re"))] { use crate::sys::net::netc::IPV6_JOIN_GROUP as IPV6_ADD_MEMBERSHIP; use crate::sys::net::netc::IPV6_LEAVE_GROUP as IPV6_DROP_MEMBERSHIP; - } else { + } else if #[cfg(not(target_env = "newlib"))] { use crate::sys::net::netc::IPV6_ADD_MEMBERSHIP; use crate::sys::net::netc::IPV6_DROP_MEMBERSHIP; } @@ -302,11 +304,19 @@ impl TcpStream { } pub fn set_ttl(&self, ttl: u32) -> io::Result<()> { - setsockopt(&self.inner, c::IPPROTO_IP, c::IP_TTL, ttl as c_int) + #[cfg(not(target_env = "newlib"))] { + setsockopt(&self.inner, c::IPPROTO_IP, c::IP_TTL, ttl as c_int) + } + #[cfg(target_env = "newlib")] { + Ok(()) + } } pub fn ttl(&self) -> io::Result { + #[cfg(not(target_env = "newlib"))] let raw: c_int = getsockopt(&self.inner, c::IPPROTO_IP, c::IP_TTL)?; + #[cfg(target_env = "newlib")] + let raw: c_int = 64; Ok(raw as u32) } @@ -399,21 +409,38 @@ impl TcpListener { } pub fn set_ttl(&self, ttl: u32) -> io::Result<()> { - setsockopt(&self.inner, c::IPPROTO_IP, c::IP_TTL, ttl as c_int) + #[cfg(not(target_env = "newlib"))] { + setsockopt(&self.inner, c::IPPROTO_IP, c::IP_TTL, ttl as c_int) + } + #[cfg(target_env = "newlib")] { + Ok(()) + } } pub fn ttl(&self) -> io::Result { + #[cfg(not(target_env = "newlib"))] let raw: c_int = getsockopt(&self.inner, c::IPPROTO_IP, c::IP_TTL)?; + #[cfg(target_env = "newlib")] + let raw: c_int = 64; Ok(raw as u32) } pub fn set_only_v6(&self, only_v6: bool) -> io::Result<()> { - setsockopt(&self.inner, c::IPPROTO_IPV6, c::IPV6_V6ONLY, only_v6 as c_int) + #[cfg(not(target_env = "newlib"))] { + setsockopt(&self.inner, c::IPPROTO_IPV6, c::IPV6_V6ONLY, only_v6 as c_int) + } + #[cfg(target_env = "newlib")] { + Err(io::Error::new(io::ErrorKind::Other, "operation not supported")) + } } pub fn only_v6(&self) -> io::Result { - let raw: c_int = getsockopt(&self.inner, c::IPPROTO_IPV6, c::IPV6_V6ONLY)?; - Ok(raw != 0) + #[cfg(not(target_env = "newlib"))] { + let raw: c_int = getsockopt(&self.inner, c::IPPROTO_IPV6, c::IPV6_V6ONLY)?; + Ok(raw != 0) + } + #[cfg(target_env = "newlib")] + Err(io::Error::new(io::ErrorKind::Other, "operation not supported")) } pub fn take_error(&self) -> io::Result> { @@ -534,80 +561,132 @@ impl UdpSocket { } pub fn set_multicast_loop_v4(&self, multicast_loop_v4: bool) -> io::Result<()> { - setsockopt( - &self.inner, - c::IPPROTO_IP, - c::IP_MULTICAST_LOOP, - multicast_loop_v4 as IpV4MultiCastType, - ) + #[cfg(not(target_env = "newlib"))] { + setsockopt( + &self.inner, + c::IPPROTO_IP, + c::IP_MULTICAST_LOOP, + multicast_loop_v4 as IpV4MultiCastType, + ) + } + #[cfg(target_env = "newlib")] { + Err(io::Error::new(io::ErrorKind::Other, "operation not supported")) + } } pub fn multicast_loop_v4(&self) -> io::Result { - let raw: IpV4MultiCastType = getsockopt(&self.inner, c::IPPROTO_IP, c::IP_MULTICAST_LOOP)?; - Ok(raw != 0) + #[cfg(not(target_env = "newlib"))] { + let raw: IpV4MultiCastType = getsockopt(&self.inner, c::IPPROTO_IP, c::IP_MULTICAST_LOOP)?; + Ok(raw != 0) + } + #[cfg(target_env = "newlib")] { + Err(io::Error::new(io::ErrorKind::Other, "operation not supported")) + } } pub fn set_multicast_ttl_v4(&self, multicast_ttl_v4: u32) -> io::Result<()> { - setsockopt( - &self.inner, - c::IPPROTO_IP, - c::IP_MULTICAST_TTL, - multicast_ttl_v4 as IpV4MultiCastType, - ) + #[cfg(not(target_env = "newlib"))] { + setsockopt( + &self.inner, + c::IPPROTO_IP, + c::IP_MULTICAST_TTL, + multicast_ttl_v4 as IpV4MultiCastType, + ) + } + #[cfg(target_env = "newlib")] { + Err(io::Error::new(io::ErrorKind::Other, "operation not supported")) + } } pub fn multicast_ttl_v4(&self) -> io::Result { - let raw: IpV4MultiCastType = getsockopt(&self.inner, c::IPPROTO_IP, c::IP_MULTICAST_TTL)?; - Ok(raw as u32) + #[cfg(not(target_env = "newlib"))] { + let raw: IpV4MultiCastType = getsockopt(&self.inner, c::IPPROTO_IP, c::IP_MULTICAST_TTL)?; + Ok(raw as u32) + } + #[cfg(target_env = "newlib")] + Err(io::Error::new(io::ErrorKind::Other, "operation not supported")) } pub fn set_multicast_loop_v6(&self, multicast_loop_v6: bool) -> io::Result<()> { - setsockopt(&self.inner, c::IPPROTO_IPV6, c::IPV6_MULTICAST_LOOP, multicast_loop_v6 as c_int) + #[cfg(not(target_env = "newlib"))] { + setsockopt(&self.inner, c::IPPROTO_IPV6, c::IPV6_MULTICAST_LOOP, multicast_loop_v6 as c_int) + } + #[cfg(target_env = "newlib")] { + Err(io::Error::new(io::ErrorKind::Other, "operation not supported")) + } } pub fn multicast_loop_v6(&self) -> io::Result { - let raw: c_int = getsockopt(&self.inner, c::IPPROTO_IPV6, c::IPV6_MULTICAST_LOOP)?; - Ok(raw != 0) + #[cfg(not(target_env = "newlib"))] { + let raw: c_int = getsockopt(&self.inner, c::IPPROTO_IPV6, c::IPV6_MULTICAST_LOOP)?; + Ok(raw != 0) + } + #[cfg(target_env = "newlib")] + Err(io::Error::new(io::ErrorKind::Other, "operation not supported")) } pub fn join_multicast_v4(&self, multiaddr: &Ipv4Addr, interface: &Ipv4Addr) -> io::Result<()> { - let mreq = c::ip_mreq { - imr_multiaddr: *multiaddr.as_inner(), - imr_interface: *interface.as_inner(), - }; - setsockopt(&self.inner, c::IPPROTO_IP, c::IP_ADD_MEMBERSHIP, mreq) + #[cfg(not(target_env = "newlib"))] { + let mreq = c::ip_mreq { + imr_multiaddr: *multiaddr.as_inner(), + imr_interface: *interface.as_inner(), + }; + setsockopt(&self.inner, c::IPPROTO_IP, c::IP_ADD_MEMBERSHIP, mreq) + } + #[cfg(target_env = "newlib")] + Err(io::Error::new(io::ErrorKind::Other, "operation not supported")) } pub fn join_multicast_v6(&self, multiaddr: &Ipv6Addr, interface: u32) -> io::Result<()> { - let mreq = c::ipv6_mreq { - ipv6mr_multiaddr: *multiaddr.as_inner(), - ipv6mr_interface: to_ipv6mr_interface(interface), - }; - setsockopt(&self.inner, c::IPPROTO_IPV6, IPV6_ADD_MEMBERSHIP, mreq) + #[cfg(not(target_env = "newlib"))] { + let mreq = c::ipv6_mreq { + ipv6mr_multiaddr: *multiaddr.as_inner(), + ipv6mr_interface: to_ipv6mr_interface(interface), + }; + setsockopt(&self.inner, c::IPPROTO_IPV6, IPV6_ADD_MEMBERSHIP, mreq) + } + #[cfg(target_env = "newlib")] + Err(io::Error::new(io::ErrorKind::Other, "operation not supported")) } pub fn leave_multicast_v4(&self, multiaddr: &Ipv4Addr, interface: &Ipv4Addr) -> io::Result<()> { - let mreq = c::ip_mreq { - imr_multiaddr: *multiaddr.as_inner(), - imr_interface: *interface.as_inner(), - }; - setsockopt(&self.inner, c::IPPROTO_IP, c::IP_DROP_MEMBERSHIP, mreq) + #[cfg(not(target_env = "newlib"))] { + let mreq = c::ip_mreq { + imr_multiaddr: *multiaddr.as_inner(), + imr_interface: *interface.as_inner(), + }; + setsockopt(&self.inner, c::IPPROTO_IP, c::IP_DROP_MEMBERSHIP, mreq) + } + #[cfg(target_env = "newlib")] + Err(io::Error::new(io::ErrorKind::Other, "operation not supported")) } pub fn leave_multicast_v6(&self, multiaddr: &Ipv6Addr, interface: u32) -> io::Result<()> { - let mreq = c::ipv6_mreq { - ipv6mr_multiaddr: *multiaddr.as_inner(), - ipv6mr_interface: to_ipv6mr_interface(interface), - }; - setsockopt(&self.inner, c::IPPROTO_IPV6, IPV6_DROP_MEMBERSHIP, mreq) + #[cfg(not(target_env = "newlib"))] { + let mreq = c::ipv6_mreq { + ipv6mr_multiaddr: *multiaddr.as_inner(), + ipv6mr_interface: to_ipv6mr_interface(interface), + }; + setsockopt(&self.inner, c::IPPROTO_IPV6, IPV6_DROP_MEMBERSHIP, mreq) + } + #[cfg(target_env = "newlib")] + Err(io::Error::new(io::ErrorKind::Other, "operation not supported")) } pub fn set_ttl(&self, ttl: u32) -> io::Result<()> { - setsockopt(&self.inner, c::IPPROTO_IP, c::IP_TTL, ttl as c_int) + #[cfg(not(target_env = "newlib"))] { + setsockopt(&self.inner, c::IPPROTO_IP, c::IP_TTL, ttl as c_int) + } + #[cfg(target_env = "newlib")] { + Ok(()) + } } pub fn ttl(&self) -> io::Result { + #[cfg(not(target_env = "newlib"))] let raw: c_int = getsockopt(&self.inner, c::IPPROTO_IP, c::IP_TTL)?; + #[cfg(target_env = "newlib")] + let raw: c_int = 64; Ok(raw as u32) } diff --git a/src/libtest/helpers/concurrency.rs b/src/libtest/helpers/concurrency.rs index 6b0c8a8af32b4..2671add39973a 100644 --- a/src/libtest/helpers/concurrency.rs +++ b/src/libtest/helpers/concurrency.rs @@ -146,4 +146,10 @@ pub fn get_concurrency() -> usize { // FIXME: implement 1 } + + #[cfg(target_vendor = "libnx")] + fn num_cpus() -> usize { + // FIXME: implement + 1 + } } diff --git a/src/libunwind/Cargo.toml b/src/libunwind/Cargo.toml index 77bcfffd506c9..045268c406b73 100644 --- a/src/libunwind/Cargo.toml +++ b/src/libunwind/Cargo.toml @@ -18,7 +18,7 @@ doc = false [dependencies] core = { path = "../libcore" } libc = { version = "0.2.51", features = ['rustc-dep-of-std'], default-features = false } -compiler_builtins = "0.1.0" +compiler_builtins = "=0.1.27" cfg-if = "0.1.8" [build-dependencies] diff --git a/src/libunwind/build.rs b/src/libunwind/build.rs index 0628e5d2fc03a..6d735cfe075b0 100644 --- a/src/libunwind/build.rs +++ b/src/libunwind/build.rs @@ -50,6 +50,8 @@ fn main() { // redox is handled in lib.rs } else if target.contains("cloudabi") { println!("cargo:rustc-link-lib=unwind"); + } else if target.contains("libnx") { + llvm_libunwind::compile(); } } @@ -89,6 +91,12 @@ mod llvm_libunwind { cfg.flag("-funwind-tables"); } + if target_vendor == "libnx" { + cfg.define("_LIBUNWIND_IS_BAREMETAL", None); + cfg.define("_LIBUNWIND_SUPPORT_DWARF_UNWIND", None); + cfg.define("_LIBUNWIND_SUPPORT_DWARF_INDEX", None); + } + let mut unwind_sources = vec![ "Unwind-EHABI.cpp", "Unwind-seh.cpp",