Skip to content

Commit

Permalink
feat(compiler): add concrete-sys rust bindings
Browse files Browse the repository at this point in the history
  • Loading branch information
aPere3 committed Feb 4, 2025
1 parent 8c47e38 commit 1abc34e
Show file tree
Hide file tree
Showing 27 changed files with 1,490 additions and 26 deletions.
14 changes: 10 additions & 4 deletions compilers/concrete-compiler/compiler/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -120,7 +120,7 @@ ifeq ($(BUILD_TYPE),Debug)
LIBOMP_LINK_TO_LIBSTDCXX_OPT=-DLIBOMP_USE_STDCPPLIB=ON
endif

all: concretecompiler python-bindings build-tests build-benchmarks doc
all: concretecompiler python-bindings build-tests build-benchmarks doc concrete-sys

# HPX #####################################################

Expand Down Expand Up @@ -154,7 +154,7 @@ $(BUILD_DIR)/configured.stamp:
-DCMAKE_BUILD_TYPE=$(BUILD_TYPE) \
-DLLVM_ENABLE_ASSERTIONS=ON \
-DLLVM_ENABLE_RTTI=ON \
-DLLVM_LINK_LLVM_DYLIB=on \
-DLLVM_LINK_LLVM_DYLIB=OFF \
-DMLIR_ENABLE_BINDINGS_PYTHON=$(BINDINGS_PYTHON_ENABLED) \
-DCONCRETELANG_BINDINGS_PYTHON_ENABLED=$(BINDINGS_PYTHON_ENABLED) \
-DCONCRETELANG_DATAFLOW_EXECUTION_ENABLED=$(DATAFLOW_EXECUTION_ENABLED) \
Expand Down Expand Up @@ -195,7 +195,8 @@ clientlib: build-initialized
serverlib: build-initialized
cmake --build $(BUILD_DIR) --target ConcretelangServerLib


concrete-sys: build-initialized
cmake --build $(BUILD_DIR) --target ConcreteSys

GITHUB_URL=https://api.github.com/repos/zama-ai/concrete-compiler-internal
GITHUB_URL_LIST_ARTIFACTS="${GITHUB_URL}/actions/artifacts?name=${KEYSETCACHENAME}&per_page=1"
Expand Down Expand Up @@ -233,7 +234,7 @@ endif

build-tests: build-unit-tests build-end-to-end-tests

run-tests: run-check-tests run-unit-tests run-end-to-end-tests run-random-end-to-end-tests-for-each-options run-python-tests
run-tests: run-check-tests run-unit-tests run-end-to-end-tests run-random-end-to-end-tests-for-each-options run-python-tests run-rust-tests

## check-tests

Expand All @@ -253,6 +254,11 @@ run-unit-tests: build-unit-tests
run-python-tests: python-bindings concretecompiler
PYTHONPATH=${PYTHONPATH}:$(BUILD_DIR)/tools/concretelang/python_packages/concretelang_core LD_PRELOAD=$(BUILD_DIR)/lib/libConcretelangRuntime.so pytest -vs -m $(PYTHON_TESTS_MARKER) tests/python

## rust-tests

run-rust-tests: concrete-sys
cd lib/Bindings/Rust && cargo test

test-compiler-file-output: concretecompiler
pytest -vs tests/test_compiler_file_output

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,6 @@
#ifndef CONCRETELANG_SUPPORT_COMPILER_ENGINE_H
#define CONCRETELANG_SUPPORT_COMPILER_ENGINE_H

#include "capnp/message.h"
#include "concrete-protocol.capnp.h"
#include "concretelang/Common/Protocol.h"
#include "concretelang/Conversion/Utils/GlobalFHEContext.h"
#include "concretelang/Support/Encodings.h"
Expand Down
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
if(CONCRETELANG_BINDINGS_PYTHON_ENABLED)
add_subdirectory(Python)
endif()

add_subdirectory(Rust)
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
add_compile_options(-fexceptions)

add_custom_target(gen_concrete_sys_bridge
COMMAND cxxbridge ${CMAKE_CURRENT_SOURCE_DIR}/concrete-sys/src/lib.rs --header > ${CMAKE_CURRENT_SOURCE_DIR}/concrete-sys/src/lib.rs.h
COMMAND cxxbridge ${CMAKE_CURRENT_SOURCE_DIR}/concrete-sys/src/lib.rs > ${CMAKE_CURRENT_SOURCE_DIR}/concrete-sys/src/lib.rs.cc
)

add_library(
ConcreteSys
SHARED
concrete-sys/src/lib.cpp
concrete-sys/src/lib.rs.cc
)

target_link_libraries(
ConcreteSys
PRIVATE
ConcretelangSupport
LLVMSupport
_ConcreteSys_ConcretelangCommon_Sec
_ConcreteSys_ConcretelangRuntime_Dfr
)

add_dependencies(
ConcreteSys
gen_concrete_sys_bridge
)
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
[workspace]

members = ["concrete-sys"]

resolver = "2"
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
Cargo.lock
target/**
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
[package]
name = "concrete-sys"
version = "0.1.0"
edition = "2021"

[dependencies]
cxx = "1.0"

[build-dependencies]
cxx-build = "1.0"

[dev-dependencies]
ar = "0.9"
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
use std::path::PathBuf;

#[cfg(target_os = "macos")]
const ARTIFACT_NAME: &str = "libConcreteSys.dylib";
#[cfg(target_os = "linux")]
const ARTIFACT_NAME: &str = "libConcreteSys.so";

fn main() {
let mut from = PathBuf::from(std::env::var("CARGO_MANIFEST_DIR").unwrap());
from.push("../../../../build/lib");
from.push(ARTIFACT_NAME);
let from = from.canonicalize().unwrap();
let mut to = PathBuf::from(std::env::var("OUT_DIR").unwrap());
to.push(ARTIFACT_NAME);
std::fs::copy(&from, &to).unwrap();
println!(
"cargo::rustc-link-search={}",
std::env::var("OUT_DIR").unwrap()
);
println!("cargo::rustc-link-lib=dylib=ConcreteSys");
println!("cargo::rerun-if-changed=src");
println!("cargo::rerun-if-changed={}", from.display());
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
lib.rs.cc
lib.rs.h
Loading

0 comments on commit 1abc34e

Please sign in to comment.