Skip to content

Commit

Permalink
Support Zig-based cross compilation
Browse files Browse the repository at this point in the history
  • Loading branch information
k0kubun committed Aug 8, 2022
1 parent 1b73044 commit 5fbb999
Showing 1 changed file with 19 additions and 12 deletions.
31 changes: 19 additions & 12 deletions mrbgem.rake
Original file line number Diff line number Diff line change
Expand Up @@ -5,21 +5,24 @@ MRuby::Gem::Specification.new('mruby-yaml') do |spec|
spec.description = 'YAML gem for mruby'
spec.homepage = 'https://github.com/mrbgems/mruby-yaml'

spec.linker.libraries << 'yaml'

require 'open3'
def run_command env, command
STDOUT.sync = true
puts "build: [exec] #{command}"
Open3.popen2e(env, command) do |stdin, stdout, thread|
print stdout.read
fail "#{command} failed" if thread.value != 0
end
# Workaround for https://github.com/ziglang/zig/issues/4986
use_zig = spec.build.cc.command.start_with?('zig ')
unless use_zig
spec.linker.libraries << 'yaml'
end

use_system_library = ENV.fetch('MRUBY_YAML_USE_SYSTEM_LIBRARY', '') != ''

unless use_system_library
require 'open3'
def run_command env, command
STDOUT.sync = true
puts "build: [exec] #{command}"
Open3.popen2e(env, command) do |stdin, stdout, thread|
print stdout.read
fail "#{command} failed" if thread.value != 0
end
end

yaml_dir = File.join(build_dir, 'libyaml')
yaml_base_dir = File.join(spec.dir, 'vendor', 'libyaml')

Expand Down Expand Up @@ -64,6 +67,10 @@ MRuby::Gem::Specification.new('mruby-yaml') do |spec|
end

spec.cc.include_paths << "#{yaml_dir}/build/include"
spec.linker.library_paths << "#{yaml_dir}/build/lib/"
if use_zig
spec.linker.flags << "#{yaml_dir}/build/lib/libyaml.a"
else
spec.linker.library_paths << "#{yaml_dir}/build/lib/"
end
end
end

0 comments on commit 5fbb999

Please sign in to comment.