Skip to content

Commit 52d25b5

Browse files
authored
Merge pull request #1270 from zama-ai/feat/concrete-rust-tfhe-rs-interop
Feat/concrete rust tfhe rs interop
2 parents a40934d + 16b8e8c commit 52d25b5

47 files changed

Lines changed: 2226 additions & 598 deletions

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.
Lines changed: 91 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,91 @@
1+
name: concrete-rust tests macos
2+
on:
3+
workflow_dispatch:
4+
pull_request:
5+
paths:
6+
- .github/workflows/concrete_rust_test_macos.yml
7+
- frontends/concrete-rust/**
8+
push:
9+
branches:
10+
- 'main'
11+
- 'release/*'
12+
13+
concurrency:
14+
group: concrete_rust_tests_macos_${{ github.ref }}
15+
cancel-in-progress: ${{ github.ref != 'refs/heads/main' }}
16+
17+
env:
18+
ACTION_RUN_URL: ${{ github.server_url }}/${{ github.repository }}/actions/runs/${{ github.run_id }}
19+
SLACK_CHANNEL: ${{ secrets.SLACK_CHANNEL }}
20+
SLACK_USERNAME: ${{ secrets.BOT_USERNAME }}
21+
SLACK_WEBHOOK: ${{ secrets.SLACK_WEBHOOK }}
22+
23+
jobs:
24+
concrete-rust-test:
25+
strategy:
26+
fail-fast: false
27+
matrix:
28+
machine: ["aws-mac1-metal", "aws-mac2-metal"]
29+
runs-on: ${{ matrix.machine }}
30+
outputs:
31+
slack_message: ${{ steps.prepare_slack_notif.outputs.slack_message }}
32+
slack_color: ${{ steps.prepare_slack_notif.outputs.slack_color }}
33+
env:
34+
concrete-compiler-dir: ${{ github.workspace }}/compilers/concrete-compiler/compiler
35+
concrete-rust-dir: ${{ github.workspace }}/frontends/concrete-rust
36+
steps:
37+
- name: Checkout
38+
uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # v4.2.2
39+
with:
40+
submodules: recursive
41+
fetch-depth: 0
42+
persist-credentials: 'false'
43+
- name: Install build dependencies
44+
run: |
45+
brew install ninja ccache
46+
- name: Setup rust toolchain for concrete-cpu
47+
uses: ./.github/actions/setup_rust_toolchain_for_concrete_cpu
48+
- name: Install rust
49+
uses: actions-rs/toolchain@16499b5e05bf2e26879000db0c1d13f7e13fa3af # v1.0.7
50+
with:
51+
toolchain: 1.84.0
52+
override: true
53+
- name: Build rust bindings
54+
run: |
55+
set -e
56+
cd ${{ env.concrete-compiler-dir }}
57+
rm -rf .venv
58+
python3 -m venv .venv
59+
source .venv/bin/activate
60+
pip install -r lib/Bindings/Python/requirements_dev.txt
61+
cargo install cxxbridge-cmd
62+
ccache -z
63+
make Python3_EXECUTABLE="$(which python)" concrete-rust
64+
ccache -s
65+
- name: Run tests
66+
run: |
67+
set -e
68+
cd ${{ env.concrete-rust-dir }}
69+
make clean
70+
make clear_locks
71+
make test
72+
- name: Prepare Slack Notification
73+
id: prepare_slack_notif
74+
if: ${{ failure() }}
75+
continue-on-error: true
76+
run: |
77+
echo "slack_message=concrete-rust-test (${{matrix.machine}}) finished with status: ${{ job.status }}. (${{ env.ACTION_RUN_URL }})" >> "$GITHUB_OUTPUT"
78+
echo "slack_color=${{ job.status }}" >> "$GITHUB_OUTPUT"
79+
80+
slack-notif-macos:
81+
needs: ["concrete-rust-test"]
82+
runs-on: "ubuntu-latest"
83+
if: always()
84+
steps:
85+
- name: Slack Notification
86+
# we want to check that prepare_slack_notif was run
87+
if: ${{ needs.concrete-rust-test.outputs.slack_color != '' }}
88+
uses: rtCamp/action-slack-notify@c33737706dea87cd7784c687dadc9adf1be59990
89+
env:
90+
SLACK_COLOR: ${{ needs.concrete-rust-test.outputs.slack_color }}
91+
SLACK_MESSAGE: ${{ needs.concrete-rust-test.outputs.slack_message }}
Lines changed: 120 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,120 @@
1+
name: concrete-rust tests linux-cpu
2+
3+
on:
4+
workflow_dispatch:
5+
pull_request:
6+
paths:
7+
- .github/workflows/concrete_rust_tests_linux.yml
8+
- frontends/concrete-rust/**
9+
push:
10+
branches:
11+
- 'main'
12+
- 'release/*'
13+
14+
env:
15+
DOCKER_IMAGE_TEST: ghcr.io/zama-ai/concrete/compiler-ci
16+
ACTION_RUN_URL: ${{ github.server_url }}/${{ github.repository }}/actions/runs/${{ github.run_id }}
17+
SLACK_CHANNEL: ${{ secrets.SLACK_CHANNEL }}
18+
SLACK_USERNAME: ${{ secrets.BOT_USERNAME }}
19+
SLACK_WEBHOOK: ${{ secrets.SLACK_WEBHOOK }}
20+
21+
concurrency:
22+
group: concrete_rust_tests_linux_${{ github.ref }}
23+
cancel-in-progress: ${{ github.ref != 'refs/heads/main' }}
24+
25+
jobs:
26+
setup-instance:
27+
runs-on: ubuntu-latest
28+
outputs:
29+
runner-name: ${{ steps.start-instance.outputs.label }}
30+
steps:
31+
- name: Start instance
32+
id: start-instance
33+
uses: zama-ai/slab-github-runner@f26b8d611b2e695158fb0a6980834f0612f65ef8 # v1.4.0
34+
with:
35+
mode: start
36+
github-token: ${{ secrets.SLAB_ACTION_TOKEN }}
37+
slab-url: ${{ secrets.SLAB_BASE_URL }}
38+
job-secret: ${{ secrets.JOB_SECRET }}
39+
backend: aws
40+
profile: cpu-test
41+
42+
build-and-test-rust:
43+
needs: setup-instance
44+
runs-on: ${{ needs.setup-instance.outputs.runner-name }}
45+
steps:
46+
- name: Checkout concrete
47+
uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # v4.2.2
48+
with:
49+
submodules: recursive
50+
fetch-depth: 0
51+
52+
- name: Create concrete build directory
53+
run: mkdir build
54+
55+
- name: Build rust bindings
56+
uses: addnab/docker-run-action@4f65fabd2431ebc8d299f8e5a018d79a769ae185 # v3
57+
with:
58+
registry: ghcr.io
59+
image: ${{ env.DOCKER_IMAGE_TEST }}
60+
username: ${{ secrets.GHCR_LOGIN }}
61+
password: ${{ secrets.GHCR_PASSWORD }}
62+
options: >-
63+
-v ${{ github.workspace }}:/concrete
64+
-v ${{ github.workspace }}/build:/build
65+
shell: bash
66+
run: |
67+
set -e
68+
ccache -z
69+
ccache -p
70+
cd /concrete/compilers/concrete-compiler/compiler
71+
make BUILD_DIR=/build DATAFLOW_EXECUTION_ENABLED=ON CCACHE=ON Python3_EXECUTABLE=$(which python) concrete-rust
72+
echo "Debug: ccache statistics (after the build):"
73+
ccache -s
74+
75+
- name: Run tests
76+
uses: addnab/docker-run-action@4f65fabd2431ebc8d299f8e5a018d79a769ae185 # v3
77+
with:
78+
registry: ghcr.io
79+
image: ${{ env.DOCKER_IMAGE_TEST }}
80+
username: ${{ secrets.GHCR_LOGIN }}
81+
password: ${{ secrets.GHCR_PASSWORD }}
82+
options: >-
83+
-v ${{ github.workspace }}:/concrete
84+
-v ${{ github.workspace }}/build:/build
85+
shell: bash
86+
run: |
87+
set -e
88+
cd /concrete/frontends/concrete-rust
89+
RUSTFLAGS="-Clink-args=-Wl,/usr/lib64/libstdc++.so.6" make COMPILER_BUILD_DIRECTORY=/build test
90+
91+
- name: Slack Notification
92+
if: ${{ failure() && github.ref == 'refs/heads/main' }}
93+
continue-on-error: true
94+
uses: rtCamp/action-slack-notify@c33737706dea87cd7784c687dadc9adf1be59990
95+
env:
96+
SLACK_COLOR: ${{ job.status }}
97+
SLACK_MESSAGE: "build-and-test-rust finished with status: ${{ job.status }}. (${{ env.ACTION_RUN_URL }})"
98+
99+
teardown-instance:
100+
if: ${{ always() && needs.setup-instance.result != 'skipped' }}
101+
needs: [ setup-instance, build-and-test-rust]
102+
runs-on: ubuntu-latest
103+
steps:
104+
- name: Stop instance
105+
id: stop-instance
106+
uses: zama-ai/slab-github-runner@f26b8d611b2e695158fb0a6980834f0612f65ef8 # v1.4.0
107+
with:
108+
mode: stop
109+
github-token: ${{ secrets.SLAB_ACTION_TOKEN }}
110+
slab-url: ${{ secrets.SLAB_BASE_URL }}
111+
job-secret: ${{ secrets.JOB_SECRET }}
112+
label: ${{ needs.setup-instance.outputs.runner-name }}
113+
114+
- name: Slack Notification
115+
if: ${{ failure() }}
116+
continue-on-error: true
117+
uses: rtCamp/action-slack-notify@c33737706dea87cd7784c687dadc9adf1be59990
118+
env:
119+
SLACK_COLOR: ${{ job.status }}
120+
SLACK_MESSAGE: "Instance teardown finished with status: ${{ job.status }}. (${{ env.ACTION_RUN_URL }})"

.gitignore

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,9 @@
66
# Jetbrains tools
77
.idea/
88

9+
# Zed
10+
.zed/
11+
912
# HPX library
1013
compilers/concrete-compiler/compiler/hpx*
1114

@@ -14,3 +17,6 @@ tmp_directory_for_cml_tests
1417

1518
# Temp file
1619
frontends/concrete-python/examples/sha1/tmp_sha1_test_file.txt
20+
21+
# Macos files
22+
**/.DS_Store

compilers/concrete-compiler/compiler/include/concretelang/Common/Values.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -159,7 +159,7 @@ struct Value {
159159

160160
/// Turns a server value to a client value, without interpreting the kind of
161161
/// value.
162-
static Value fromRawTransportValue(TransportValue transportVal);
162+
static Value fromRawTransportValue(const TransportValue &transportVal);
163163

164164
/// Turns a client value to a raw (without kind info attached) server value.
165165
TransportValue intoRawTransportValue() const;

compilers/concrete-compiler/compiler/lib/Bindings/Python/concrete/compiler/tfhers_int.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@ def export_int(value: TransportValue, info: TfhersFheIntDescription) -> bytes:
2222
"""Convert Concrete value to TFHErs and serialize it.
2323
2424
Args:
25+
2526
value (Value): value to export
2627
info (TfhersFheIntDescription): description of the TFHErs integer to export to
2728

compilers/concrete-compiler/compiler/lib/Bindings/Python/requirements_dev.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,4 +3,5 @@ pylint==3.3.3
33
mypy==1.11.2
44
numpy>=1.23,<2.0
55
jsonpickle>=3.0.3
6+
pybind11>=2.13
67
pybind11-stubgen>=2.5

compilers/concrete-compiler/compiler/lib/Bindings/Rust/CMakeLists.txt

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,8 +12,16 @@ if(LINUX)
1212
set(CMAKE_SHARED_LINKER_FLAGS "${CMAKE_SHARED_LINKER_FLAGS} -Wl,-Bsymbolic")
1313
endif()
1414

15-
target_link_libraries(ConcreteRust PRIVATE ConcretelangSupport ConcretelangClientLib ConcretelangServerLib
16-
ConcretelangRuntimeStatic)
15+
target_link_libraries(
16+
ConcreteRust
17+
PRIVATE ConcretelangSupport
18+
ConcretelangClientLib
19+
ConcretelangServerLib
20+
ConcretelangRuntimeStatic
21+
LLVMSupport
22+
capnp
23+
capnp-json
24+
kj)
1725

1826
if(APPLE)
1927
find_library(SECURITY_FRAMEWORK Security)

compilers/concrete-compiler/compiler/lib/Common/Values.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ using concretelang::protocol::vectorToProtoPayload;
2525
namespace concretelang {
2626
namespace values {
2727

28-
Value Value::fromRawTransportValue(TransportValue transportVal) {
28+
Value Value::fromRawTransportValue(const TransportValue &transportVal) {
2929
Value output;
3030
auto integerPrecision =
3131
transportVal.asReader().getRawInfo().getIntegerPrecision();

frontends/concrete-rust/Makefile

Lines changed: 38 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,43 @@
11
CARGO_SUBDIRS := concrete concrete-macro test concrete-keygen
2+
COMPILER_BUILD_DIRECTORY := ../../../compilers/concrete-compiler/compiler/build
3+
4+
.PHONY: test clean run pcc
25

3-
.PHONY: test
46
test:
57
@for dir in $(CARGO_SUBDIRS); do \
6-
echo "Running cargo test in $$dir..."; \
7-
COMPILER_BUILD_DIRECTORY=../../../compilers/concrete-compiler/compiler/build cargo test --manifest-path $$dir/Cargo.toml || exit 1; \
8+
echo "Running cargo test in $$dir..."; \
9+
COMPILER_BUILD_DIRECTORY=$(COMPILER_BUILD_DIRECTORY) cargo test --all-features --manifest-path $$dir/Cargo.toml -- --nocapture || exit 1; \
10+
done
11+
12+
clean:
13+
@for dir in $(CARGO_SUBDIRS); do \
14+
echo "Cleaning target folder in $$dir..."; \
15+
rm -rf $$dir/target || exit 1; \
816
done
17+
18+
clear_locks :
19+
@for dir in $(CARGO_SUBDIRS); do \
20+
echo "Cleaning lock in $$dir..."; \
21+
rm -rf $$dir/Cargo.lock || exit 1; \
22+
done
23+
24+
run:
25+
cd test && \
26+
COMPILER_BUILD_DIRECTORY=$(COMPILER_BUILD_DIRECTORY) cargo run
27+
28+
pcc:
29+
@for dir in $(CARGO_SUBDIRS); do \
30+
echo "Running pcc in $$dir..."; \
31+
COMPILER_BUILD_DIRECTORY=$(COMPILER_BUILD_DIRECTORY) cargo check --all-features --manifest-path $$dir/Cargo.toml || exit 1; \
32+
done
33+
34+
format:
35+
@for dir in $(CARGO_SUBDIRS); do \
36+
echo "Running format in $$dir..."; \
37+
COMPILER_BUILD_DIRECTORY=$(COMPILER_BUILD_DIRECTORY) cargo fmt --manifest-path $$dir/Cargo.toml || exit 1; \
38+
done
39+
40+
regen_test_zips:
41+
cd test/src && \
42+
python ../python/test.py && \
43+
python ../python/test_tfhers.py

frontends/concrete-rust/concrete-keygen/Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ capnpc = "0.20.1"
3737
capnp = "0.20.3"
3838

3939
clap = { version = "4.5.16", features = ["derive"], optional = true }
40-
zip = { version = "2.6.1", optional = true }
40+
zip = { version = "3.0", optional = true }
4141

4242
wasm-bindgen = { version = "0.2", features = ["serde-serialize"], optional = true }
4343
wasm-bindgen-futures = { version = "0.4.50", optional = true }

0 commit comments

Comments
 (0)