diff --git a/bin/natalie b/bin/natalie index 468ab0759..d60f312ed 100755 --- a/bin/natalie +++ b/bin/natalie @@ -261,7 +261,8 @@ class Runner def run_temp_and_wait(path) build_dir = File.expand_path('../build', __dir__) - env = { 'LD_LIBRARY_PATH' => "#{build_dir}:#{build_dir}/onigmo/lib" } + var_name = RUBY_PLATFORM =~ /darwin/ ? 'DYLD_LIBRARY_PATH' : 'LD_LIBRARY_PATH' + env = { var_name => Natalie::Compiler::CppBackend::LIB_PATHS.join(':') } pid = spawn(env, path, *ARGV) Process.wait(pid) @run_result = $? diff --git a/lib/natalie/compiler/backends/cpp_backend.rb b/lib/natalie/compiler/backends/cpp_backend.rb index c520858db..6b9488326 100644 --- a/lib/natalie/compiler/backends/cpp_backend.rb +++ b/lib/natalie/compiler/backends/cpp_backend.rb @@ -47,7 +47,7 @@ class CppBackend File.join(BUILD_DIR, 'zlib'), ].freeze - PACKAGES_REQUIRING_PKG_CONFIG = %w[openssl libffi].freeze + PACKAGES_REQUIRING_PKG_CONFIG = %w[openssl libffi yaml-0.1].freeze def initialize(instructions, compiler:, compiler_context:) @instructions = instructions diff --git a/test/setup_pkgconfig_with_homebrew.sh b/test/setup_pkgconfig_with_homebrew.sh new file mode 100755 index 000000000..5afd49deb --- /dev/null +++ b/test/setup_pkgconfig_with_homebrew.sh @@ -0,0 +1,24 @@ +#!/bin/bash + +# Homebrew does not put the .pc files in a common place that pkg-config can find. +# This script sets up the PKG_CONFIG_PATH so that the packages can be found by Natalie. +# You can run this prior to running `bin/natalie` or `rake test` or whatever. +# +# Usage: +# +# eval(test/setup_pkgconfig_with_homebrew.sh) + +set -e + +packages=("libyaml") + +if ! type -P brew &>/dev/null; then + echo "Could not find $(brew) command. This script assumes you have Homebrew installed." + exit 1 +fi + +for package in ${packages[@]}; do + PKG_CONFIG_PATH="$PKG_CONFIG_PATH:$(brew --prefix $package)/lib/pkgconfig" +done + +echo "export PKG_CONFIG_PATH=\"$PKG_CONFIG_PATH\""