diff --git a/.github/workflows/ubuntu.yml b/.github/workflows/ubuntu.yml index 774a814..4adc446 100644 --- a/.github/workflows/ubuntu.yml +++ b/.github/workflows/ubuntu.yml @@ -2,6 +2,12 @@ name: ubuntu on: [push, pull_request] jobs: gcc: + env: + # 'set-env' has been disabled by default because it's a + # potential security issue. See https://github.blog/changelog/2020-10-01-github-actions-deprecating-set-env-and-add-path-commands/. + # We re-enable it here for now because the problem does not + # appear to affect us. + ACTIONS_ALLOW_UNSECURE_COMMANDS: true runs-on: ubuntu-latest steps: - name: Install libraries diff --git a/.gitmodules b/.gitmodules new file mode 100644 index 0000000..e19f35d --- /dev/null +++ b/.gitmodules @@ -0,0 +1,3 @@ +[submodule "third_party/libyaml"] + path = third_party/libyaml + url = https://github.com/yaml/libyaml.git diff --git a/README.md b/README.md index 02442dc..af37d1b 100644 --- a/README.md +++ b/README.md @@ -28,6 +28,13 @@ else end ``` +### Getting libyaml + +If you have a compiled version of `libyaml` available on your system, you can use it by setting the environment variable `MRUBY_YAML_USE_SYSTEM_LIBRARY` to a non-empty value and ensuring your compiler can find the library. + +Otherwise, Rake will attempt to compile it from sources obtained from the offical `libyaml` GitHub repository. This requires that you have `autoconf` installed. + + ### Documentation #### `YAML.load(yaml_str)` diff --git a/mrbgem.rake b/mrbgem.rake index 27e5f87..9033520 100644 --- a/mrbgem.rake +++ b/mrbgem.rake @@ -20,18 +20,22 @@ MRuby::Gem::Specification.new('mruby-yaml') do |spec| use_system_library = ENV.fetch('MRUBY_YAML_USE_SYSTEM_LIBRARY', '') != '' unless use_system_library - yaml_version = "0.2.2" - yaml_dir = "#{build_dir}/yaml-#{yaml_version}" + yaml_base_dir = "libyaml" + yaml_dir = File.join(build_dir, yaml_base_dir) FileUtils.mkdir_p build_dir - if ! File.exists? yaml_dir - Dir.chdir(build_dir) do - e = {} - tar_zxf = (RUBY_PLATFORM.match(/solaris/) ? 'gzip -d | tar xf -' : 'tar zxf -') - run_command e, "curl -L https://pyyaml.org/download/libyaml/yaml-#{yaml_version}.tar.gz | #{tar_zxf}" - run_command e, "mkdir #{yaml_dir}/build" - end + # We build libyaml in the gem's build directory, which means + # copying the sources from the repo. + if ! File.exists? "#{yaml_dir}" + + # But first, we generate the configure script. This requires GNU + # autoconf to be installed. + Dir.chdir(File.join(spec.dir, 'third_party', yaml_base_dir)) { + run_command({}, "./bootstrap") + } + + FileUtils.cp_r File.join(spec.dir, 'third_party', yaml_base_dir), build_dir end if ! File.exists? "#{yaml_dir}/build/lib/libyaml.a" diff --git a/third_party/libyaml b/third_party/libyaml new file mode 160000 index 0000000..690a781 --- /dev/null +++ b/third_party/libyaml @@ -0,0 +1 @@ +Subproject commit 690a781ef6af70ce6749d6e2be91743345123998