Skip to content

Commit

Permalink
Merge pull request #1680 from natalie-lang/brew-pkg-config
Browse files Browse the repository at this point in the history
  • Loading branch information
seven1m authored Jan 9, 2024
2 parents 9964002 + 0aa9785 commit d6a726e
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 2 deletions.
3 changes: 2 additions & 1 deletion bin/natalie
Original file line number Diff line number Diff line change
Expand Up @@ -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 = $?
Expand Down
2 changes: 1 addition & 1 deletion lib/natalie/compiler/backends/cpp_backend.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
24 changes: 24 additions & 0 deletions test/setup_pkgconfig_with_homebrew.sh
Original file line number Diff line number Diff line change
@@ -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\""

0 comments on commit d6a726e

Please sign in to comment.