Skip to content

Commit e299e72

Browse files
committed
add build for pocl_standalone
1 parent 7d3ca3d commit e299e72

File tree

2 files changed

+113
-2
lines changed

2 files changed

+113
-2
lines changed

P/pocl/pocl@7/common.jl

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
function build_script(standalone=false)
1+
function build_script(;standalone=false)
22
preheader = """
33
STANDALONE=$(standalone)
44
"""
@@ -83,6 +83,10 @@ function build_script(standalone=false)
8383
8484
if [[ "${STANDALONE}" == "true" ]]; then
8585
CMAKE_FLAGS+=(-DENABLE_ICD:BOOL=OFF)
86+
# prefix
87+
CMAKE_FLAGS+=(-DRENAME_POCL:BOOL=OFF)
88+
# Change the library name
89+
sed -i 's/set\(POCL_LIBRARY_NAME "OpenCL"\)/set\(POCL_LIBRARY_NAME "pocl_standalone"\)/g' CMakeLists.txt
8690
else
8791
# Build POCL as an dynamic library loaded by the OpenCL runtime
8892
CMAKE_FLAGS+=(-DENABLE_ICD:BOOL=ON)
@@ -164,7 +168,7 @@ function build_script(standalone=false)
164168
"""
165169
end
166170

167-
function init_block(standalone=false)
171+
function init_block(;standalone=false)
168172

169173
opencl = raw"""
170174
# Register this driver with OpenCL_jll

P/pocl_standalone/build_tarballs.jl

Lines changed: 107 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,107 @@
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+
using BinaryBuilder, Pkg
4+
using Base.BinaryPlatforms
5+
6+
const YGGDRASIL_DIR = "../.."
7+
include(joinpath(YGGDRASIL_DIR, "fancy_toys.jl"))
8+
9+
name = "pocl_standalone"
10+
version = v"7.0"
11+
12+
# Collection of sources required to complete build
13+
sources = [
14+
DirectorySource("../pocl/bundled"),
15+
GitSource("https://github.com/maleadt/pocl",
16+
"0d4baa74067db1f986fb7d70f40561c453be7b73") # v7.0-RC2 + #1918
17+
]
18+
19+
#=
20+
21+
PoCL wants to be linked against LLVM for run-time code generation, but also generates code
22+
at compile time using LLVM tools, so we need to carefully select which of the different
23+
builds of LLVM we need:
24+
25+
- the Dependency one, in $prefix: everything we want, but can't use it during the build as
26+
its binaries aren't executable here (hopefully they will be with BinaryBuilder2.jl).
27+
- the HostDependency one, in $host_prefix: can't emit code for the target, but provides an
28+
llvm-config returning the right flags. so we use it as the llvm-config during the build,
29+
spoofing the returned paths to the Dependency ones.
30+
- the native toolchain: supports the target, but can't be linked against, and provides the
31+
wrong LLVM flags. so we only use its tools during the build, requiring that the chosen
32+
LLVM version is compatible with the one used at run time, to avoid IR incompatibilities.
33+
34+
=#
35+
36+
# These are the platforms we will build for by default, unless further
37+
# platforms are passed in on the command line
38+
platforms = expand_cxxstring_abis(supported_platforms())
39+
## we don't build LLVM 15+ for i686-linux-musl.
40+
filter!(p -> !(arch(p) == "i686" && libc(p) == "musl"), platforms)
41+
## PoCL doesn't support 32-bit Windows
42+
filter!(p -> !(arch(p) == "i686" && os(p) == "windows"), platforms)
43+
44+
include("../pocl/common.jl")
45+
46+
# The products that we will ensure are always built
47+
# XXX: Rename this library to pocl_standalone?
48+
products = [
49+
LibraryProduct(["libpocl_standalone", "pocl_standalone"], :libpocl),
50+
ExecutableProduct("poclcc", :poclcc),
51+
]
52+
53+
# Dependencies that must be installed before this package can be built
54+
dependencies = [
55+
HostBuildDependency(PackageSpec(name="LLVM_full_jll", version=v"20.1.2")),
56+
BuildDependency(PackageSpec(name="LLVM_full_jll", version=v"20.1.2")),
57+
# Dependency("OpenCL_jll"),
58+
# BuildDependency("OpenCL_Headers_jll"),
59+
# Dependency("Hwloc_jll"),
60+
# only used at run time, but also detected by the build
61+
Dependency("SPIRV_LLVM_Translator_jll", compat="20.1"),
62+
Dependency("SPIRV_Tools_jll"),
63+
# only used at run time
64+
RuntimeDependency("Clang_unified_jll"),
65+
RuntimeDependency("LLD_unified_jll")
66+
]
67+
68+
builds = []
69+
for platform in platforms
70+
should_build_platform(triplet(platform)) || continue
71+
72+
# On macOS, we need to use a newer SDK to match the one LLVM was built with
73+
platform_sources = if Sys.isapple(platform)
74+
[sources;
75+
ArchiveSource("https://github.com/phracker/MacOSX-SDKs/releases/download/10.15/MacOSX10.14.sdk.tar.xz",
76+
"0f03869f72df8705b832910517b47dd5b79eb4e160512602f593ed243b28715f")]
77+
else
78+
sources
79+
end
80+
81+
# on Windows, we need to use a version of GCC that supports `.drectve -exclude-symbols`
82+
# or we run into export ordinal limits
83+
preferred_gcc_version = if Sys.iswindows(platform)
84+
v"13"
85+
else
86+
v"10"
87+
end
88+
89+
push!(builds, (; platform, sources=platform_sources, preferred_gcc_version))
90+
end
91+
92+
# don't allow `build_tarballs` to override platform selection based on ARGS.
93+
# we handle that ourselves by calling `should_build_platform`
94+
non_platform_ARGS = filter(arg -> startswith(arg, "--"), ARGS)
95+
96+
# `--register` and `--deploy` should only be passed to the final `build_tarballs` invocation
97+
non_reg_ARGS = filter(non_platform_ARGS) do arg
98+
arg != "--register" && !startswith(arg, "--deploy")
99+
end
100+
101+
for (i,build) in enumerate(builds)
102+
build_tarballs(i == lastindex(builds) ? non_platform_ARGS : non_reg_ARGS,
103+
name, version, build.sources, build_script(standalone=true),
104+
[build.platform], products, dependencies;
105+
build.preferred_gcc_version, preferred_llvm_version=v"20",
106+
julia_compat="1.6", init_block=init_block(standalone=true))
107+
end

0 commit comments

Comments
 (0)