Skip to content

Commit

Permalink
rust: Port cargo and ripgrep
Browse files Browse the repository at this point in the history
  • Loading branch information
64 committed May 8, 2021
1 parent a2f254c commit 421a895
Show file tree
Hide file tree
Showing 7 changed files with 155 additions and 5 deletions.
25 changes: 24 additions & 1 deletion bootstrap.d/dev-lang.yml
Expand Up @@ -30,6 +30,13 @@ sources:
tag: '0.2.93'
version: '0.2.93'

- name: host-bootstrap-cargo
subdir: 'ports'
url: 'https://static.rust-lang.org/dist/2021-05-08/cargo-nightly-x86_64-unknown-linux-gnu.tar.xz'
format: 'tar.xz'
extract_path: 'cargo-nightly-x86_64-unknown-linux-gnu'
version: '0.53.0'

tools:
- name: host-python
from_source: python
Expand All @@ -49,6 +56,7 @@ tools:
tools_required:
- host-llvm-toolchain
compile:
- cargo_home: false
- args: |
cat << EOF > config.toml
changelog-seen = 2
Expand All @@ -57,7 +65,7 @@ tools:
targets = "X86"
[build]
target = ["x86_64-unknown-managarm-system"]
target = ["x86_64-unknown-managarm-system", "x86_64-unknown-linux-gnu"]
docs = false
[install]
Expand All @@ -76,6 +84,21 @@ tools:
install:
- args: ['@THIS_SOURCE_DIR@/x.py', 'install', '-j', '@PARALLELISM@']

- name: host-cargo
source:
subdir: 'ports'
git: 'https://github.com/rust-lang/cargo.git'
tag: '0.53.0'
version: '0.53.0'
tools_required:
- host-rust
sources_required:
- rust-libc
- host-bootstrap-cargo # Cargo requires cargo to build, so we download a binary that we can use temporarily
compile:
- args: ['@THIS_SOURCE_DIR@/../host-bootstrap-cargo/cargo/bin/cargo', 'install', '--target', 'x86_64-unknown-linux-gnu',
'--target-dir', '@THIS_BUILD_DIR@', '--path', '@THIS_SOURCE_DIR@', '-j@PARALLELISM@', '--root', '@PREFIX@']

packages:
- name: nasm
source:
Expand Down
16 changes: 16 additions & 0 deletions bootstrap.d/sys-apps.yml
Expand Up @@ -217,6 +217,22 @@ packages:
environ:
DESTDIR: '@THIS_COLLECT_DIR@'

- name: ripgrep
source:
subdir: ports
git: 'https://github.com/BurntSushi/ripgrep.git'
tag: '12.1.1'
version: '12.1.1'
tools_required:
- host-cargo
sources_required:
- rust-libc
- rust-num-cpus
configure:
- args: ['cargo', 'update', '--manifest-path', '@THIS_SOURCE_DIR@/Cargo.toml', '-p', 'libc', '--precise', '0.2.93']
build:
- args: ['cargo', 'install', '--locked', '--target-dir', '@THIS_BUILD_DIR@', '--path', '@THIS_SOURCE_DIR@', '--root', '@THIS_COLLECT_DIR@', '-j@PARALLELISM@']

- name: groff
source:
subdir: ports
Expand Down
7 changes: 7 additions & 0 deletions bootstrap.d/sys-libs.yml
@@ -1,3 +1,10 @@
sources:
- name: rust-num-cpus
subdir: 'ports'
git: 'https://github.com/seanmonstar/num_cpus.git'
tag: 'v1.13.0'
version: '1.13.0'

packages:
- name: gdbm
source:
Expand Down
13 changes: 13 additions & 0 deletions extrafiles/config.toml
@@ -0,0 +1,13 @@
[unstable]
patch-in-config = true

[build]
rustc = "@BUILD_ROOT@/tools/host-rust/bin/rustc"
target = "x86_64-unknown-managarm-system"

[target.x86_64-unknown-managarm-system]
linker = "@BUILD_ROOT@/tools/system-gcc/bin/x86_64-managarm-gcc"

[patch.crates-io]
libc = { path = "@SRC_ROOT@/ports/rust-libc" }
num_cpus = { path = "@SRC_ROOT@/ports/rust-num-cpus" }
8 changes: 4 additions & 4 deletions patches/rust-libc/0001-managarm-initial-port.patch
@@ -1,7 +1,7 @@
From f5c66b35e9082f36d8b3647e1de996cf11d0e997 Mon Sep 17 00:00:00 2001
From 6946817a03e47b6f14449041f29670c344ac4e5f Mon Sep 17 00:00:00 2001
From: Matt Taylor <mstaveleytaylor@gmail.com>
Date: Thu, 8 Apr 2021 22:08:55 +0100
Subject: [PATCH] managarm: initial port
Subject: [PATCH 1/2] managarm: initial port

---
src/unix/mlibc/mod.rs | 547 ++++++++++++++++++++++++++++++++++++++++++
Expand All @@ -11,7 +11,7 @@ Subject: [PATCH] managarm: initial port

diff --git a/src/unix/mlibc/mod.rs b/src/unix/mlibc/mod.rs
new file mode 100644
index 000000000..51b9ee91d
index 0000000..51b9ee9
--- /dev/null
+++ b/src/unix/mlibc/mod.rs
@@ -0,0 +1,547 @@
Expand Down Expand Up @@ -563,7 +563,7 @@ index 000000000..51b9ee91d
+ pub fn writev(fd: ::c_int, iov: *const ::iovec, count: ::c_int) -> ::ssize_t;
+}
diff --git a/src/unix/mod.rs b/src/unix/mod.rs
index be7b6e73e..b7c67bb39 100644
index be7b6e7..b7c67bb 100644
--- a/src/unix/mod.rs
+++ b/src/unix/mod.rs
@@ -1459,6 +1459,9 @@ cfg_if! {
Expand Down
@@ -0,0 +1,53 @@
From 048651aee5a4d29f174c27446abc546fab2f250c Mon Sep 17 00:00:00 2001
From: Matt Taylor <mstaveleytaylor@gmail.com>
Date: Sat, 8 May 2021 19:33:53 +0100
Subject: [PATCH 2/2] managarm: Add missing glue for memmap and num_cpus

---
src/unix/mlibc/mod.rs | 16 ++++++++++++++++
1 file changed, 16 insertions(+)

diff --git a/src/unix/mlibc/mod.rs b/src/unix/mlibc/mod.rs
index 51b9ee9..28dc0f0 100644
--- a/src/unix/mlibc/mod.rs
+++ b/src/unix/mlibc/mod.rs
@@ -19,6 +19,19 @@ pub type socklen_t = ::c_ulong;
// options/internal/include/bits/off_t.h
pub type off_t = ::c_long;

+// abis/mlibc/vm-flags.h
+pub const MAP_ANON: ::c_int = 8;
+pub const MAP_PRIVATE: ::c_int = 1;
+pub const MAP_SHARED: ::c_int = 2;
+pub const PROT_EXEC: ::c_int = 4;
+pub const PROT_READ: ::c_int = 1;
+pub const PROT_WRITE: ::c_int = 2;
+
+// options/posix/include/sys/mman.h
+pub const MAP_FAILED: *mut ::c_void = usize::MAX as *mut ::c_void;
+pub const MS_ASYNC: ::c_int = 1;
+pub const MS_SYNC: ::c_int = 2;
+
// options/ansi/include/time.h
pub const CLOCK_MONOTONIC: clockid_t = 1;
pub const CLOCK_REALTIME: clockid_t = 0;
@@ -151,6 +164,7 @@ pub const STDERR_FILENO: ::c_int = 2;
pub const STDIN_FILENO: ::c_int = 0;
pub const STDOUT_FILENO: ::c_int = 1;
pub const _SC_GETPW_R_SIZE_MAX: ::c_int = 1;
+pub const _SC_NPROCESSORS_ONLN: ::c_int = 6;
pub const _SC_PAGESIZE: ::c_int = _SC_PAGE_SIZE;
pub const _SC_PAGE_SIZE: ::c_int = 3;

@@ -521,6 +535,8 @@ extern "C" {
result: *mut *mut passwd,
) -> ::c_int;
pub fn ioctl(fd: ::c_int, request: ::c_ulong, ...) -> ::c_int;
+ pub fn mprotect(addr: *mut ::c_void, len: ::size_t, prot: ::c_int) -> ::c_int;
+ pub fn msync(addr: *mut ::c_void, len: ::size_t, flags: ::c_int) -> ::c_int;
pub fn pthread_condattr_setclock(
attr: *mut pthread_condattr_t,
clock_id: ::clockid_t,
--
2.31.1

38 changes: 38 additions & 0 deletions patches/rust-num-cpus/0001-managarm-Initial-port.patch
@@ -0,0 +1,38 @@
From 4b2069349810204ec0cd3e2d8c7fef3e71833d06 Mon Sep 17 00:00:00 2001
From: Matt Taylor <mstaveleytaylor@gmail.com>
Date: Fri, 7 May 2021 19:16:06 +0100
Subject: [PATCH] managarm: Initial port

---
src/lib.rs | 8 ++++++++
1 file changed, 8 insertions(+)

diff --git a/src/lib.rs b/src/lib.rs
index 6c8280f..d911c49 100644
--- a/src/lib.rs
+++ b/src/lib.rs
@@ -254,6 +254,13 @@ fn get_num_cpus() -> usize {
cpus as usize
}

+#[cfg(target_os = "managarm")]
+fn get_num_cpus() -> usize {
+ unsafe {
+ libc::sysconf(libc::_SC_NPROCESSORS_ONLN) as usize
+ }
+}
+
#[cfg(target_os = "openbsd")]
fn get_num_cpus() -> usize {
use std::ptr;
@@ -420,6 +427,7 @@ fn get_num_cpus() -> usize {
target_os = "netbsd",
target_os = "haiku",
target_os = "hermit",
+ target_os = "managarm",
windows,
)))]
fn get_num_cpus() -> usize {
--
2.31.1

0 comments on commit 421a895

Please sign in to comment.