Skip to content

Commit 8d4fc34

Browse files
[openfhe_julia_int128] initialize and [openfhe_julia] update (#9961)
* [openfhe_julia_int128] Initialize * introduce common.jl * Update common.jl * Update common.jl * disable apple * enable apple * tru later gcc * Update build_tarballs.jl * use gcc in macos * Apply suggestions from code review Co-authored-by: Mosè Giordano <765740+giordano@users.noreply.github.com> * Set gcc and g++ compilers for apple and freebsd * filter 32 bit systems * set new compiler flag * try to built from pr with GNU_SOURCE * add gnu source as command line option * new try * try sdk 14 * disable apple * remove new line * add lc++abi flag * Update common.jl * add apple patch * Update apple-fix-cmake-typeinfo-int128.patch * add linker flag * use appropriate linker command * remove bundled from deps * export outside if * Update common.jl * fix * change to all apple, not apple darwin * Update common.jl * set CXXFLAGS instead of LDFLAGS * try out llvm-config * undo * try macosx14.5.sdk * delete linker flag * add tabs * Update common.jl --------- Co-authored-by: Mosè Giordano <765740+giordano@users.noreply.github.com>
1 parent 51e4e52 commit 8d4fc34

File tree

5 files changed

+154
-82
lines changed

5 files changed

+154
-82
lines changed

O/openfhe_julia/README.md

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
The OpenFHE library works with both 64-bit and 128-bit integers.
2+
3+
This package builds upon the default 64-bit version.
4+
5+
To use the 128-bit version, use
6+
[openfhe_julia_int128](https://github.com/JuliaPackaging/Yggdrasil/tree/master/O/openfhe_julia_int128).
7+
8+
Most of the build steps for openfhe_julia and
9+
[openfhe_julia_int128](https://github.com/JuliaPackaging/Yggdrasil/tree/master/O/openfhe_julia_int128) are the same,
10+
so the shared parts are in the
11+
[common.jl](https://github.com/JuliaPackaging/Yggdrasil/blob/master/O/openfhe_julia/common.jl) script.

O/openfhe_julia/build_tarballs.jl

Lines changed: 6 additions & 82 deletions
Original file line numberDiff line numberDiff line change
@@ -1,93 +1,17 @@
11
# Note that this script can accept some limited command-line arguments, run
22
# `julia build_tarballs.jl --help` to see a usage message.
3-
using BinaryBuilder, Pkg
4-
5-
# See https://github.com/JuliaLang/Pkg.jl/issues/2942
6-
# Once this Pkg issue is resolved, this must be removed
7-
uuid = Base.UUID("a83860b7-747b-57cf-bf1f-3e79990d037f")
8-
delete!(Pkg.Types.get_last_stdlibs(v"1.6.3"), uuid)
3+
include("common.jl")
94

5+
# If you make changes in this file, e.g., to release a new version,
6+
# be sure to also release a new version of `openfhe_julia_int128` as well (see `../openfhe_julia_int128/build_tarballs.jl`)
107
name = "openfhe_julia"
118
version = v"0.3.6"
129

13-
# Collection of sources required to complete build
14-
sources = [
15-
GitSource("https://github.com/hpsc-lab/openfhe-julia.git",
16-
"4939f1dd11ae2640b5bb397f731df8ef94307e74"),
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-
mkdir build && cd build
46-
47-
cmake .. \
48-
-DCMAKE_INSTALL_PREFIX=$prefix \
49-
-DCMAKE_TOOLCHAIN_FILE=${CMAKE_TARGET_TOOLCHAIN} \
50-
-DCMAKE_BUILD_TYPE=Release \
51-
-DJulia_PREFIX=$prefix
52-
53-
make -j${nproc}
54-
make install
55-
"""
56-
57-
# These are the platforms we will build for by default, unless further
58-
# platforms are passed in on the command line
59-
include("../../L/libjulia/common.jl")
60-
platforms = vcat(libjulia_platforms.(julia_versions)...)
61-
62-
# We cannot build with musl since OpenFHE requires the `execinfo.h` header for `backtrace`
63-
platforms = filter(p -> libc(p) != "musl", platforms)
64-
65-
# PowerPC and 32-bit x86 and 64-bit FreeBSD on ARM 64 platforms are not supported by OpenFHE
66-
platforms = filter(p -> arch(p) != "i686", platforms)
67-
platforms = filter(p -> arch(p) != "powerpc64le", platforms)
68-
platforms = filter(p -> !(Sys.isfreebsd(p) && arch(p) == "aarch64"), platforms)
69-
70-
# Expand C++ string ABIs since we use std::string
71-
platforms = expand_cxxstring_abis(platforms)
72-
10+
git_hash = "4939f1dd11ae2640b5bb397f731df8ef94307e74"
7311

74-
# The products that we will ensure are always built
75-
products = [
76-
LibraryProduct("libopenfhe_julia", :libopenfhe_julia),
77-
]
12+
sources, script, platforms, products, dependencies = prepare_openfhe_julia_build(name, git_hash)
7813

79-
# Dependencies that must be installed before this package can be built
80-
dependencies = [
81-
BuildDependency(PackageSpec(;name="libjulia_jll", version=v"1.10.9")),
82-
Dependency(PackageSpec(name="libcxxwrap_julia_jll", uuid="3eaa8342-bff7-56a5-9981-c04077f7cee7"); compat="0.13.0"),
83-
Dependency(PackageSpec(name="OpenFHE_jll", uuid="a2687184-f17b-54bc-b2bb-b849352af807"); compat="1.2.3"),
84-
# For OpenMP we use libomp from `LLVMOpenMP_jll` where we use LLVM as compiler (BSD
85-
# systems), and libgomp from `CompilerSupportLibraries_jll` everywhere else.
86-
Dependency(PackageSpec(name="CompilerSupportLibraries_jll", uuid="e66e0078-7015-5450-92f7-15fbd957f2ae");
87-
platforms=filter(!Sys.isbsd, platforms)),
88-
Dependency(PackageSpec(name="LLVMOpenMP_jll", uuid="1d63c593-3942-5779-bab2-d838dc0a180e");
89-
platforms=filter(Sys.isbsd, platforms)),
90-
]
14+
push!(dependencies, Dependency(PackageSpec(name="OpenFHE_jll", uuid="a2687184-f17b-54bc-b2bb-b849352af807"); compat="1.2.3"))
9115

9216
# Build the tarballs, and possibly a `build.jl` as well.
9317
build_tarballs(ARGS, name, version, sources, script, platforms, products, dependencies;

O/openfhe_julia/common.jl

Lines changed: 108 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,108 @@
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

O/openfhe_julia_int128/README.md

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
The OpenFHE library works with both 64-bit and 128-bit integers.
2+
3+
This package builds upon the 128-bit version.
4+
5+
To use the 64-bit version, use
6+
[openfhe_julia](https://github.com/JuliaPackaging/Yggdrasil/tree/master/O/openfhe_julia).
7+
8+
Most of the build steps for openfhe_julia_int128 and
9+
[openfhe_julia](https://github.com/JuliaPackaging/Yggdrasil/tree/master/O/openfhe_julia) are the same,
10+
so the shared parts are in the
11+
[common.jl](https://github.com/JuliaPackaging/Yggdrasil/blob/master/O/openfhe_julia/common.jl) script.
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
# Note that this script can accept some limited command-line arguments, run
2+
# `julia build_tarballs.jl --help` to see a usage message.
3+
include(joinpath(@__DIR__, "..", "openfhe_julia", "common.jl"))
4+
5+
# If you make changes in this file, e.g., to release a new version,
6+
# be sure to also release a new version of `openfhe_julia` as well (see `../openfhe_julia/build_tarballs.jl`)
7+
name = "openfhe_julia_int128"
8+
version = v"0.3.6"
9+
10+
git_hash = "4939f1dd11ae2640b5bb397f731df8ef94307e74"
11+
12+
sources, script, platforms, products, dependencies = prepare_openfhe_julia_build(name, git_hash)
13+
14+
push!(dependencies, Dependency(PackageSpec(name="OpenFHE_int128_jll", uuid="a89a0bdd-1663-5679-8b21-c3a5388322bc"); compat="1.2.3"))
15+
16+
# Build the tarballs, and possibly a `build.jl` as well.
17+
build_tarballs(ARGS, name, version, sources, script, platforms, products, dependencies;
18+
julia_compat="1.6", preferred_gcc_version = v"9")

0 commit comments

Comments
 (0)