Skip to content

Commit

Permalink
Windows: Do not use %LLVM_CONFIG% when linking dynamically
Browse files Browse the repository at this point in the history
  • Loading branch information
HertzDevil committed Dec 15, 2023
1 parent c53dd72 commit 104495e
Showing 1 changed file with 27 additions and 12 deletions.
39 changes: 27 additions & 12 deletions src/llvm/lib_llvm.cr
Original file line number Diff line number Diff line change
@@ -1,19 +1,34 @@
{% begin %}
lib LibLLVM
LLVM_CONFIG = {{ env("LLVM_CONFIG") || `#{__DIR__}/ext/find-llvm-config`.stringify }}
end
{% end %}
{% if flag?(:win32) && flag?(:preview_dll) %}
{% config = nil %}
{% for dir in Crystal::LIBRARY_PATH.split(';') %}
{% config ||= read_file?("#{dir.id}/llvm_VERSION") %}
{% end %}

{% begin %}
{% unless flag?(:win32) %}
@[Link("stdc++")]
{% unless config %}
{% raise "Cannot determine LLVM configuration; ensure the file `llvm_VERSION` exists under `CRYSTAL_LIBRARY_PATH`" %}
{% end %}

{% lines = config.lines.map(&.chomp) %}
{% llvm_version = lines[0] %}
{% llvm_targets = lines[1] %}
{% llvm_ldflags = lines[2] %}
{% extra_lib = "llvm" %}
{% else %}
{% llvm_config = env("LLVM_CONFIG") || `#{__DIR__}/ext/find-llvm-config`.stringify %}
{% llvm_version = `#{llvm_config.id} --version`.stringify %}
{% llvm_targets = env("LLVM_TARGETS") || `#{llvm_config.id} --targets-built`.stringify %}
{% llvm_ldflags = `#{llvm_config.id} --libs --system-libs --ldflags#{" --link-static".id if flag?(:static)}#{" 2> /dev/null".id unless flag?(:win32)}`.stringify %}
{% extra_lib = flag?(:win32) ? nil : "stdc++" %}
{% end %}

{% if extra_lib %}
@[Link({{ extra_lib }})]
{% end %}
@[Link(ldflags: {{"`#{LibLLVM::LLVM_CONFIG} --libs --system-libs --ldflags#{" --link-static".id if flag?(:static)}#{" 2> /dev/null".id unless flag?(:win32)}`"}})]
@[Link(ldflags: {{ llvm_ldflags.strip }})]
lib LibLLVM
VERSION = {{`#{LibLLVM::LLVM_CONFIG} --version`.chomp.stringify.gsub(/git/, "")}}
BUILT_TARGETS = {{ (
env("LLVM_TARGETS") || `#{LibLLVM::LLVM_CONFIG} --targets-built`
).strip.downcase.split(' ').map(&.id.symbolize) }}
VERSION = {{ llvm_version.strip.gsub(/git/, "") }}
BUILT_TARGETS = {{ llvm_targets.strip.downcase.split(' ').map(&.id.symbolize) }}
end
{% end %}

Expand Down

0 comments on commit 104495e

Please sign in to comment.