chore: build rust package using install dir

This commit is contained in:
youben11
2022-12-07 16:59:33 +01:00
committed by Ayoub Benaissa
parent 8d063d299c
commit 65235408bc
2 changed files with 22 additions and 59 deletions

View File

@@ -8,7 +8,7 @@ CC_COMPILER=
CXX_COMPILER=
CUDA_SUPPORT?=OFF
CONCRETE_CORE_PATH?= $(shell pwd)/concrete-core
INSTALL_PREFIX?=/usr/local/
INSTALL_PREFIX?=$(abspath $(BUILD_DIR))/install
INSTALL_PATH=$(abspath $(INSTALL_PREFIX))/concretecompiler/
MAKEFILE_ROOT_DIR=$(shell pwd)
@@ -164,12 +164,8 @@ python-bindings: build-initialized
cmake --build $(BUILD_DIR) --target ConcretelangMLIRPythonModules
cmake --build $(BUILD_DIR) --target ConcretelangPythonModules
# MLIRCAPIRegistration is currently required for linking rust bindings
# This may fade if we can represent it somewhere else, mainly, we may be able to define a single
# lib that the rust bindings need to link to, while that lib contains all necessary libs
rust-bindings: build-initialized concretecompiler CAPI
cmake --build $(BUILD_DIR) --target MLIRCAPIRegistration
cd lib/Bindings/Rust && CONCRETE_COMPILER_BUILD_DIR=$(abspath $(BUILD_DIR)) cargo build --release
rust-bindings: install
cd lib/Bindings/Rust && CONCRETE_COMPILER_INSTALL_DIR=$(INSTALL_PATH) cargo build --release
CAPI:
cmake --build $(BUILD_DIR) --target CONCRETELANGCAPIFHE CONCRETELANGCAPIFHELINALG CONCRETELANGCAPISupport
@@ -230,7 +226,7 @@ test-compiler-file-output: concretecompiler
## rust-tests
run-rust-tests: rust-bindings
cd lib/Bindings/Rust && CONCRETE_COMPILER_BUILD_DIR=$(abspath $(BUILD_DIR)) LD_LIBRARY_PATH=$(abspath $(BUILD_DIR))/lib cargo test --release
cd lib/Bindings/Rust && CONCRETE_COMPILER_INSTALL_DIR=$(INSTALL_PATH) LD_LIBRARY_PATH=$(INSTALL_PATH)/lib cargo test --release
## end-to-end-tests
@@ -404,7 +400,11 @@ check-rust-format:
rust-format:
cd lib/Bindings/Rust && cargo fmt
install: concretecompiler concrete-optimizer-lib CAPI
# libraries we want to have in the installation that aren't already a deps of other targets
install-deps:
cmake --build $(BUILD_DIR) --target MLIRCAPIRegistration
install: concretecompiler concrete-optimizer-lib CAPI install-deps
$(info Install prefix set to $(INSTALL_PREFIX))
$(info Installing under $(INSTALL_PATH))
mkdir -p $(INSTALL_PATH)/include

View File

@@ -2,7 +2,7 @@ extern crate bindgen;
use std::env;
use std::error::Error;
use std::path::{Path, PathBuf};
use std::path::Path;
use std::process::exit;
const MLIR_STATIC_LIBS: [&str; 179] = [
@@ -281,38 +281,18 @@ fn main() {
}
fn run() -> Result<(), Box<dyn Error>> {
let root = std::fs::canonicalize("../../../../")?;
// library paths
let build_dir = get_build_dir();
let lib_dir = build_dir.join("lib");
// compiler build libs
println!("cargo:rustc-link-search={}", lib_dir.to_str().unwrap());
// concrete optimizer lib
println!(
"cargo:rustc-link-search={}",
root.join("compiler/concrete-optimizer/target/release")
.to_str()
.unwrap()
);
// include paths
let include_paths = [
// compiler build
build_dir.join("tools/concretelang/include/"),
// mlir build
build_dir.join("tools/mlir/include"),
// llvm build
build_dir.join("include"),
// compiler
root.join("compiler/include/"),
// mlir
root.join("llvm-project/mlir/include/"),
// llvm
root.join("llvm-project/llvm/include/"),
// concrete-optimizer
root.join("compiler/concrete-optimizer/concrete-optimizer-cpp/src/cpp/"),
];
let mut include_paths = Vec::new();
// if set, use installation path of concrete compiler to lookup libraries and include files
match env::var("CONCRETE_COMPILER_INSTALL_DIR") {
Ok(install_dir) => {
println!("cargo:rustc-link-search={}/lib/", install_dir);
include_paths.push(Path::new(&format!("{}/include/", install_dir)).to_path_buf());
}
Err(_e) => println!(
"cargo:warning=You are not setting CONCRETE_COMPILER_INSTALL_DIR, \
so your compiler/linker will have to lookup libs and include dirs on their own"
),
}
// linking
// concrete-compiler libs
for concrete_compiler_lib in CONCRETE_COMPILER_LIBS {
@@ -364,20 +344,3 @@ fn get_system_libcpp() -> Option<&'static str> {
Some("stdc++")
}
}
fn get_build_dir() -> PathBuf {
// this env variable can be used to point to a different build directory
let build_dir = match env::var("CONCRETE_COMPILER_BUILD_DIR") {
Ok(val) => std::path::Path::new(&val).to_path_buf(),
Err(_e) => std::path::Path::new(".")
.parent()
.unwrap()
.join("..")
.join("..")
.join("..")
.join("build")
.canonicalize()
.unwrap(),
};
return build_dir;
}