Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Trying to get LibUI to work on more platforms by simply installing a Gem #68

Merged
merged 3 commits into from
Nov 7, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
157 changes: 85 additions & 72 deletions Rakefile
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,14 @@ def puts(str)
Kernel.puts("[Rake] #{str}")
end

platforms = %w[x86_64-linux x86_64-darwin arm64-darwin x64-mingw]
platforms = %w[
x86_64-linux
aarch64-linux
x86_64-darwin
arm64-darwin
x64-mingw
x86-mingw32
]

task :build_platform do
require 'fileutils'
Expand All @@ -41,11 +48,6 @@ task :release_platform do
end
end

# Give platform specific file extension.
def lib_name
"libui.#{RbConfig::CONFIG['SOEXT']}"
end

def url_libui_ng_source_zip(commit_hash = 'master')
"https://github.com/libui-ng/libui-ng/archive/#{commit_hash}.zip"
end
Expand Down Expand Up @@ -156,9 +158,7 @@ def build_libui_ng(commit_hash)
require 'open3'

FileUtils.mkdir_p(File.expand_path('vendor', __dir__))
target_path = File.expand_path("vendor/#{lib_name}", __dir__)

# check_file_exist(target_path, sha256sum_expected)
target_path = File.expand_path("vendor/libui.#{RbConfig::CONFIG['host_cpu']}.#{RbConfig::CONFIG['SOEXT']}", __dir__)

Dir.mktmpdir do |dir|
Dir.chdir(dir) do
Expand Down Expand Up @@ -219,7 +219,7 @@ def build_libui_ng(commit_hash)

puts "Saved #{build_log_path}"

path = "build/meson-out/#{lib_name}"
path = "build/meson-out/libui.#{RbConfig::CONFIG['SOEXT']}"

if File.exist?(path)
puts "Successfully built #{path}"
Expand Down Expand Up @@ -247,24 +247,24 @@ def build_libui_ng(commit_hash)
end

namespace 'vendor' do
namespace 'libui-ng' do
desc 'Build libui-ng latest master [commit hash]'
task 'build', 'hash' do |_, args|
s = build_libui_ng(args['hash'])
abort if s == false
end
desc 'Build libui-ng latest master [commit hash]'
task 'build', 'hash' do |_, args|
s = build_libui_ng(args['hash'])
abort if s == false
end

desc 'Download latest dev build for Ubuntu to vendor directory'
namespace 'libui-ng' do
desc 'Download latest official pre-build for Ubuntu to vendor directory'
task :ubuntu_x64 do
download_libui_ng_nightly(
'libui.so',
'libui.x86_64.so',
'builddir/meson-out/libui.so',
'Ubuntu-x64-shared-debug.zip'
)
end

desc 'Download latest dev build for Mac to vendor directory'
task :mac do
desc 'Download latest official pre-build for Mac to vendor directory'
task :macos do
download_libui_ng_nightly(
'libui.dylib',
'builddir/meson-out/libui.dylib',
Expand All @@ -273,63 +273,76 @@ namespace 'vendor' do
end
end

namespace 'kojix2' do
desc 'Download kojix2 pre-build for Ubuntu to vendor directory'
task :ubuntu_x64 do
download_kojix2_libui_ng_nightly(
'libui.so',
'builddir/meson-out/libui.so',
'Ubuntu-x64-shared-release.zip'
)
end
desc 'Download pre-build for Ubuntu to vendor directory'
task :ubuntu_x64 do
download_kojix2_libui_ng_nightly(
'libui.x86_64.so',
'builddir/meson-out/libui.so',
'Ubuntu-x64-shared-release.zip'
)
end

desc 'Download kojix2 pre-build for Raspbian to vendor directory'
task :raspbian_64 do
download_kojix2_libui_ng_nightly(
'libui.so',
'builddir/meson-out/libui.so',
'Raspbian-aarch64-shared-release.zip'
)
end
desc 'Download pre-build for Raspbian to vendor directory'
task :raspbian_aarch64 do
download_kojix2_libui_ng_nightly(
'libui.aarch64.so',
'builddir/meson-out/libui.so',
'Raspbian-aarch64-shared-release.zip'
)
end

desc 'Download kojix2 pre-build for Mac to vendor directory'
task :mac do
download_kojix2_libui_ng_nightly(
'libui.dylib',
'builddir/meson-out/libui.dylib',
'macOS-x64-shared-release.zip'
)
end
desc 'Download pre-build for Mac to vendor directory'
task :macos_x64 do
download_kojix2_libui_ng_nightly(
'libui.x86_64.dylib',
'builddir/meson-out/libui.dylib',
'macOS-x64-shared-release.zip'
)
end

desc 'Download kojix2 pre-build for Windows to vendor directory'
task :windows_x64 do
download_kojix2_libui_ng_nightly(
'libui.dll',
'builddir/meson-out/libui.dll',
'Win-x64-shared-release.zip'
)
end
desc 'Download pre-build for Mac to vendor directory'
task :macos_arm64 do
download_kojix2_libui_ng_nightly(
'libui.arm64.dylib',
'builddir/meson-out/libui.dylib',
'macOS-x64-shared-release.zip'
)
end

desc 'Download kojix2 pre-build for Windows to vendor directory'
task :windows_x86 do
download_kojix2_libui_ng_nightly(
'libui.dll',
'builddir/meson-out/libui.dll',
'Win-x86-shared-release.zip'
)
end
desc 'Download pre-build for Windows to vendor directory'
task :windows_x64 do
download_kojix2_libui_ng_nightly(
'libui.x64.dll',
'builddir/meson-out/libui.dll',
'Win-x64-shared-release.zip'
)
end

desc 'Download kojix2 pre-build for your platform to vendor directory'
task :auto do
# TODO: Add support for other platforms
case RUBY_PLATFORM
when /linux/
Rake::Task['vendor:kojix2:ubuntu_x64'].invoke
when /darwin/
Rake::Task['vendor:kojix2:mac'].invoke
when /mingw/
Rake::Task['vendor:kojix2:windows_x64'].invoke
end
desc 'Download pre-build for Windows to vendor directory'
task :windows_x86 do
download_kojix2_libui_ng_nightly(
'libui.x86.dll',
'builddir/meson-out/libui.dll',
'Win-x86-shared-release.zip'
)
end

# desc 'Download pre-build for your platform to vendor directory'
# task :auto do
# # TODO: Add support for other platforms
# case RUBY_PLATFORM
# when /linux/
# Rake::Task['vendor:kojix2:ubuntu_x64'].invoke
# when /darwin/
# Rake::Task['vendor:kojix2:mac'].invoke
# when /mingw/
# Rake::Task['vendor:kojix2:windows_x64'].invoke
# end
# end

task :clean do
(Dir['vendor/*'] - Dir['vendor/{LICENSE,README}.md']).each do |f|
FileUtils.rm_rf(f)
end
end
end
22 changes: 15 additions & 7 deletions lib/libui.rb
Original file line number Diff line number Diff line change
Expand Up @@ -9,13 +9,21 @@ class << self
attr_accessor :ffi_lib
end

lib_name = "libui.#{RbConfig::CONFIG['SOEXT']}"

self.ffi_lib = if ENV['LIBUIDIR'] && !ENV['LIBUIDIR'].empty?
File.expand_path(lib_name, ENV['LIBUIDIR'])
else
File.expand_path("../vendor/#{lib_name}", __dir__)
end
lib_name = [
"libui.#{RbConfig::CONFIG['host_cpu']}.#{RbConfig::CONFIG['SOEXT']}",
"libui.#{RbConfig::CONFIG['SOEXT']}",
]

self.ffi_lib = \
if ENV['LIBUIDIR'] && !ENV['LIBUIDIR'].empty?
lib_name.lazy
.map { |name| File.expand_path(name, ENV['LIBUIDIR']) }
.find { |path| File.exist?(path) }
else
lib_name.lazy
.map { |name| File.expand_path("../vendor/#{name}", __dir__) }
.find { |path| File.exist?(path) }
end

require_relative 'libui/ffi'
require_relative 'libui/libui_base'
Expand Down
24 changes: 14 additions & 10 deletions libui.gemspec
Original file line number Diff line number Diff line change
Expand Up @@ -10,22 +10,26 @@ Gem::Specification.new do |spec|
spec.authors = ['kojix2']
spec.email = ['2xijok@gmail.com']

spec.required_ruby_version = '>= 2.5'

spec.files = Dir['*.{md,txt}', '{lib}/**/*', 'vendor/{LICENSE,README}.md']
spec.require_paths = 'lib'

spec.files = Dir['*.{md,txt}', '{lib}/**/*', 'vendor/{LICENSE,README}.md']
spec.required_ruby_version = '>= 2.5'

case spec.platform.to_s
when 'x86_64-linux'
spec.files << 'vendor/libui.so'
# when "aarch64-linux"
# spec.files << "vendor/libui.so"
when 'x86_64-darwin', 'arm64-darwin'
spec.files << 'vendor/libui.dylib'
spec.files << 'vendor/libui.x86_64.so'
when 'aarch64-linux'
spec.files << 'vendor/libui.aarch64.so' # raspberry pi
when 'x86_64-darwin'
spec.files << 'vendor/libui.x86_64.dylib' # universal binary
when 'arm64-darwin'
spec.files << 'vendor/libui.arm64.dylib' # universal binary
when 'x64-mingw'
spec.files << 'vendor/libui.dll'
spec.files << 'vendor/libui.x64.dll'
when 'x86-mingw32'
spec.files << 'vendor/libui.x86.dll'
else
spec.files.concat(Dir['vendor/*.{dll,dylib,so}'])
spec.files.concat(Dir['vendor/*.{dll,dylib,so}']) # all
end

# spec.add_dependency 'fiddle'
Expand Down