Skip to content

Commit

Permalink
Add cc's search paths to Unix dynamic library loader
Browse files Browse the repository at this point in the history
  • Loading branch information
HertzDevil committed Oct 25, 2024
1 parent 8a96e33 commit 7fad341
Show file tree
Hide file tree
Showing 8 changed files with 21 additions and 50 deletions.
7 changes: 0 additions & 7 deletions spec/std/llvm/aarch64_spec.cr
Original file line number Diff line number Diff line change
@@ -1,11 +1,4 @@
require "spec"

{% if flag?(:interpreted) && !flag?(:win32) %}
# TODO: figure out how to link against libstdc++ in interpreted code (#14398)
pending LLVM::ABI::AArch64
{% skip_file %}
{% end %}

require "llvm"

{% if LibLLVM::BUILT_TARGETS.includes?(:aarch64) %}
Expand Down
7 changes: 0 additions & 7 deletions spec/std/llvm/arm_abi_spec.cr
Original file line number Diff line number Diff line change
@@ -1,11 +1,4 @@
require "spec"

{% if flag?(:interpreted) && !flag?(:win32) %}
# TODO: figure out how to link against libstdc++ in interpreted code (#14398)
pending LLVM::ABI::ARM
{% skip_file %}
{% end %}

require "llvm"

{% if LibLLVM::BUILT_TARGETS.includes?(:arm) %}
Expand Down
7 changes: 0 additions & 7 deletions spec/std/llvm/avr_spec.cr
Original file line number Diff line number Diff line change
@@ -1,11 +1,4 @@
require "spec"

{% if flag?(:interpreted) && !flag?(:win32) %}
# TODO: figure out how to link against libstdc++ in interpreted code (#14398)
pending LLVM::ABI::AVR
{% skip_file %}
{% end %}

require "llvm"

{% if LibLLVM::BUILT_TARGETS.includes?(:avr) %}
Expand Down
7 changes: 0 additions & 7 deletions spec/std/llvm/llvm_spec.cr
Original file line number Diff line number Diff line change
@@ -1,11 +1,4 @@
require "spec"

{% if flag?(:interpreted) && !flag?(:win32) %}
# TODO: figure out how to link against libstdc++ in interpreted code (#14398)
pending LLVM
{% skip_file %}
{% end %}

require "llvm"

describe LLVM do
Expand Down
7 changes: 0 additions & 7 deletions spec/std/llvm/type_spec.cr
Original file line number Diff line number Diff line change
@@ -1,11 +1,4 @@
require "spec"

{% if flag?(:interpreted) && !flag?(:win32) %}
# TODO: figure out how to link against libstdc++ in interpreted code (#14398)
pending LLVM::Type
{% skip_file %}
{% end %}

require "llvm"

describe LLVM::Type do
Expand Down
7 changes: 0 additions & 7 deletions spec/std/llvm/x86_64_abi_spec.cr
Original file line number Diff line number Diff line change
@@ -1,11 +1,4 @@
require "spec"

{% if flag?(:interpreted) && !flag?(:win32) %}
# TODO: figure out how to link against libstdc++ in interpreted code (#14398)
pending LLVM::ABI::X86_64
{% skip_file %}
{% end %}

require "llvm"

{% if LibLLVM::BUILT_TARGETS.includes?(:x86) %}
Expand Down
7 changes: 0 additions & 7 deletions spec/std/llvm/x86_abi_spec.cr
Original file line number Diff line number Diff line change
@@ -1,13 +1,6 @@
{% skip_file if flag?(:win32) %} # 32-bit windows is not supported

require "spec"

{% if flag?(:interpreted) %}
# TODO: figure out how to link against libstdc++ in interpreted code (#14398)
pending LLVM::ABI::X86
{% skip_file %}
{% end %}

require "llvm"

{% if LibLLVM::BUILT_TARGETS.includes?(:x86) %}
Expand Down
22 changes: 21 additions & 1 deletion src/compiler/crystal/loader/unix.cr
Original file line number Diff line number Diff line change
Expand Up @@ -162,6 +162,10 @@ class Crystal::Loader
read_ld_conf(default_search_paths)
{% end %}

cc_each_library_path do |path|
default_search_paths << path
end

{% if flag?(:darwin) %}
default_search_paths << "/usr/lib"
default_search_paths << "/usr/local/lib"
Expand All @@ -179,7 +183,7 @@ class Crystal::Loader
default_search_paths << "/usr/lib"
{% end %}

default_search_paths
default_search_paths.uniq!
end

def self.read_ld_conf(array = [] of String, path = "/etc/ld.so.conf") : Nil
Expand All @@ -201,4 +205,20 @@ class Crystal::Loader
end
end
end

def self.cc_each_library_path(& : String ->) : Nil
search_dirs = begin
`#{Crystal::Compiler::DEFAULT_LINKER} -print-search-dirs`
rescue IO::Error
return
end

search_dirs.each_line do |line|
if libraries = line.lchop?("libraries: =")
libraries.split(Process::PATH_DELIMITER) do |path|
yield File.expand_path(path)
end
end
end
end
end

0 comments on commit 7fad341

Please sign in to comment.