Module: WGPU::Native::Distribution
- Defined in:
- lib/wgpu/native/distribution.rb
Constant Summary collapse
- VERSION =
"v27.0.4.0"- RELEASE_BASE_URL =
"https://github.com/gfx-rs/wgpu-native/releases/download/#{VERSION}"- VERSION_COMPONENTS =
VERSION.delete_prefix("v").split(".").map { |part| Integer(part, 10) }.freeze
- ENCODED_VERSION =
wgpuGetVersion packs vMAJOR.MINOR.PATCH.BUILD into four big-endian bytes.
VERSION_COMPONENTS.reduce(0) { |encoded, part| (encoded << 8) | part }
- UNIMPLEMENTED_CAPABILITIES =
{ compilation_info: [VERSION].freeze, buffer_map_state: [VERSION].freeze, pipeline_async: [VERSION].freeze }.freeze
- ARTIFACTS =
[ { pattern: /x86_64-linux/, archive: "wgpu-linux-x86_64-release.zip", library: "libwgpu_native.so", sha256: "271481ef76fbf3ea09631a6079e9493636ecf813cd9c92306c44a1a452991ba1" }, { pattern: /aarch64-linux/, archive: "wgpu-linux-aarch64-release.zip", library: "libwgpu_native.so", sha256: "a2f22248200997b69373273b10d50a58164f6ed840877289f3e46bff317b134e" }, { pattern: /x86_64-darwin/, archive: "wgpu-macos-x86_64-release.zip", library: "libwgpu_native.dylib", sha256: "660fe9be59b555ec1d7c839e5cf8b6c71762938af61ab444a7a58dd87970dba2" }, { pattern: /arm64-darwin/, archive: "wgpu-macos-aarch64-release.zip", library: "libwgpu_native.dylib", sha256: "15367c26fdbe6892db35007d39f3883593384e777360b70e6bd704cb5dedde53" }, { pattern: /(?:x64|x86_64)-(?:mingw|mswin)/, archive: "wgpu-windows-x86_64-msvc-release.zip", library: "wgpu_native.dll", sha256: "f14ca334b4d253881bde2605bd147f332178d705f56fbd74f81458797c77fce1" } ].map(&:freeze).freeze
Class Method Summary collapse
-
.artifact_for(platform = RUBY_PLATFORM) ⇒ Hash
Selects the native release artifact for a Ruby platform.
-
.cache_directories(env: ENV, home: Dir.home, host_os: ) ⇒ Array<String>
Returns cache directories in lookup order.
-
.capability_implemented?(name) ⇒ Boolean
Reports whether a native capability is implemented by the pinned release.
-
.legacy_cache_dir(home: Dir.home) ⇒ String
Returns the legacy versioned cache directory.
-
.library_paths(platform: RUBY_PLATFORM, env: ENV, home: Dir.home, host_os: ) ⇒ Array<String>
Returns candidate cached library paths for a platform.
-
.primary_cache_dir(env: ENV, home: Dir.home, host_os: ) ⇒ String
Returns the preferred versioned native-library cache directory.
-
.release_url(artifact) ⇒ String
Builds the download URL for an artifact entry.
-
.unsupported_platform_message(platform) ⇒ String
Builds an actionable unsupported-platform message.
-
.version_string(encoded_version) ⇒ String
Decodes the packed native version into a release tag.
Class Method Details
.artifact_for(platform = RUBY_PLATFORM) ⇒ Hash
Selects the native release artifact for a Ruby platform.
61 62 63 64 65 66 67 68 |
# File 'lib/wgpu/native/distribution.rb', line 61 def artifact_for(platform = RUBY_PLATFORM) raise LoadError, (platform) if platform.include?("musl") artifact = ARTIFACTS.find { |candidate| candidate[:pattern].match?(platform) } return artifact if artifact raise LoadError, (platform) end |
.cache_directories(env: ENV, home: Dir.home, host_os: ) ⇒ Array<String>
Returns cache directories in lookup order.
100 101 102 |
# File 'lib/wgpu/native/distribution.rb', line 100 def cache_directories(env: ENV, home: Dir.home, host_os: RbConfig::CONFIG["host_os"]) [primary_cache_dir(env:, home:, host_os:), legacy_cache_dir(home:)].uniq end |
.capability_implemented?(name) ⇒ Boolean
Reports whether a native capability is implemented by the pinned release.
138 139 140 |
# File 'lib/wgpu/native/distribution.rb', line 138 def capability_implemented?(name) !UNIMPLEMENTED_CAPABILITIES.fetch(name, []).include?(VERSION) end |
.legacy_cache_dir(home: Dir.home) ⇒ String
Returns the legacy versioned cache directory.
90 91 92 |
# File 'lib/wgpu/native/distribution.rb', line 90 def legacy_cache_dir(home: Dir.home) File.join(File.(home), ".cache", "wgpu-ruby", VERSION) end |
.library_paths(platform: RUBY_PLATFORM, env: ENV, home: Dir.home, host_os: ) ⇒ Array<String>
Returns candidate cached library paths for a platform.
112 113 114 115 116 |
# File 'lib/wgpu/native/distribution.rb', line 112 def library_paths(platform: RUBY_PLATFORM, env: ENV, home: Dir.home, host_os: RbConfig::CONFIG["host_os"]) library = artifact_for(platform)[:library] cache_directories(env:, home:, host_os:).map { |directory| File.join(directory, "lib", library) } end |
.primary_cache_dir(env: ENV, home: Dir.home, host_os: ) ⇒ String
Returns the preferred versioned native-library cache directory.
76 77 78 79 80 81 82 83 84 |
# File 'lib/wgpu/native/distribution.rb', line 76 def primary_cache_dir(env: ENV, home: Dir.home, host_os: RbConfig::CONFIG["host_os"]) override = present_value(env["WGPU_CACHE_DIR"]) return File.join(File.(override), VERSION) if override xdg_cache = present_value(env["XDG_CACHE_HOME"]) return File.join(File.(xdg_cache), "wgpu-ruby", VERSION) if xdg_cache File.join(default_cache_base(env:, home:, host_os:), "wgpu-ruby", VERSION) end |
.release_url(artifact) ⇒ String
Builds the download URL for an artifact entry.
122 123 124 |
# File 'lib/wgpu/native/distribution.rb', line 122 def release_url(artifact) "#{RELEASE_BASE_URL}/#{artifact.fetch(:archive)}" end |
.unsupported_platform_message(platform) ⇒ String
Builds an actionable unsupported-platform message.
146 147 148 149 150 151 152 153 |
# File 'lib/wgpu/native/distribution.rb', line 146 def (platform) supported = ARTIFACTS.map { |artifact| artifact[:pattern].inspect }.join(", ") <<~MESSAGE.chomp Unsupported platform: #{platform} Supported 64-bit platforms: #{supported} Build wgpu-native for this host and set WGPU_LIB_PATH to the shared library. MESSAGE end |
.version_string(encoded_version) ⇒ String
Decodes the packed native version into a release tag.
130 131 132 133 |
# File 'lib/wgpu/native/distribution.rb', line 130 def version_string(encoded_version) components = [24, 16, 8, 0].map { |shift| (encoded_version >> shift) & 0xFF } "v#{components.join(".")}" end |