Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Py #13

Merged
merged 11 commits into from
Jul 30, 2024
Merged

Py #13

Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
169 changes: 169 additions & 0 deletions .github/workflows/CI.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,169 @@
# This file is autogenerated by maturin v1.7.0
# To update, run
#
# maturin generate-ci github
#
name: CI

on:
push:
branches:
- main
- master
tags:
- '*'
pull_request:
workflow_dispatch:

permissions:
contents: read

jobs:
linux:
runs-on: ${{ matrix.platform.runner }}
strategy:
matrix:
platform:
- runner: ubuntu-latest
target: x86_64
- runner: ubuntu-latest
target: x86
- runner: ubuntu-latest
target: aarch64
- runner: ubuntu-latest
target: armv7
- runner: ubuntu-latest
target: s390x
- runner: ubuntu-latest
target: ppc64le
steps:
- uses: actions/checkout@v4
- uses: actions/setup-python@v5
with:
python-version: 3.x
- name: Build wheels
uses: PyO3/maturin-action@v1
with:
target: ${{ matrix.platform.target }}
args: --release --out dist --find-interpreter
sccache: 'true'
manylinux: auto
- name: Upload wheels
uses: actions/upload-artifact@v4
with:
name: wheels-linux-${{ matrix.platform.target }}
path: dist

musllinux:
runs-on: ${{ matrix.platform.runner }}
strategy:
matrix:
platform:
- runner: ubuntu-latest
target: x86_64
- runner: ubuntu-latest
target: x86
- runner: ubuntu-latest
target: aarch64
- runner: ubuntu-latest
target: armv7
steps:
- uses: actions/checkout@v4
- uses: actions/setup-python@v5
with:
python-version: 3.x
- name: Build wheels
uses: PyO3/maturin-action@v1
with:
target: ${{ matrix.platform.target }}
args: --release --out dist --find-interpreter
sccache: 'true'
manylinux: musllinux_1_2
- name: Upload wheels
uses: actions/upload-artifact@v4
with:
name: wheels-musllinux-${{ matrix.platform.target }}
path: dist

windows:
runs-on: ${{ matrix.platform.runner }}
strategy:
matrix:
platform:
- runner: windows-latest
target: x64
- runner: windows-latest
target: x86
steps:
- uses: actions/checkout@v4
- uses: actions/setup-python@v5
with:
python-version: 3.x
architecture: ${{ matrix.platform.target }}
- name: Build wheels
uses: PyO3/maturin-action@v1
with:
target: ${{ matrix.platform.target }}
args: --release --out dist --find-interpreter
sccache: 'true'
- name: Upload wheels
uses: actions/upload-artifact@v4
with:
name: wheels-windows-${{ matrix.platform.target }}
path: dist

macos:
runs-on: ${{ matrix.platform.runner }}
strategy:
matrix:
platform:
- runner: macos-12
target: x86_64
- runner: macos-14
target: aarch64
steps:
- uses: actions/checkout@v4
- uses: actions/setup-python@v5
with:
python-version: 3.x
- name: Build wheels
uses: PyO3/maturin-action@v1
with:
target: ${{ matrix.platform.target }}
args: --release --out dist --find-interpreter
sccache: 'true'
- name: Upload wheels
uses: actions/upload-artifact@v4
with:
name: wheels-macos-${{ matrix.platform.target }}
path: dist

sdist:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- name: Build sdist
uses: PyO3/maturin-action@v1
with:
command: sdist
args: --out dist
- name: Upload sdist
uses: actions/upload-artifact@v4
with:
name: wheels-sdist
path: dist

release:
name: Release
runs-on: ubuntu-latest
if: "startsWith(github.ref, 'refs/tags/')"
needs: [linux, musllinux, windows, macos, sdist]
steps:
- uses: actions/download-artifact@v4
- name: Publish to PyPI
uses: PyO3/maturin-action@v1
env:
MATURIN_PYPI_TOKEN: ${{ secrets.PYPI_API_TOKEN }}
with:
command: upload
args: --non-interactive --skip-existing wheels-*/*
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -15,3 +15,5 @@ Cargo.lock
.idea
.vscode
*.exe
.cargo
venv
33 changes: 7 additions & 26 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -3,30 +3,11 @@ name = "river"
version = "0.1.0"
edition = "2021"

[dependencies]
libc = "0.2.153"
clap = { version = "4.5.1", features = ["derive"] }
clap-verbosity-flag = "2.2.0"
log = "0.4.20"
env_logger = "0.10.2"
tempfile = "3.10.0"
serde = { version = "1.0.197", features = ["derive"] }
serde_json = "1.0.114"
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
[lib]
name = "river"
crate-type = ["cdylib"]

[target.'cfg(windows)'.dependencies.windows]
version = "0.53.0"
features = [
"Win32_Storage",
"Win32_Storage_FileSystem",
"Win32_System_Ioctl",
"Win32_System_IO",
"Win32_Foundation",
"Win32_Security",
"Win32_System_JobObjects",
"Win32_System_Threading",
"Win32_UI_WindowsAndMessaging",
"Win32_System_Diagnostics",
"Win32_System_Diagnostics_Debug",
"Win32_System_ProcessStatus",
"Win32_System_WindowsProgramming"
]
[dependencies]
pyo3 = "0.22.0"
libc = "0.2.155"
83 changes: 0 additions & 83 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,84 +1 @@
# river

## 用法

```bash
$ river -h
example: `river -vvv -- /usr/bin/echo hello world`

Usage: river.exe [OPTIONS] -- <COMMAND>...

Arguments:
<COMMAND>... Program to run and command line arguments

Options:
-i, --input <INPUT>
Input stream. The default value is STDIN(0)
-o, --output <OUTPUT>
Output stream. The default value is STDOUT(1)
-e, --error <ERROR>
Error stream. The default value is STDERR(2)
-r, --result <RESULT>
Output location of the running result. The default value is STDOUT(1)
-t, --time-limit <TIME_LIMIT>
Time limit, in ms. The default value is unlimited
-c, --cpu-time-limit <CPU_TIME_LIMIT>
CPU Time limit, in ms. The default value is unlimited
-m, --memory-limit <MEMORY_LIMIT>
Memory limit, in kib. The default value is unlimited
-v, --verbose...
Increase logging verbosity
-q, --quiet...
Decrease logging verbosity
-h, --help
Print help
-V, --version
Print version
```

## 结果

结果的格式为 JSON

| 字段 | 含义 |
|-----------------|--------------------|
| `time_used` | 程序运行用时 |
| `cpu_time_used` | 程序运行使用 CPU 时间 |
| `memory_used` | 程序运行使用内存 |
| `exit_code` | 程序退出 code,正常情况下为 0 |
| `status` | 正常情况下为 0 |
| `signal` | 正常情况下为 0 |

## 系统支持

`~` 代表开发中的功能

| 特性 | Linux | Windows | macOS |
|-------------|-------|---------|-------|
| 执行指定命令 | ~ | √ | ~ |
| 流重定向 | ~ | √ | ~ |
| 运行时间统计 | ~ | √ | ~ |
| 运行 CPU 时间统计 | ~ | √ | ~ |
| 运行内存统计 | ~ | √ | ~ |
| 运行时间限制 | ~ | √ | ~ |
| 运行 CPU 时间限制 | ~ | ~ | ~ |
| 运行内存限制 | ~ | ~ | ~ |
| 获取进程退出状态 | ~ | ~ | ~ |
| 切换工作空间 | ~ | ~ | ~ |
| 传递环境变量 | ~ | ~ | ~ |
| 网络限制 | ~ | ~ | ~ |
| 写入文件大小限制 | ~ | ~ | ~ |
| 进程/线程数量限制 | ~ | ~ | ~ |
| 危险系统调用限制 | ~ | ~ | ~ |
| 执行用户权限限制 | ~ | ~ | ~ |
| 平滑退出 | ~ | ~ | ~ |

**注意:** Windows 平台下运行 CPU 时间限制与运行内存限制不能保证精确,请不要以此为基准进行判断。

## 测试

```bash
cargo test -- --test-threads=1
```

测试涉及文件操作,建议顺序执行测试用例(并发限制为 1)
15 changes: 15 additions & 0 deletions pyproject.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
[build-system]
requires = ["maturin>=1.7,<2.0"]
build-backend = "maturin"

[project]
name = "river"
requires-python = ">=3.8"
classifiers = [
"Programming Language :: Rust",
"Programming Language :: Python :: Implementation :: CPython",
"Programming Language :: Python :: Implementation :: PyPy",
]
dynamic = ["version"]
[tool.maturin]
features = ["pyo3/extension-module"]
27 changes: 27 additions & 0 deletions resources/runit.s
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
.text
.globl main
main:
endbr64
pushq %rbp
movq %rsp, %rbp
subq $48, %rsp
movl %edi, -20(%rbp)
movq %rsi, -32(%rbp)
movq %rdx, -40(%rbp)
call fork@PLT
movl %eax, -4(%rbp)
cmpl $0, -4(%rbp)
jne .L2
movq -32(%rbp), %rax
leaq 8(%rax), %rcx
movq -32(%rbp), %rax
addq $8, %rax
movq (%rax), %rax
movq -40(%rbp), %rdx
movq %rcx, %rsi
movq %rax, %rdi
call execve@PLT
.L2:
movl $0, %eax
leave
ret
45 changes: 0 additions & 45 deletions src/error.rs

This file was deleted.

Loading