Skip to content

Commit d86fd79

Browse files
committed
CUDA_Compiler_jll build 0.1.0+0
1 parent b656034 commit d86fd79

16 files changed

+750
-0
lines changed

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
override/

.pkg/platform_augmentation.jl

Lines changed: 129 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,129 @@
1+
using Base.BinaryPlatforms
2+
3+
using Libdl
4+
5+
# before loading CUDA_Driver_jll, try to find out where the system driver is located.
6+
let
7+
name = if Sys.iswindows()
8+
Libdl.find_library("nvcuda")
9+
else
10+
Libdl.find_library(["libcuda.so.1", "libcuda.so"])
11+
end
12+
13+
# if we've found a system driver, put a dependency on it,
14+
# so that we get recompiled if the driver changes.
15+
if name != ""
16+
handle = Libdl.dlopen(name)
17+
path = Libdl.dlpath(handle)
18+
Libdl.dlclose(handle)
19+
20+
@debug "Adding include dependency on $path"
21+
Base.include_dependency(path)
22+
end
23+
end
24+
25+
# platform augmentation hooks run in an ill-defined environment, where:
26+
# - CUDA_Driver_jll may not be available
27+
# - the wrong version of CUDA_Driver_jll may be available
28+
#
29+
# because of that, we need to be very careful about using that dependency.
30+
# currently, we support all existing versions of CUDA_Driver_jll, but if we
31+
# ever need to introduce a breaking change, we'll need some way to identify
32+
# the version of CUDA_Driver_jll from its module (e.g. a global constant).
33+
#
34+
# ref: https://github.com/JuliaLang/Pkg.jl/issues/3225
35+
# can't use Preferences for the same reason
36+
try
37+
using CUDA_Driver_jll
38+
catch err
39+
# we'll handle this below
40+
end
41+
42+
# get the version of the available CUDA driver by querying either CUDA_Driver_jll's
43+
# driver, or the system driver if CUDA_Driver_jll is not available
44+
function get_driver_version()
45+
if !@isdefined(CUDA_Driver_jll)
46+
# driver JLL not available because we're in the middle of installing packages
47+
@debug "CUDA_Driver_jll not available; not selecting an artifact"
48+
return nothing
49+
end
50+
51+
cuda_driver = if CUDA_Driver_jll.is_available()
52+
@debug "Using CUDA_Driver_jll for driver discovery"
53+
54+
if !isdefined(CUDA_Driver_jll, :libcuda) || # [email protected]
55+
isnothing(CUDA_Driver_jll.libcuda) # https://github.com/JuliaLang/julia/issues/48999
56+
# no driver found
57+
@debug "CUDA_Driver_jll reports no driver found"
58+
return nothing
59+
end
60+
CUDA_Driver_jll.libcuda
61+
else
62+
# CUDA_Driver_jll only kicks in for supported platforms, so fall back to
63+
# a system search if the artifact isn't available (JLLWrappers.jl#50)
64+
@debug "CUDA_Driver_jll unavailable, falling back to system search"
65+
66+
driver_name = if Sys.iswindows()
67+
Libdl.find_library("nvcuda")
68+
else
69+
Libdl.find_library(["libcuda.so.1", "libcuda.so"])
70+
end
71+
if driver_name == ""
72+
# no driver found
73+
@debug "CUDA_Driver_jll unavailable, and no system CUDA driver found"
74+
return nothing
75+
end
76+
77+
driver_name
78+
end
79+
@debug "Found CUDA driver at '$cuda_driver'"
80+
81+
# minimal API call wrappers we need
82+
function cuDriverGetVersion(library_handle)
83+
function_handle = Libdl.dlsym(library_handle, "cuDriverGetVersion"; throw_error=false)
84+
if function_handle === nothing
85+
@debug "Driver library seems invalid (does not contain 'cuDriverGetVersion')"
86+
return nothing
87+
end
88+
version_ref = Ref{Cint}()
89+
status = ccall(function_handle, Cint, (Ptr{Cint},), version_ref)
90+
if status != 0
91+
@debug "Call to 'cuDriverGetVersion' failed with status $status"
92+
return nothing
93+
end
94+
major, ver = divrem(version_ref[], 1000)
95+
minor, patch = divrem(ver, 10)
96+
return VersionNumber(major, minor, patch)
97+
end
98+
99+
driver_handle = Libdl.dlopen(cuda_driver; throw_error=false)
100+
if driver_handle === nothing
101+
@debug "Failed to load CUDA driver"
102+
return nothing
103+
end
104+
105+
cuDriverGetVersion(driver_handle)
106+
end
107+
108+
# returns the value for the "cuda" tag we should use in the platform ("$MAJOR")
109+
# or nothing if no CUDA driver was found.
110+
function cuda_driver_tag()
111+
cuda_driver = get_driver_version()
112+
if cuda_driver === nothing
113+
@debug "Failed to query CUDA driver version"
114+
return nothing
115+
end
116+
@debug "CUDA driver version: $cuda_driver"
117+
118+
"$(cuda_driver.major)"
119+
end
120+
121+
function augment_platform!(platform::Platform)
122+
if !haskey(platform, "cuda")
123+
platform["cuda"] = something(cuda_driver_tag(), "none")
124+
# XXX: use "none" when we couldn't find a compatible toolkit.
125+
# we can't just leave off the platform tag or Pkg would select *any* artifact.
126+
end
127+
128+
return platform
129+
end

.pkg/select_artifacts.jl

Lines changed: 134 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,134 @@
1+
push!(Base.LOAD_PATH, dirname(@__DIR__))
2+
3+
using TOML, Artifacts, Base.BinaryPlatforms
4+
include("./platform_augmentation.jl")
5+
artifacts_toml = joinpath(dirname(@__DIR__), "Artifacts.toml")
6+
7+
# Update Base.parse to support riscv64, needed for Julia <1.12
8+
@static if !haskey(BinaryPlatforms.arch_mapping, "riscv64")
9+
10+
BinaryPlatforms.arch_mapping["riscv64"] = "(rv64|riscv64)"
11+
12+
function bbparse(::Type{Platform}, triplet::AbstractString; validate_strict::Bool = false)
13+
arch_mapping = BinaryPlatforms.arch_mapping
14+
os_mapping = BinaryPlatforms.os_mapping
15+
libc_mapping = BinaryPlatforms.libc_mapping
16+
call_abi_mapping = BinaryPlatforms.call_abi_mapping
17+
libgfortran_version_mapping = BinaryPlatforms.libgfortran_version_mapping
18+
cxxstring_abi_mapping = BinaryPlatforms.cxxstring_abi_mapping
19+
libstdcxx_version_mapping = BinaryPlatforms.libstdcxx_version_mapping
20+
21+
# Helper function to collapse dictionary of mappings down into a regex of
22+
# named capture groups joined by "|" operators
23+
c(mapping) = string("(",join(["(?<$k>$v)" for (k, v) in mapping], "|"), ")")
24+
25+
# We're going to build a mondo regex here to parse everything:
26+
triplet_regex = Regex(string(
27+
"^",
28+
# First, the core triplet; arch/os/libc/call_abi
29+
c(arch_mapping),
30+
c(os_mapping),
31+
c(libc_mapping),
32+
c(call_abi_mapping),
33+
# Next, optional things, like libgfortran/libstdcxx/cxxstring abi
34+
c(libgfortran_version_mapping),
35+
c(cxxstring_abi_mapping),
36+
c(libstdcxx_version_mapping),
37+
# Finally, the catch-all for extended tags
38+
"(?<tags>(?:-[^-]+\\+[^-]+)*)?",
39+
"\$",
40+
))
41+
42+
m = match(triplet_regex, triplet)
43+
if m !== nothing
44+
# Helper function to find the single named field within the giant regex
45+
# that is not `nothing` for each mapping we give it.
46+
get_field(m, mapping) = begin
47+
for k in keys(mapping)
48+
if m[k] !== nothing
49+
# Convert our sentinel `nothing` values to actual `nothing`
50+
if endswith(k, "_nothing")
51+
return nothing
52+
end
53+
# Convert libgfortran/libstdcxx version numbers
54+
if startswith(k, "libgfortran")
55+
return VersionNumber(parse(Int,k[12:end]))
56+
elseif startswith(k, "libstdcxx")
57+
return VersionNumber(3, 4, parse(Int,m[k][11:end]))
58+
else
59+
return k
60+
end
61+
end
62+
end
63+
end
64+
65+
# Extract the information we're interested in:
66+
arch = get_field(m, arch_mapping)
67+
os = get_field(m, os_mapping)
68+
libc = get_field(m, libc_mapping)
69+
call_abi = get_field(m, call_abi_mapping)
70+
libgfortran_version = get_field(m, libgfortran_version_mapping)
71+
libstdcxx_version = get_field(m, libstdcxx_version_mapping)
72+
cxxstring_abi = get_field(m, cxxstring_abi_mapping)
73+
function split_tags(tagstr)
74+
tag_fields = filter(!isempty, split(tagstr, "-"))
75+
if isempty(tag_fields)
76+
return Pair{String,String}[]
77+
end
78+
return map(v -> Symbol(v[1]) => v[2], split.(tag_fields, "+"))
79+
end
80+
tags = split_tags(m["tags"])
81+
82+
# Special parsing of os version number, if any exists
83+
function extract_os_version(os_name, pattern)
84+
m_osvn = match(pattern, m[os_name])
85+
if m_osvn !== nothing
86+
return VersionNumber(m_osvn.captures[1])
87+
end
88+
return nothing
89+
end
90+
os_version = nothing
91+
if os == "macos"
92+
os_version = extract_os_version("macos", r".*darwin([\d.]+)"sa)
93+
end
94+
if os == "freebsd"
95+
os_version = extract_os_version("freebsd", r".*freebsd([\d.]+)"sa)
96+
end
97+
if os == "openbsd"
98+
os_version = extract_os_version("openbsd", r".*openbsd([\d.]+)"sa)
99+
end
100+
101+
return Platform(
102+
arch, os;
103+
validate_strict,
104+
libc,
105+
call_abi,
106+
libgfortran_version,
107+
cxxstring_abi,
108+
libstdcxx_version,
109+
os_version,
110+
tags...,
111+
)
112+
end
113+
throw(ArgumentError("Platform `$(triplet)` is not an officially supported platform"))
114+
end
115+
116+
else
117+
# riscv64 is supported, all is fine
118+
119+
const bbparse = parse
120+
121+
end
122+
123+
124+
# Get "target triplet" from ARGS, if given (defaulting to the host triplet otherwise)
125+
target_triplet = get(ARGS, 1, Base.BinaryPlatforms.host_triplet())
126+
127+
# Augment this platform object with any special tags we require
128+
platform = augment_platform!(HostPlatform(bbparse(Platform, target_triplet)))
129+
130+
# Select all downloadable artifacts that match that platform
131+
artifacts = select_downloadable_artifacts(artifacts_toml; platform, include_lazy=true)
132+
133+
# Output the result to `stdout` as a TOML dictionary
134+
TOML.print(stdout, artifacts)

Artifacts.toml

Lines changed: 90 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,90 @@
1+
[[CUDA_Compiler]]
2+
arch = "x86_64"
3+
cuda = "11"
4+
git-tree-sha1 = "303252a294c2ec14078c4325a3f56a595f295d0d"
5+
lazy = true
6+
libc = "glibc"
7+
os = "linux"
8+
9+
[[CUDA_Compiler.download]]
10+
sha256 = "a249766eebae37d103e45c90c331784a3d26633194b2facb259c6fcb29f8ae03"
11+
url = "https://github.com/JuliaBinaryWrappers/CUDA_Compiler_jll.jl/releases/download/CUDA_Compiler-v0.1.0+0/CUDA_Compiler.v0.1.0.x86_64-linux-gnu-cuda+11.tar.gz"
12+
[[CUDA_Compiler]]
13+
arch = "aarch64"
14+
cuda = "11"
15+
cuda_platform = "jetson"
16+
git-tree-sha1 = "c612150991b9cd602b791d8f64d15585ee5065d6"
17+
lazy = true
18+
libc = "glibc"
19+
os = "linux"
20+
21+
[[CUDA_Compiler.download]]
22+
sha256 = "4b89ab924dae5e44204fdeedb814fb603f3f8f26fe962d92f212774787744841"
23+
url = "https://github.com/JuliaBinaryWrappers/CUDA_Compiler_jll.jl/releases/download/CUDA_Compiler-v0.1.0+0/CUDA_Compiler.v0.1.0.aarch64-linux-gnu-cuda_platform+jetson-cuda+11.tar.gz"
24+
[[CUDA_Compiler]]
25+
arch = "aarch64"
26+
cuda = "11"
27+
cuda_platform = "sbsa"
28+
git-tree-sha1 = "aa9adec8c998c154d0e27a81ea7e1b769275549a"
29+
lazy = true
30+
libc = "glibc"
31+
os = "linux"
32+
33+
[[CUDA_Compiler.download]]
34+
sha256 = "fc9c1cd6a93c700f827b1dd484bff0ca2b5ea54e9b1f0bad70bea8517ae1b275"
35+
url = "https://github.com/JuliaBinaryWrappers/CUDA_Compiler_jll.jl/releases/download/CUDA_Compiler-v0.1.0+0/CUDA_Compiler.v0.1.0.aarch64-linux-gnu-cuda_platform+sbsa-cuda+11.tar.gz"
36+
[[CUDA_Compiler]]
37+
arch = "x86_64"
38+
cuda = "11"
39+
git-tree-sha1 = "153f9b6dd687301732936ebcd8ee7e759ab56806"
40+
lazy = true
41+
os = "windows"
42+
43+
[[CUDA_Compiler.download]]
44+
sha256 = "4da6c51fab2e0b5a31a5d13fcad2d635691d6f107875914b6d6510879472b2fb"
45+
url = "https://github.com/JuliaBinaryWrappers/CUDA_Compiler_jll.jl/releases/download/CUDA_Compiler-v0.1.0+0/CUDA_Compiler.v0.1.0.x86_64-w64-mingw32-cuda+11.tar.gz"
46+
[[CUDA_Compiler]]
47+
arch = "x86_64"
48+
cuda = "12"
49+
git-tree-sha1 = "6283886c5dd600750885a23bff8d37f687172633"
50+
lazy = true
51+
libc = "glibc"
52+
os = "linux"
53+
54+
[[CUDA_Compiler.download]]
55+
sha256 = "bdc82d97b73b7e0e5369f40ca4d9813b314578292a750ce09977280d11eb8da3"
56+
url = "https://github.com/JuliaBinaryWrappers/CUDA_Compiler_jll.jl/releases/download/CUDA_Compiler-v0.1.0+0/CUDA_Compiler.v0.1.0.x86_64-linux-gnu-cuda+12.tar.gz"
57+
[[CUDA_Compiler]]
58+
arch = "aarch64"
59+
cuda = "12"
60+
cuda_platform = "jetson"
61+
git-tree-sha1 = "40f3ae67ed1f3877f73803c65dbc4c1d0717c09b"
62+
lazy = true
63+
libc = "glibc"
64+
os = "linux"
65+
66+
[[CUDA_Compiler.download]]
67+
sha256 = "61a5418b016dd9965eba530186fe68f4b041ef059d2fbb3c24e0ddb235abcdca"
68+
url = "https://github.com/JuliaBinaryWrappers/CUDA_Compiler_jll.jl/releases/download/CUDA_Compiler-v0.1.0+0/CUDA_Compiler.v0.1.0.aarch64-linux-gnu-cuda_platform+jetson-cuda+12.tar.gz"
69+
[[CUDA_Compiler]]
70+
arch = "aarch64"
71+
cuda = "12"
72+
cuda_platform = "sbsa"
73+
git-tree-sha1 = "20ed9b0da384988be731fd3428525cd1433a72b6"
74+
lazy = true
75+
libc = "glibc"
76+
os = "linux"
77+
78+
[[CUDA_Compiler.download]]
79+
sha256 = "07d88f979ce98f74210a90a690b1bb07d7de22455f3ff42cb93597f145ec812d"
80+
url = "https://github.com/JuliaBinaryWrappers/CUDA_Compiler_jll.jl/releases/download/CUDA_Compiler-v0.1.0+0/CUDA_Compiler.v0.1.0.aarch64-linux-gnu-cuda_platform+sbsa-cuda+12.tar.gz"
81+
[[CUDA_Compiler]]
82+
arch = "x86_64"
83+
cuda = "12"
84+
git-tree-sha1 = "e317e3a5f402be1ed606645018aa67d772284ed2"
85+
lazy = true
86+
os = "windows"
87+
88+
[[CUDA_Compiler.download]]
89+
sha256 = "528c37bc3d53b69446e172381c7978c791731037ed15d4bb7a8a345fac005a54"
90+
url = "https://github.com/JuliaBinaryWrappers/CUDA_Compiler_jll.jl/releases/download/CUDA_Compiler-v0.1.0+0/CUDA_Compiler.v0.1.0.x86_64-w64-mingw32-cuda+12.tar.gz"

LICENSE

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,11 @@
1+
The Julia source code within this repository (all files under `src/`) are
2+
released under the terms of the MIT "Expat" License, the text of which is
3+
included below. This license does not apply to the binary package wrapped by
4+
this Julia package and automatically downloaded by the Julia package manager
5+
upon installing this wrapper package. The binary package's license is shipped
6+
alongside the binary itself and can be found within the
7+
`share/licenses/CUDA_Compiler` directory within its prefix.
8+
19
MIT License
210

311
Copyright (c) 2025 JuliaBinaryWrappers

Project.toml

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
name = "CUDA_Compiler_jll"
2+
uuid = "d1e2174e-dfdc-576e-b43e-73b79eb1aca8"
3+
version = "0.1.0+0"
4+
5+
[deps]
6+
JLLWrappers = "692b3bcd-3c85-4b1f-b108-f13ce0eb3210"
7+
CUDA_Driver_jll = "4ee394cb-3365-5eb0-8335-949819d2adfc"
8+
LazyArtifacts = "4af54fe1-eca0-43a8-85a7-787d91b784e3"
9+
Libdl = "8f399da3-3557-5675-b5ff-fb832c97cbdb"
10+
TOML = "fa267f1f-6049-4f14-aa54-33bafae1ed76"
11+
Artifacts = "56f22d72-fd6d-98f1-02f0-08ddc0907c33"
12+
13+
[compat]
14+
JLLWrappers = "1.7.0"
15+
julia = "1.6"
16+
CUDA_Driver_jll = "12"
17+
LazyArtifacts = "< 0.0.1, 1"
18+
Libdl = "< 0.0.1, 1"
19+
TOML = "< 0.0.1, 1"
20+
Artifacts = "< 0.0.1, 1"

0 commit comments

Comments
 (0)