Files
concrete/compilers/concrete-compiler/compiler/lib/Bindings/Rust/build.rs
Andi Drebes c8c969773e Rebase onto llvm-project 465ee9bfb26d with local changes
This commit rebases the compiler onto commit 465ee9bfb26d from
llvm-project with locally maintained patches on top, i.e.:

  * 5d8669d669ee: Fix the element alignment (size) for memrefCopy
  * 4239163ea337: fix: Do not fold the memref.subview if the offset are
                  != 0 and strides != 1
  * 72c5decfcc21: remove github stuff from llvm
  * 8d0ce8f9eca1: Support arbitrary element types in named operations
                  via attributes
  * 94f64805c38c: Copy attributes of scf.for on bufferization and make
                  it an allocation hoisting barrier

Main upstream changes from llvm-project that required modification of
concretecompiler:

  * Switch to C++17
  * Various changes in the interfaces for linalg named operations
  * Transition from `llvm::Optional` to `std::optional`
  * Use of enums instead of string values for iterator types in linalg
  * Changed default naming convention of getter methods in
    ODS-generated operation classes from `some_value()` to
    `getSomeValue()`
  * Renaming of Arithmetic dialect to Arith
  * Refactoring of side effect interfaces (i.e., renaming from
    `NoSideEffect` to `Pure`)
  * Re-design of the data flow analysis framework
  * Refactoring of build targets for Python bindings
  * Refactoring of array attributes with integer values
  * Renaming of `linalg.init_tensor` to `tensor.empty`
  * Emission of `linalg.map` operations in bufferization of the Tensor
    dialect requiring another linalg conversion pass and registration
    of the bufferization op interfaces for linalg operations
  * Refactoring of the one-shot bufferizer
  * Necessity to run the expand-strided-metadata, affine-to-std and
    finalize-memref-to-llvm passes before converson to the LLVM
    dialect
  * Renaming of `BlockAndValueMapping` to `IRMapping`
  * Changes in the build function of `LLVM::CallOp`
  * Refactoring of the construction of `llvm::ArrayRef` and
    `llvm::MutableArrayRef` (direct invocation of constructor instead
    of builder functions for some cases)
  * New naming conventions for generated SSA values requiring rewrite
    of some check tests
  * Refactoring of `mlir::LLVM::lookupOrCreateMallocFn()`
  * Interface changes in generated type parsers
  * New dependencies for to mlir_float16_utils and
    MLIRSparseTensorRuntime for the runtime
  * Overhaul of MLIR-c deleting `mlir-c/Registration.h`
  * Deletion of library MLIRLinalgToSPIRV
  * Deletion of library MLIRLinalgAnalysis
  * Deletion of library MLIRMemRefUtils
  * Deletion of library MLIRQuantTransforms
  * Deletion of library MLIRVectorToROCDL
2023-03-09 17:47:16 +01:00

346 lines
9.0 KiB
Rust

extern crate bindgen;
use std::env;
use std::error::Error;
use std::path::Path;
use std::process::exit;
const MLIR_STATIC_LIBS: [&str; 174] = [
"MLIRMemRefDialect",
"MLIRVectorToSPIRV",
"MLIRControlFlowInterfaces",
"MLIRLinalgToStandard",
"MLIRAnalysis",
"MLIRSPIRVDeserialization",
"MLIRTransformDialect",
"MLIRSparseTensorPipelines",
"MLIRVectorToGPU",
"MLIRTranslateLib",
"MLIRPass",
"MLIRComplexToLibm",
"MLIRInferTypeOpInterface",
"MLIRMemRefToSPIRV",
"MLIRAMDGPUToROCDL",
"MLIRBufferizationTransformOps",
"MLIRExecutionEngineUtils",
"MLIRNVVMDialect",
"MLIRSCFUtils",
"MLIRLinalgTransforms",
"MLIRParser",
"MLIRFuncTransforms",
"MLIRTosaTestPasses",
"MLIRTosaToArith",
"MLIRTensorDialect",
"MLIRGPUTransforms",
"MLIRLowerableDialectsToLLVM",
"MLIRBufferizationToMemRef",
"MLIRPresburger",
"MLIRFuncDialect",
"MLIRPDLToPDLInterp",
"MLIRArithTransforms",
"MLIRViewLikeInterface",
"MLIRTargetCpp",
"MLIROpenMPToLLVM",
"MLIRSPIRVConversion",
"MLIRNVGPUTransforms",
"MLIRSparseTensorTransforms",
"MLIRAffineAnalysis",
"MLIRArmSVETransforms",
"MLIRArmNeon2dToIntr",
"MLIRDataLayoutInterfaces",
"MLIRAffineTransforms",
"MLIROpenACCToLLVMIRTranslation",
"MLIRTensorUtils",
"MLIRSPIRVSerialization",
"MLIRShapeToStandard",
"MLIRArithToSPIRV",
"MLIRArithDialect",
"MLIRFuncToSPIRV",
"MLIRQuantUtils",
"MLIRTensorTilingInterfaceImpl",
"MLIRX86VectorToLLVMIRTranslation",
"MLIRCopyOpInterface",
"MLIRMathToLibm",
"MLIRGPUToGPURuntimeTransforms",
"MLIRLLVMDialect",
"MLIRAffineDialect",
"MLIRTransforms",
"MLIRVectorTransforms",
"MLIROpenMPDialect",
"MLIRControlFlowDialect",
"MLIRVectorUtils",
"MLIRROCDLDialect",
"MLIRPDLDialect",
"MLIRAsyncDialect",
"MLIRLinalgToLLVM",
"MLIROpenACCDialect",
"MLIRVectorDialect",
"MLIROpenACCToSCF",
"MLIRIR",
"MLIRCAPIIR",
"MLIRTargetLLVMIRImport",
"MLIRTensorToLinalg",
"MLIRCallInterfaces",
"MLIRTensorInferTypeOpInterfaceImpl",
"MLIRTransformDialectTransforms",
"MLIRComplexDialect",
"MLIRAffineUtils",
"MLIRLoopLikeInterface",
"MLIRDialect",
"MLIRLinalgUtils",
"MLIRSCFToSPIRV",
"MLIRAffineToStandard",
"MLIRX86VectorDialect",
"MLIRGPUToVulkanTransforms",
"MLIRRewrite",
"MLIRAMXToLLVMIRTranslation",
"MLIRInferIntRangeInterface",
"MLIRCAPIRegisterEverything",
"MLIRNVVMToLLVMIRTranslation",
"MLIRAsyncTransforms",
"MLIRPDLInterpDialect",
"MLIRTransformUtils",
"MLIRLinalgDialect",
"MLIRMathDialect",
"MLIRMemRefTransforms",
"MLIRSPIRVModuleCombiner",
"MLIRMathToLLVM",
"MLIRControlFlowToLLVM",
"MLIRArmSVEDialect",
"MLIRSPIRVTranslateRegistration",
"MLIRToLLVMIRTranslationRegistration",
"MLIRSCFDialect",
"MLIRTilingInterface",
"MLIREmitCDialect",
"MLIRTableGen",
"MLIRTosaToSCF",
"MLIROpenMPToLLVMIRTranslation",
"MLIRSupport",
"MLIROpenACCToLLVM",
"MLIRAMDGPUDialect",
"MLIRTosaToLinalg",
"MLIRSparseTensorUtils",
"MLIRFuncToLLVM",
"MLIRTargetLLVMIRExport",
"MLIRControlFlowToSPIRV",
"MLIRReconcileUnrealizedCasts",
"MLIRComplexToStandard",
"MLIRMathTransforms",
"MLIRSPIRVUtils",
"MLIRCastInterfaces",
"MLIRTosaToTensor",
"MLIRGPUToSPIRV",
"MLIRBufferizationDialect",
"MLIRSCFToControlFlow",
"MLIRArmSVEToLLVMIRTranslation",
"MLIRExecutionEngine",
"MLIRBufferizationTransforms",
"MLIRSparseTensorDialect",
"MLIRTensorToSPIRV",
"MLIRVectorToSCF",
"MLIRLLVMToLLVMIRTranslation",
"MLIRNVGPUDialect",
"MLIRAsyncToLLVM",
"MLIRAMXDialect",
"MLIRLinalgTransformOps",
"MLIRMathToSPIRV",
"MLIRSCFToOpenMP",
"MLIRShapeDialect",
"MLIRGPUToROCDLTransforms",
"MLIRGPUToNVVMTransforms",
"MLIRTensorTransforms",
"MLIRSCFToGPU",
"MLIRDialectUtils",
"MLIRNVGPUToNVVM",
"MLIRTosaDialect",
"MLIRVectorToLLVM",
"MLIRSPIRVDialect",
"MLIRSideEffectInterfaces",
"MLIRQuantDialect",
"MLIRSCFTransforms",
"MLIRMLProgramDialect",
"MLIRDLTIDialect",
"MLIRLinalgFrontend",
"MLIRROCDLToLLVMIRTranslation",
"MLIRArmNeonDialect",
"MLIRSPIRVToLLVM",
"MLIRLLVMIRTransforms",
"MLIRTosaTransforms",
"MLIRLLVMCommonConversion",
"MLIRSCFTransformOps",
"MLIRArmNeonToLLVMIRTranslation",
"MLIRAMXTransforms",
"MLIRSPIRVTransforms",
"MLIRMemRefToLLVM",
"MLIRSPIRVBinaryUtils",
"MLIRArithUtils",
"MLIRVectorInterfaces",
"MLIRGPUOps",
"MLIRComplexToLLVM",
"MLIRShapeOpsTransforms",
"MLIRX86VectorTransforms",
"MLIRArithToLLVM",
];
const LLVM_STATIC_LIBS: [&str; 51] = [
"LLVMAggressiveInstCombine",
"LLVMAnalysis",
"LLVMAsmParser",
"LLVMAsmPrinter",
"LLVMBinaryFormat",
"LLVMBitReader",
"LLVMBitstreamReader",
"LLVMBitWriter",
"LLVMCFGuard",
"LLVMCodeGen",
"LLVMCore",
"LLVMCoroutines",
"LLVMDebugInfoCodeView",
"LLVMDebugInfoDWARF",
"LLVMDebugInfoMSF",
"LLVMDebugInfoPDB",
"LLVMDemangle",
"LLVMExecutionEngine",
"LLVMFrontendOpenMP",
"LLVMGlobalISel",
"LLVMInstCombine",
"LLVMInstrumentation",
"LLVMipo",
"LLVMIRReader",
"LLVMJITLink",
"LLVMLinker",
"LLVMMC",
"LLVMMCDisassembler",
"LLVMMCParser",
"LLVMObjCARCOpts",
"LLVMObject",
"LLVMOrcJIT",
"LLVMOrcShared",
"LLVMOrcTargetProcess",
"LLVMPasses",
"LLVMProfileData",
"LLVMRemarks",
"LLVMRuntimeDyld",
"LLVMScalarOpts",
"LLVMSelectionDAG",
"LLVMSupport",
"LLVMSymbolize",
"LLVMTableGen",
"LLVMTableGenGlobalISel",
"LLVMTarget",
"LLVMTextAPI",
"LLVMTransformUtils",
"LLVMVectorize",
"LLVMX86CodeGen",
"LLVMX86Desc",
"LLVMX86Info",
];
const CONCRETE_COMPILER_LIBS: [&str; 33] = [
"RTDialect",
"RTDialectTransforms",
"ConcretelangSupport",
"ConcreteToCAPI",
"ConcretelangConversion",
"ConcretelangTransforms",
"FHETensorOpsToLinalg",
"ConcretelangServerLib",
"CONCRETELANGCAPIFHE",
"TFHEGlobalParametrization",
"ConcretelangClientLib",
"ConcretelangConcreteTransforms",
"ConcretelangSDFGInterfaces",
"ConcretelangSDFGTransforms",
"CONCRETELANGCAPISupport",
"FHELinalgDialect",
"ConcretelangInterfaces",
"TFHEDialect",
"CONCRETELANGCAPIFHELINALG",
"FHELinalgDialectTransforms",
"FHEDialect",
"TFHEToConcrete",
"FHEToTFHECrt",
"FHEToTFHEScalar",
"TFHEDialectTransforms",
"concrete_optimizer",
"LinalgExtras",
"FHEDialectAnalysis",
"ConcreteDialect",
"RTDialectAnalysis",
"SDFGDialect",
"ExtractSDFGOps",
"SDFGToStreamEmulator",
];
fn main() {
if let Err(error) = run() {
eprintln!("{}", error);
exit(1);
}
}
fn run() -> Result<(), Box<dyn Error>> {
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 {
println!("cargo:rustc-link-lib=static={}", concrete_compiler_lib);
}
// concrete compiler runtime
println!("cargo:rustc-link-lib=ConcretelangRuntime");
// concrete optimizer
// `-bundle` serve to not have multiple definition issues
println!("cargo:rustc-link-lib=static:-bundle=concrete_optimizer_cpp");
// mlir libs
for mlir_static_lib in MLIR_STATIC_LIBS {
println!("cargo:rustc-link-lib=static={}", mlir_static_lib);
}
// llvm libs
for llvm_static_lib in LLVM_STATIC_LIBS {
println!("cargo:rustc-link-lib=static={}", llvm_static_lib);
}
// required by llvm
println!("cargo:rustc-link-lib=ncurses");
if let Some(name) = get_system_libcpp() {
println!("cargo:rustc-link-lib={}", name);
}
// zlib
println!("cargo:rustc-link-lib=z");
println!("cargo:rerun-if-changed=api.h");
bindgen::builder()
.header("api.h")
.clang_args(
include_paths
.into_iter()
.map(|path| format!("-I{}", path.to_str().unwrap())),
)
.parse_callbacks(Box::new(bindgen::CargoCallbacks))
.generate()
.unwrap()
.write_to_file(Path::new(&env::var("OUT_DIR")?).join("bindings.rs"))?;
Ok(())
}
fn get_system_libcpp() -> Option<&'static str> {
if cfg!(target_env = "msvc") {
None
} else if cfg!(target_os = "macos") {
Some("c++")
} else {
Some("stdc++")
}
}