|
| 1 | +using BinaryBuilder, Pkg |
| 2 | + |
| 3 | +include("../../L/libjulia/common.jl") |
| 4 | + |
| 5 | +function prepare_openfhe_julia_build(name::String, git_hash::String) |
| 6 | + # See https://github.com/JuliaLang/Pkg.jl/issues/2942 |
| 7 | + # Once this Pkg issue is resolved, this must be removed |
| 8 | + uuid = Base.UUID("a83860b7-747b-57cf-bf1f-3e79990d037f") |
| 9 | + delete!(Pkg.Types.get_last_stdlibs(v"1.6.3"), uuid) |
| 10 | + |
| 11 | + # Collection of sources required to complete build |
| 12 | + sources = [ |
| 13 | + GitSource("https://github.com/hpsc-lab/openfhe-julia.git", |
| 14 | + git_hash), |
| 15 | + ArchiveSource("https://github.com/alexey-lysiuk/macos-sdk/releases/download/14.5/MacOSX14.5.tar.xz", |
| 16 | + "f6acc6209db9d56b67fcaf91ec1defe48722e9eb13dc21fb91cfeceb1489e57e"), |
| 17 | + ] |
| 18 | + |
| 19 | + # Bash recipe for building across all platforms |
| 20 | + script = raw""" |
| 21 | + cd $WORKSPACE/srcdir/openfhe-julia/ |
| 22 | +
|
| 23 | + if [[ "${target}" == *-mingw* ]]; then |
| 24 | + # This is needed because otherwise we get unusable binaries (error "The specified |
| 25 | + # executable is not a valid application for this OS platform"). These come from |
| 26 | + # CompilerSupportLibraries_jll. |
| 27 | + # xref: https://github.com/JuliaPackaging/Yggdrasil/issues/7904 |
| 28 | + # |
| 29 | + # The remove path pattern matches `lib/gcc/<triple>/<major>/`, where `<triple>` is the |
| 30 | + # platform triplet and `<major>` is the GCC major version with which CSL was built |
| 31 | + # xref: https://github.com/JuliaPackaging/Yggdrasil/pull/7535 |
| 32 | + # |
| 33 | + # However, before CSL v1.1, these files were located in just `lib/`, thus we clean this |
| 34 | + # directory as well. |
| 35 | + if test -n "$(find $prefix/lib/gcc/*mingw*/*/libgcc*)"; then |
| 36 | + rm $prefix/lib/gcc/*mingw*/*/libgcc* $prefix/lib/gcc/*mingw*/*/libmsvcrt* |
| 37 | + elif test -n "$(find $prefix/lib/libgcc*)"; then |
| 38 | + rm $prefix/lib/libgcc* $prefix/lib/libmsvcrt* |
| 39 | + else |
| 40 | + echo "Could not find any libraries to remove :-/" |
| 41 | + find $prefix/lib |
| 42 | + fi |
| 43 | + fi |
| 44 | + |
| 45 | + # For MacOS higher version of SDK and additional linker flag are required |
| 46 | + # according to https://github.com/llvm/llvm-project/issues/119608 to link typeid(__int128) |
| 47 | + if [[ "$target" == *-apple-darwin* ]]; then |
| 48 | + export LDFLAGS="-lc++abi" |
| 49 | + apple_sdk_root=$WORKSPACE/srcdir/MacOSX14.5.sdk |
| 50 | + sed -i "s!/opt/$bb_target/$bb_target/sys-root!$apple_sdk_root!" $CMAKE_TARGET_TOOLCHAIN |
| 51 | + sed -i "s!/opt/$bb_target/$bb_target/sys-root!$apple_sdk_root!" /opt/bin/$bb_full_target/$target-clang++ |
| 52 | + fi |
| 53 | +
|
| 54 | + mkdir build && cd build |
| 55 | +
|
| 56 | + cmake .. \ |
| 57 | + -DCMAKE_INSTALL_PREFIX=$prefix \ |
| 58 | + -DCMAKE_TOOLCHAIN_FILE=${CMAKE_TARGET_TOOLCHAIN} \ |
| 59 | + -DCMAKE_BUILD_TYPE=Release \ |
| 60 | + -DJulia_PREFIX=$prefix |
| 61 | +
|
| 62 | + make -j${nproc} |
| 63 | + make install |
| 64 | + """ |
| 65 | + |
| 66 | + # These are the platforms we will build for by default, unless further |
| 67 | + # platforms are passed in on the command line |
| 68 | + platforms = vcat(libjulia_platforms.(julia_versions)...) |
| 69 | + |
| 70 | + # We cannot build with musl since OpenFHE requires the `execinfo.h` header for `backtrace` |
| 71 | + platforms = filter(p -> libc(p) != "musl", platforms) |
| 72 | + |
| 73 | + # PowerPC and 32-bit x86 and 64-bit FreeBSD on ARM 64 platforms are not supported by OpenFHE |
| 74 | + platforms = filter(p -> arch(p) != "i686", platforms) |
| 75 | + platforms = filter(p -> arch(p) != "powerpc64le", platforms) |
| 76 | + platforms = filter(p -> !(Sys.isfreebsd(p) && arch(p) == "aarch64"), platforms) |
| 77 | + |
| 78 | + if name == "openfhe_julia_int128" |
| 79 | + # 32 bit systems does not support __int128 |
| 80 | + platforms = filter(p -> nbits(p) != 32, platforms) |
| 81 | + # armv6l and armv7l do not support 128 bit int size |
| 82 | + platforms = filter(p -> arch(p) != "armv6l", platforms) |
| 83 | + platforms = filter(p -> arch(p) != "armv7l", platforms) |
| 84 | + end |
| 85 | + |
| 86 | + # Expand C++ string ABIs since we use std::string |
| 87 | + platforms = expand_cxxstring_abis(platforms) |
| 88 | + |
| 89 | + |
| 90 | + # The products that we will ensure are always built |
| 91 | + products = [ |
| 92 | + LibraryProduct("libopenfhe_julia", :libopenfhe_julia), |
| 93 | + ] |
| 94 | + |
| 95 | + # Dependencies that must be installed before this package can be built |
| 96 | + dependencies = [ |
| 97 | + BuildDependency(PackageSpec(;name="libjulia_jll", version=v"1.10.9")), |
| 98 | + Dependency(PackageSpec(name="libcxxwrap_julia_jll", uuid="3eaa8342-bff7-56a5-9981-c04077f7cee7"); compat="0.13.0"), |
| 99 | + # For OpenMP we use libomp from `LLVMOpenMP_jll` where we use LLVM as compiler (BSD |
| 100 | + # systems), and libgomp from `CompilerSupportLibraries_jll` everywhere else. |
| 101 | + Dependency(PackageSpec(name="CompilerSupportLibraries_jll", uuid="e66e0078-7015-5450-92f7-15fbd957f2ae"); |
| 102 | + platforms=filter(!Sys.isbsd, platforms)), |
| 103 | + Dependency(PackageSpec(name="LLVMOpenMP_jll", uuid="1d63c593-3942-5779-bab2-d838dc0a180e"); |
| 104 | + platforms=filter(Sys.isbsd, platforms)), |
| 105 | + ] |
| 106 | + |
| 107 | + return sources, script, platforms, products, dependencies |
| 108 | +end |
0 commit comments