Skip to content

Commit 0bbfef3

Browse files
committed
ML-KEM: Restructure C Extraction
use common c.sh, symlink update documentation ci: update needs names in C workflow mlkem: drop c-nss extract scripts ci: update more needs names Revert "ci: update more needs names" This reverts commit b2d6f85. ci: update needs of mlkem c status, but correct this time fix C/C++ extraction add mlkem.cmake symlink, move around version header kill script files ci: clean the right directory
1 parent 0755df9 commit 0bbfef3

File tree

99 files changed

+282
-392
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

99 files changed

+282
-392
lines changed

.github/workflows/docker-c-build-test.yml

Lines changed: 25 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -40,54 +40,54 @@ jobs:
4040
tags: ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}:${{ env.VERSION_TAG }}
4141
outputs:
4242
image: ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}:${{ env.VERSION_TAG }}
43-
extract:
43+
extract-ml-kem-c-header-only:
4444
needs: [build-and-push-image]
4545
runs-on: ubuntu-latest
4646
container:
4747
image: ${{ needs.build-and-push-image.outputs.image }}
4848
defaults:
4949
run:
50-
working-directory: libcrux-ml-kem
50+
working-directory: libcrux-ml-kem/extracts/c_header_only
5151
shell: bash
5252
steps:
5353
- uses: actions/checkout@v5
5454

55-
- name: Extract C
55+
- name: Extract C (header only)
5656
run: |
5757
export HOME=/home/user
58-
./c.sh --config cg.yaml --mlkem768 --no-unrolling --out c --clean --no-glue
59-
- name: Upload C extraction
58+
./extract.sh
59+
- name: Upload header only C extraction
6060
uses: actions/upload-artifact@v4
6161
with:
62-
name: c-extraction
63-
path: libcrux-ml-kem/c
62+
name: extraction-ml-kem-c-header-only
63+
path: libcrux-ml-kem/extracts/c_header_only/generated
6464
include-hidden-files: true
6565
if-no-files-found: error
66-
extract-header-only-ml-kem:
66+
extract-ml-kem-cpp-header-only:
6767
needs: [build-and-push-image]
6868
runs-on: ubuntu-latest
6969
container:
7070
image: ${{ needs.build-and-push-image.outputs.image }}
7171
defaults:
7272
run:
73-
working-directory: libcrux-ml-kem
73+
working-directory: libcrux-ml-kem/extracts/cpp_header_only
7474
shell: bash
7575
steps:
7676
- uses: actions/checkout@v5
7777

78-
- name: Extract C (header only)
78+
- name: Extract C++ (header only)
7979
run: |
8080
export HOME=/home/user
81-
./boring.sh --no-clean
81+
./extract.sh --no-clean
8282
83-
- name: Upload header only C extraction
83+
- name: Upload header only C++ extraction
8484
uses: actions/upload-artifact@v4
8585
with:
86-
name: header-only-c-extraction-ml-kem
87-
path: libcrux-ml-kem/cg/
86+
name: extraction-ml-kem-cpp-header-only
87+
path: libcrux-ml-kem/extracts/cpp_header_only/generated
8888
include-hidden-files: true
8989
if-no-files-found: error
90-
extract-header-only-ml-dsa:
90+
extract-ml-dsa-header-only:
9191
needs: [build-and-push-image]
9292
runs-on: ubuntu-latest
9393
container:
@@ -107,12 +107,12 @@ jobs:
107107
- name: Upload header only C extraction
108108
uses: actions/upload-artifact@v4
109109
with:
110-
name: header-only-c-extraction-ml-dsa
110+
name: extraction-ml-dsa-header-only
111111
path: libcrux-ml-dsa/cg/
112112
include-hidden-files: true
113113
if-no-files-found: error
114-
test-build:
115-
needs: [extract]
114+
test-build-ml-kem-c-header-only:
115+
needs: [extract-ml-kem-c-header-only]
116116
strategy:
117117
fail-fast: false
118118
matrix:
@@ -128,7 +128,7 @@ jobs:
128128
steps:
129129
- uses: actions/download-artifact@v5
130130
with:
131-
name: c-extraction
131+
name: extraction-ml-kem-c-header-only
132132

133133
- name: 🔨 Build
134134
run: |
@@ -149,8 +149,8 @@ jobs:
149149
LIBCRUX_BENCHMARKS=1 cmake -B build -DCMAKE_BUILD_TYPE=Release
150150
cmake --build build --config Release
151151
if: ${{ matrix.os != 'windows-latest' }}
152-
test-build-header-only-ml-kem:
153-
needs: [extract-header-only-ml-kem]
152+
test-build-ml-kem-cpp-header-only:
153+
needs: [extract-ml-kem-cpp-header-only]
154154
strategy:
155155
fail-fast: false
156156
matrix:
@@ -165,7 +165,7 @@ jobs:
165165
steps:
166166
- uses: actions/download-artifact@v5
167167
with:
168-
name: header-only-c-extraction-ml-kem
168+
name: extraction-ml-kem-cpp-header-only
169169

170170
- name: 🔨 Build
171171
run: |
@@ -181,8 +181,8 @@ jobs:
181181
run: ./build/Debug/ml_kem_test
182182
if: ${{ matrix.os == 'windows-latest' }}
183183

184-
test-build-header-only-ml-dsa:
185-
needs: [extract-header-only-ml-dsa]
184+
test-build-ml-dsa-header-only:
185+
needs: [extract-ml-dsa-header-only]
186186
strategy:
187187
fail-fast: false
188188
matrix:
@@ -197,7 +197,7 @@ jobs:
197197
steps:
198198
- uses: actions/download-artifact@v5
199199
with:
200-
name: header-only-c-extraction-ml-dsa
200+
name: extraction-ml-dsa-header-only
201201

202202
- name: 🔨 Build
203203
run: |

.github/workflows/mlkem-c.yml

Lines changed: 39 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,8 @@ jobs:
3838
if: ${{ always() }}
3939
needs:
4040
- setup
41-
- extract
41+
- extract-c
42+
- extract-cpp
4243
- diff
4344
- build-c
4445
- build-cpp
@@ -51,47 +52,61 @@ jobs:
5152
if: ${{ (contains(needs.*.result, 'failure')) }}
5253
run: exit 1
5354

54-
extract:
55+
extract-c:
5556
needs: [setup]
5657
if: ${{ needs.setup.outputs.should-run == 'true' }}
5758
runs-on: ubuntu-latest
5859
container:
5960
image: ${{ needs.setup.outputs.image }}
6061
defaults:
6162
run:
62-
working-directory: libcrux-ml-kem
63+
working-directory: libcrux-ml-kem/extracts/c_header_only
6364
shell: bash
6465
steps:
6566
- uses: actions/checkout@v5
6667

67-
- name: Extract C++
68-
run: |
69-
export HOME=/home/user
70-
./boring.sh --no-clean
71-
7268
- name: Extract C
7369
run: |
7470
export HOME=/home/user
75-
./c.sh --config cg.yaml --mlkem768 --no-unrolling --out c --clean --no-glue
71+
./extract.sh
7672
77-
- name: Upload C++ extraction
73+
- name: Upload C extraction
7874
uses: actions/upload-artifact@v4
7975
with:
80-
name: cpp-extraction-ml-kem
81-
path: libcrux-ml-kem/cg/
76+
name: c-extraction-ml-kem
77+
path: libcrux-ml-kem/extracts/c_header_only/generated
8278
include-hidden-files: true
8379
if-no-files-found: error
8480

85-
- name: Upload C extraction
81+
extract-cpp:
82+
needs: [setup]
83+
if: ${{ needs.setup.outputs.should-run == 'true' }}
84+
runs-on: ubuntu-latest
85+
container:
86+
image: ${{ needs.setup.outputs.image }}
87+
defaults:
88+
run:
89+
working-directory: libcrux-ml-kem/extracts/cpp_header_only
90+
shell: bash
91+
steps:
92+
- uses: actions/checkout@v5
93+
94+
- name: Extract C++
95+
run: |
96+
export HOME=/home/user
97+
./extract.sh --no-clean
98+
99+
- name: Upload C++ extraction
86100
uses: actions/upload-artifact@v4
87101
with:
88-
name: c-extraction-ml-kem
89-
path: libcrux-ml-kem/c/
102+
name: cpp-extraction-ml-kem
103+
path: libcrux-ml-kem/extracts/cpp_header_only/generated
90104
include-hidden-files: true
91105
if-no-files-found: error
92106

107+
93108
diff:
94-
needs: [extract]
109+
needs: [extract-c, extract-cpp]
95110
runs-on: ubuntu-latest
96111
defaults:
97112
run:
@@ -110,18 +125,18 @@ jobs:
110125

111126
- name: Diff Extraction C++
112127
run: |
113-
libcrux-ml-kem/headers_kill_revs.sh libcrux-ml-kem/cg
114-
libcrux-ml-kem/headers_kill_revs.sh ~/mlkem-cpp-extraction
115-
diff -r libcrux-ml-kem/cg ~/mlkem-cpp-extraction
128+
libcrux-ml-kem/extracts/common/headers_kill_revs.sh libcrux-ml-kem/extracts/cpp_header_only/generated
129+
libcrux-ml-kem/extracts/common/headers_kill_revs.sh ~/mlkem-cpp-extraction
130+
diff -r libcrux-ml-kem/extracts/cpp_header_only/generated ~/mlkem-cpp-extraction
116131
117132
- name: Diff Extraction C
118133
run: |
119-
libcrux-ml-kem/headers_kill_revs.sh libcrux-ml-kem/c
120-
libcrux-ml-kem/headers_kill_revs.sh ~/mlkem-c-extraction
121-
diff -r libcrux-ml-kem/c ~/mlkem-c-extraction
134+
libcrux-ml-kem/extracts/common/headers_kill_revs.sh libcrux-ml-kem/extracts/c_header_only/generated
135+
libcrux-ml-kem/extracts/common/headers_kill_revs.sh ~/mlkem-c-extraction
136+
diff -r libcrux-ml-kem/extracts/c_header_only/generated ~/mlkem-c-extraction
122137
123138
build-c:
124-
needs: [extract]
139+
needs: [extract-c]
125140
strategy:
126141
fail-fast: false
127142
matrix:
@@ -158,7 +173,7 @@ jobs:
158173
if: ${{ matrix.os == 'windows-latest' }}
159174

160175
build-cpp:
161-
needs: [extract]
176+
needs: [extract-cpp]
162177
strategy:
163178
fail-fast: false
164179
matrix:

CONTRIBUTING.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@ Relative to the crate root, the structure we aim to use is:
4747
/extracts/
4848
/extracts/$name/extract.sh -- the script that extracts the code
4949
/extracts/$name/extract.yaml -- the eurydice config for the extraction
50-
/extracts/$name/out/ -- the extracted code
50+
/extracts/$name/generated/ -- the extracted code
5151
/extracts/$name/... -- per-extraction extra data
5252
```
5353

PUBLISHING.md

Lines changed: 0 additions & 9 deletions
This file was deleted.

RELEASE.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -99,3 +99,8 @@ later update these as well.
9999
### Running `cargo publish`
100100

101101
This pushes the crate to crates.io. Before running the full push, do a dry run.
102+
103+
### Tag the commit
104+
105+
Create and push a git tag named `${crate name}-v${version}` for all published
106+
crates.

libcrux-ml-kem/C-CODE.md

Lines changed: 21 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
# Extraction into C code
22

3-
The folders `./c` and `./cg` contain C code extracted from `libcrux-ml-kem`.
3+
The subfolders of `./extracts/` contain C code extracted from `libcrux-ml-kem`.
44

55
The C code is generated from Rust using [Charon], [Eurydice] and
66
[KaRaMeL]. Charon translates the Rust crate to Low-Level Borrow
@@ -17,22 +17,27 @@ opam install --yes ocamlfind visitors menhir ppx_deriving_yojson core_unix sedle
1717
```
1818

1919
Now you're ready to install the tools.
20+
2021
### Set tool directories
22+
2123
Set the directories where tool repositories should be cloned and tools should be built in. Setting these environment variables is important for the extraction script `c.sh`.
24+
2225
```bash
2326
export CHARON_HOME=$HOME/charon
2427
export KRML_HOME=$HOME/karamel
2528
export EURYDICE_HOME=$HOME/eurydice
2629
```
2730

2831
### Charon
32+
2933
```bash
3034
git clone https://github.com/AeneasVerif/charon.git $CHARON_HOME
3135
cd $CHARON_HOME
3236
make
3337
```
3438

3539
### KaRaMeL
40+
3641
```bash
3742
git clone https://github.com/FStarLang/karamel.git $KRML_HOME
3843
cd $KRML_HOME
@@ -48,23 +53,29 @@ make
4853

4954
## Generating C code
5055

51-
The [c.sh](../c.sh) bash script drives the extraction, using the
52-
[c.yaml](../c.yaml) configuration file, which configures the Eurydice
53-
translation.
54-
55-
To generate a header-only version, use [boring.sh](../boring.sh)
56-
instead, which internally runs [c.sh](../c.sh) with a header-only
57-
configuration found in [cg.yaml](../cg.yaml).
56+
Each extraction has a script `extract.sh` for extracting the code. They all make
57+
use of the `extracts/common/c.sh` script, but use it with different arguments.
58+
Each extraction also comes with an `extract.yaml` configuration file, which
59+
configures the Eurydice translation.
5860

5961
While running the commands separately is possible, it is not
6062
recommended because the script sets all necessary configuration flags.
6163

64+
We maintain the following extraction configurations:
65+
66+
- `c_header_only`: header-only C code
67+
- `cpp_header_only`: header-only C++ code
68+
69+
For the `c_header_only` and `cpp_header_only` extractions we also keep the
70+
extracted code in the repository so users don't need to extract it themselves.
71+
6272
## Build
6373

64-
Make sure to use `CC=clang CXX=clang++` when benchmarking on Linux to get full performance.
74+
Make sure to use `CC=clang CXX=clang++` when benchmarking on Linux to get full
75+
performance.
6576

6677
```bash
67-
cd ./c # or ./cg, if you want to build header-only
78+
cd extracts/c_header_only # or extracts/cpp_header_only if you want to build C++
6879
cmake -B build
6980
cmake --build build
7081
```

libcrux-ml-kem/Cargo.toml

Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -11,15 +11,9 @@ description = "Libcrux ML-KEM & Kyber implementations"
1111
exclude = [
1212
"/tests",
1313
"/implementation_notes.pdf",
14-
"/c",
14+
"/extracts",
1515
"/proofs",
16-
"/c.sh",
17-
"/c.yaml",
1816
"/hax.py",
19-
"/cg",
20-
"/c-nss.sh",
21-
"/c.sh",
22-
"/boring.sh",
2317
]
2418

2519
[lib]

libcrux-ml-kem/c-nss.sh

Lines changed: 0 additions & 21 deletions
This file was deleted.

0 commit comments

Comments
 (0)