Skip to content

Commit 8680ba0

Browse files
committed
Merge P2-01 core source library
2 parents 65e5e53 + 6c5e9b4 commit 8680ba0

32 files changed

Lines changed: 1054 additions & 99 deletions
Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
1+
name: P2 core source consumers
2+
3+
on:
4+
push:
5+
branches: [master]
6+
pull_request:
7+
workflow_dispatch:
8+
9+
permissions:
10+
contents: read
11+
12+
jobs:
13+
consumer:
14+
name: Core source consumer (${{ matrix.rid }})
15+
strategy:
16+
fail-fast: false
17+
matrix:
18+
include:
19+
- os: windows-2025
20+
rid: win-x64
21+
- os: ubuntu-24.04
22+
rid: linux-x64
23+
runs-on: ${{ matrix.os }}
24+
timeout-minutes: 15
25+
steps:
26+
- uses: actions/checkout@v4
27+
- uses: actions/setup-dotnet@v4
28+
with:
29+
global-json-file: global.json
30+
- if: matrix.rid == 'linux-x64'
31+
run: sudo apt-get install --no-install-recommends -y clang zlib1g-dev
32+
- run: dotnet build RustSharp.slnx -c Release
33+
- run: dotnet tool restore --tool-manifest .config/dotnet-tools.json
34+
- name: Run generated consumer regression tests
35+
run: dotnet run --project tests/RustSharp.Tests -c Release --no-build --no-restore -- --filter 'core-v1 generated' --timeout 60 --deadline 120
36+
- name: Compile and execute the Native AOT consumer
37+
env:
38+
RUSTSHARP_NATIVE_AOT_SDK_VERSION: 10.0.404
39+
run: dotnet src/RustSharp.Cli/bin/Release/net10.0/rsc.dll test library/core/Cargo.toml --runtime ${{ matrix.rid }} --output artifacts/p2-core-source/${{ matrix.rid }} --timeout 360
40+
- name: Verify the original managed assembly
41+
shell: pwsh
42+
run: |
43+
$ErrorActionPreference = 'Stop'
44+
$framework = @(dotnet --list-runtimes | Select-String '^Microsoft\.NETCore\.App (10\.\d+\.\d+) \[(.+)\]$' |
45+
Sort-Object { [version]$_.Matches[0].Groups[1].Value } -Descending | Select-Object -First 1)
46+
if ($LASTEXITCODE -ne 0 -or $framework.Count -ne 1) { throw 'A .NET 10 reference runtime is required.' }
47+
$reference = Join-Path $framework[0].Matches[0].Groups[2].Value $framework[0].Matches[0].Groups[1].Value
48+
$output = 'artifacts/p2-core-source/${{ matrix.rid }}'
49+
./eng/Invoke-ILVerify.ps1 -AssemblyPath "$output/core.dll" -ReferenceDirectory $reference -EvidencePath "$output/core.ilverify.json"
50+
- if: always()
51+
uses: actions/upload-artifact@v4
52+
with:
53+
name: p2-core-source-${{ matrix.rid }}-${{ github.sha }}
54+
path: artifacts/p2-core-source/${{ matrix.rid }}/

‎README.md‎

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -62,11 +62,19 @@ rsc check <source.rs|Cargo.toml> [--profile <name>]
6262
rsc build <source.rs|Cargo.toml> [--output <program.dll>] [--profile <name>]
6363
rsc compile <source.rs|Cargo.toml> [--output <program.dll>] [--profile <name>]
6464
rsc run <source.rs|Cargo.toml> [--output <program.dll>] [--timeout <seconds>] [--profile <name>]
65+
rsc test <Cargo.toml> [--runtime <rid>] [--output <directory>] [--timeout <seconds>]
6566
rsc publish <source.rs|Cargo.toml> [--runtime <rid>] [--output <directory>] [--timeout <seconds>] [--profile <name>]
6667
```
6768

6869
`compile` is retained as a compatibility alias for `build`.
6970

71+
Run `rsc test library/core/Cargo.toml` to compile and execute the core package's
72+
integration consumer under `safe-core-generics-core-v1`. The command uses explicit
73+
`[[test]]` targets with `name`, `path`, and `harness = false`. Each target has a
74+
`fn main()` entry point and a neighboring `.stdout` file checked against its output.
75+
Pass `--runtime win-x64` or `--runtime linux-x64` on the matching x64 host to
76+
publish and execute the Native AOT test binary against the same expected output.
77+
7078
Use `rsc check samples/type-system.rs --profile safe-core-types-v1` for the
7179
type-system sample. This profile accepts `check`; executable commands report
7280
`RSC0009` before creating output. See the [type-system contract](docs/type-system-profile.md)

‎README_zh.md‎

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -62,11 +62,19 @@ rsc check <source.rs|Cargo.toml> [--profile <name>]
6262
rsc build <source.rs|Cargo.toml> [--output <program.dll>] [--profile <name>]
6363
rsc compile <source.rs|Cargo.toml> [--output <program.dll>] [--profile <name>]
6464
rsc run <source.rs|Cargo.toml> [--output <program.dll>] [--timeout <seconds>] [--profile <name>]
65+
rsc test <Cargo.toml> [--runtime <rid>] [--output <directory>] [--timeout <seconds>]
6566
rsc publish <source.rs|Cargo.toml> [--runtime <rid>] [--output <directory>] [--timeout <seconds>] [--profile <name>]
6667
```
6768

6869
`compile` 保留为 `build` 的兼容别名。
6970

71+
运行 `rsc test library/core/Cargo.toml`,使用 `safe-core-generics-core-v1` 编译并执行
72+
core 包的集成消费者。命令使用显式声明的 `[[test]]` 目标,要求提供 `name`、`path` 和
73+
`harness = false`。每个目标使用 `fn main()` 作为入口,并对照同目录、同文件名主干的
74+
`.stdout` 文件检查输出。
75+
在对应的 x64 主机上使用 `--runtime win-x64` 或 `--runtime linux-x64`,可以发布并执行
76+
Native AOT 测试程序,使用相同的预期输出检查结果。
77+
7078
使用 `rsc check samples/type-system.rs --profile safe-core-types-v1` 检查类型系统示例。
7179
该配置档接受 `check`;可执行命令会在创建输出前报告 `RSC0009`。
7280
配置档范围及独立的生命周期/借用检查边界见[类型系统契约](docs/type-system-profile.md)。

‎docs/roadmap/P2.md‎

Lines changed: 13 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -40,14 +40,22 @@ VS Code, CLI, and application platform gates cover Windows and Linux x64.
4040

4141
Parent hard dependency: `P1-GATE`.
4242

43+
The executable consumer at `rsc test library/core/Cargo.toml` exercises generic
44+
`Option` and heterogeneous `Result` associated functions and matching, bounded
45+
scalar output and comparison, and empty and once iterator state. Its regressions
46+
check linked crate and specialization metadata, source diagnostics, and mismatched
47+
output. The consumer runs on CoreCLR and with `--runtime win-x64` or
48+
`--runtime linux-x64` on the matching host. The [candidate workflow](../../.github/workflows/p2-core-source.yml)
49+
runs the consumer on both platforms and verifies each original managed assembly.
50+
4351
| ID | Status | Deliverable / ownership | Depends on | Done when | Evidence |
4452
| --- | --- | --- | --- | --- | --- |
4553
| P2-01.01 | 🚧 In progress | Freeze `core-v1` API/signature, trait, and case manifest; `library/core/`, conformance manifests. | P1-GATE | All seven parent families have named members, positive/error/boundary cases, and a fixed denominator; unknown members are classified. | `test:core-manifest`; [contract evidence](../evidence/p2/P2-01.01.json). The contract evidence validates the 42-case inventory, 28-member surface, seven families, six bounded targets and `runtimeEvidence=false`. Formal closure awaits P1-GATE. |
46-
| P2-01.02 | 🚧 In progress | Primitive operations and managed-hybrid `Option`/`Result`; `RustSharp.Runtime.Core`. | P2-01.01 | Runtime constructors, matching, combinators, and error propagation pass 12/12 CoreCLR tests and Windows/Linux x64 Native AOT smoke consumers; Rust# generic enum/front-end integration remains open. | [Runtime evidence](../evidence/p2/P2-01.runtime.json); generated Rust# consumer and diagnostic matrix remain open. |
47-
| P2-01.03 | 🚧 In progress | Formatting and display/debug adapters; `RustSharp.Runtime.Core`. | P2-01.01 | Runtime display/debug, UTF-8 and budget cases pass 6/6 on CoreCLR and Windows/Linux x64 Native AOT; Rust# formatting trait integration remains open. | [Runtime evidence](../evidence/p2/P2-01.runtime.json); language-level format consumer remains open. |
48-
| P2-01.04 | 🚧 In progress | Comparison and hashing contracts; `RustSharp.Runtime.Core`. | P2-01.02 | Runtime equality/order/float partial comparison and stable hashing pass 6/6 on CoreCLR and Windows/Linux x64 Native AOT; Rust# trait lowering remains open. | [Runtime evidence](../evidence/p2/P2-01.runtime.json); language-level comparison/hash consumer remains open. |
49-
| P2-01.05 | 🚧 In progress | Iterator foundations and adapters; `RustSharp.Runtime.Core`. | P2-01.02 | Runtime empty/once/map/order/laziness cases pass 6/6 on CoreCLR and Windows/Linux x64 Native AOT; Rust# iterator ownership lowering remains open. | [Runtime evidence](../evidence/p2/P2-01.runtime.json); language-level iterator consumer remains open. |
50-
| P2-01.06 | 🚧 In progress | Export inventory and compiled library consumers; runtime consumer harness. | P2-01.03, P2-01.04, P2-01.05 | Two composed runtime consumers pass CoreCLR and Windows/Linux x64 Native AOT smoke runs; generated Rust# export inventory, ILVerify binding and invalid consumer diagnostics remain open. | [Runtime evidence](../evidence/p2/P2-01.runtime.json). |
54+
| P2-01.02 | 🚧 In progress | Primitive operations and managed-hybrid `Option`/`Result`; `RustSharp.Runtime.Core`. | P2-01.01 | Source-linked `Option<T>` and `Result<T, E>` support construction, predicates, fallback and pattern matching. Static associated functions support inferred and explicit type arguments. Primitive coverage, receiver methods, `map` and `?` remain open. | [Runtime evidence](../evidence/p2/P2-01.runtime.json) · `rsc test library/core/Cargo.toml` |
55+
| P2-01.03 | 🚧 In progress | Formatting and display/debug adapters; `RustSharp.Runtime.Core`. | P2-01.01 | The source consumer exercises `i32` display and `bool` debug output. The full formatting trait and adapter surface remains open. | [Runtime evidence](../evidence/p2/P2-01.runtime.json) · `rsc test library/core/Cargo.toml` |
56+
| P2-01.04 | 🚧 In progress | Comparison and hashing contracts; `RustSharp.Runtime.Core`. | P2-01.02 | The source consumer exercises `i32` equality and ordering. Language-level comparison traits and hashing remain open. | [Runtime evidence](../evidence/p2/P2-01.runtime.json) · `rsc test library/core/Cargo.toml` |
57+
| P2-01.05 | 🚧 In progress | Iterator foundations and adapters; `RustSharp.Runtime.Core`. | P2-01.02 | The source consumer exercises `empty`, `once` and explicit iterator state. Iterator traits, `map` and ownership lowering remain open. | [Runtime evidence](../evidence/p2/P2-01.runtime.json) · `rsc test library/core/Cargo.toml` |
58+
| P2-01.06 | 🚧 In progress | Export inventory and compiled library consumers; runtime consumer harness. | P2-01.03, P2-01.04, P2-01.05 | A Rust# consumer runs through the Cargo integration-test command on CoreCLR and locally on both x64 Native AOT platforms. The original PE has an ILVerify check and linked-source inventory assertions. Full public export inventory, the full invalid-consumer matrix, and pinned-SDK candidate evidence remain open. | [Runtime evidence](../evidence/p2/P2-01.runtime.json) · `rsc test library/core/Cargo.toml` |
5159

5260
<a id="p2-02"></a>
5361
## P2-02 — Managed-hybrid alloc library

‎docs/roadmap/P2_zh.md‎

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -31,14 +31,20 @@ VS Code、CLI 和应用平台门槛覆盖 Windows 与 Linux x64。
3131

3232
父任务硬依赖:`P1-GATE`。
3333

34+
可通过 `rsc test library/core/Cargo.toml` 运行生成的消费者。它覆盖泛型 `Option` 和
35+
异构 `Result` 的关联函数与匹配、有界的标量输出与比较,以及空迭代器与单元素迭代器
36+
的状态。回归检查源码包链接与特化元数据、源码诊断和不匹配的输出。消费者可在 CoreCLR
37+
上运行,也可在对应主机上使用 `--runtime win-x64` 或 `--runtime linux-x64`。
38+
[候选验证工作流](../../.github/workflows/p2-core-source.yml)在两个平台运行消费者并验证各自的原始托管程序集。
39+
3440
| ID | 状态 | 交付物 / 所有权 | 依赖 | 完成条件 | 证据 |
3541
| --- | --- | --- | --- | --- | --- |
3642
| P2-01.01 | 🚧 进行中 | 冻结 `core-v1` API/签名、trait 与用例清单;`library/core/`、一致性清单。 | P1-GATE | 父任务全部七个功能族都有具名成员、正向/错误/边界用例及固定分母;未知成员已分类。 | `test:core-manifest`;[契约证据](../evidence/p2/P2-01.01.json)验证了 42 个固定用例、28 个成员、七个家族、六个有界目标和 `runtimeEvidence=false`。正式结项需等待 P1-GATE。 |
37-
| P2-01.02 | 🚧 进行中 | 原语操作及托管混合 `Option`/`Result`;`RustSharp.Runtime.Core`。 | P2-01.01 | 运行时构造、匹配、组合器和错误传播通过 CoreCLR 12/12 及 Windows/Linux x64 Native AOT 冒烟消费者;Rust# 泛型枚举/前端集成仍开放。 | [运行时证据](../evidence/p2/P2-01.runtime.json);生成 Rust# 消费者与诊断矩阵仍开放。 |
38-
| P2-01.03 | 🚧 进行中 | 格式化及 display/debug 适配器;`RustSharp.Runtime.Core`。 | P2-01.01 | 运行时 display/debug、UTF-8 和预算用例在 CoreCLR 及 Windows/Linux x64 Native AOT 通过 6/6;Rust# 格式化 trait 集成仍开放。 | [运行时证据](../evidence/p2/P2-01.runtime.json);语言级格式化消费者仍开放。 |
39-
| P2-01.04 | 🚧 进行中 | 比较与哈希契约;`RustSharp.Runtime.Core`。 | P2-01.02 | 运行时相等/排序/浮点部分比较和稳定哈希在 CoreCLR 及 Windows/Linux x64 Native AOT 通过 6/6;Rust# trait 降低仍开放。 | [运行时证据](../evidence/p2/P2-01.runtime.json);语言级比较/哈希消费者仍开放。 |
40-
| P2-01.05 | 🚧 进行中 | 迭代器基础和适配器;`RustSharp.Runtime.Core`。 | P2-01.02 | 运行时空/once/map/顺序/惰性用例在 CoreCLR 及 Windows/Linux x64 Native AOT 通过 6/6;Rust# 迭代器所有权降低仍开放。 | [运行时证据](../evidence/p2/P2-01.runtime.json);语言级迭代器消费者仍开放。 |
41-
| P2-01.06 | 🚧 进行中 | 导出清单及编译库消费者;运行时消费者夹具。 | P2-01.03, P2-01.04, P2-01.05 | 两个组合运行时消费者通过 CoreCLR 及 Windows/Linux x64 Native AOT 冒烟运行;生成 Rust# 导出清单、ILVerify 绑定和无效消费者诊断仍开放。 | [运行时证据](../evidence/p2/P2-01.runtime.json)。 |
43+
| P2-01.02 | 🚧 进行中 | 原语操作及托管混合 `Option`/`Result`;`RustSharp.Runtime.Core`。 | P2-01.01 | 源码链接的 `Option<T>` 和 `Result<T, E>` 支持构造、判定、回退与模式匹配。静态关联函数支持推断与显式类型参数。原语覆盖、带接收者的方法、`map` 和 `?` 仍待完成。 | [运行时证据](../evidence/p2/P2-01.runtime.json) · `rsc test library/core/Cargo.toml` |
44+
| P2-01.03 | 🚧 进行中 | 格式化及 display/debug 适配器;`RustSharp.Runtime.Core`。 | P2-01.01 | 源码消费者覆盖 `i32` 的 display 输出和 `bool` 的 debug 输出。完整的格式化 trait 与适配器仍待完成。 | [运行时证据](../evidence/p2/P2-01.runtime.json) · `rsc test library/core/Cargo.toml` |
45+
| P2-01.04 | 🚧 进行中 | 比较与哈希契约;`RustSharp.Runtime.Core`。 | P2-01.02 | 源码消费者覆盖 `i32` 的相等和排序。语言级比较 trait 和哈希仍待完成。 | [运行时证据](../evidence/p2/P2-01.runtime.json) · `rsc test library/core/Cargo.toml` |
46+
| P2-01.05 | 🚧 进行中 | 迭代器基础和适配器;`RustSharp.Runtime.Core`。 | P2-01.02 | 源码消费者覆盖 `empty`、`once` 和显式迭代器状态。迭代器 trait、`map` 与所有权降低仍待完成。 | [运行时证据](../evidence/p2/P2-01.runtime.json) · `rsc test library/core/Cargo.toml` |
47+
| P2-01.06 | 🚧 进行中 | 导出清单及编译库消费者;运行时消费者夹具。 | P2-01.03, P2-01.04, P2-01.05 | Rust# 消费者通过 Cargo 集成测试命令在 CoreCLR 和本地两个 x64 Native AOT 平台运行。原始 PE 已接入 ILVerify 和源码链接清单断言。完整的公开导出清单、无效消费者矩阵和锁定 SDK 的候选证据仍待完成。 | [运行时证据](../evidence/p2/P2-01.runtime.json) · `rsc test library/core/Cargo.toml` |
4248

4349
<a id="p2-02"></a>
4450
## P2-02 — 托管混合 alloc 库

‎library/core/Cargo.toml‎

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
[package]
2+
name = "core"
3+
version = "0.1.0"
4+
edition = "2024"
5+
6+
[[test]]
7+
name = "core"
8+
path = "tests/core.rs"
9+
harness = false

‎library/core/src/cmp.rs‎

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
pub enum Ordering {
2+
Less,
3+
Equal,
4+
Greater,
5+
}
6+
7+
pub fn eq_i32(left: i32, right: i32) -> bool {
8+
left == right
9+
}
10+
11+
pub fn cmp_i32(left: i32, right: i32) -> Ordering {
12+
if left < right {
13+
Ordering::Less
14+
} else if left > right {
15+
Ordering::Greater
16+
} else {
17+
Ordering::Equal
18+
}
19+
}

‎library/core/src/fmt.rs‎

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
/// Writes one signed decimal integer followed by a newline.
2+
pub fn write(value: i32) {
3+
println!("{}", value);
4+
}
5+
6+
/// Writes the debug spelling of a boolean followed by a newline.
7+
pub fn write_debug(value: bool) {
8+
println!("{:?}", value);
9+
}

‎library/core/src/iter.rs‎

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
use crate::option::Option;
2+
3+
/// A source-level iterator with at most one item.
4+
pub struct Once<T> {
5+
item: Option<T>,
6+
}
7+
8+
pub fn empty<T>() -> Once<T> {
9+
Once { item: Option::None }
10+
}
11+
12+
pub fn once<T>(item: T) -> Once<T> {
13+
Once { item: Option::Some(item) }
14+
}
15+
16+
/// Consumes the current iterator and returns its item and exhausted state.
17+
pub fn next<T>(iterator: Once<T>) -> (Option<T>, Once<T>) {
18+
(iterator.item, empty::<T>())
19+
}

‎library/core/src/lib.rs‎

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
pub mod cmp;
2+
pub mod fmt;
3+
pub mod iter;
4+
pub mod option;
5+
pub mod result;

0 commit comments

Comments
 (0)