Skip to content

Commit

Permalink
Add Crystal::HOST_TRIPLE and TARGET_TRIPLE (crystal-lang#13823)
Browse files Browse the repository at this point in the history
  • Loading branch information
HertzDevil authored and Blacksmoke16 committed Dec 11, 2023
1 parent ad01d58 commit 0bfb53b
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 4 deletions.
5 changes: 2 additions & 3 deletions spec/compiler/config_spec.cr
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,8 @@ require "./spec_helper"
describe Crystal::Config do
it ".host_target" do
{% begin %}
# TODO: CRYSTAL_SPEC_COMPILER_BIN must be quoted (#11456)
{% compiler = (env("CRYSTAL_SPEC_COMPILER_BIN") || "bin/crystal").id %}
Crystal::Config.host_target.should eq Crystal::Codegen::Target.new({{ `#{compiler} --version`.lines[-1] }}.lchop("Default target: "))
{% host_triple = Crystal.constant("HOST_TRIPLE") || Crystal::DESCRIPTION.lines[-1].gsub(/^Default target: /, "") %}
Crystal::Config.host_target.should eq Crystal::Codegen::Target.new({{ host_triple }})
{% end %}
end

Expand Down
9 changes: 8 additions & 1 deletion src/compiler/crystal/program.cr
Original file line number Diff line number Diff line change
Expand Up @@ -118,7 +118,7 @@ module Crystal
# A `ProgressTracker` object which tracks compilation progress.
property progress_tracker = ProgressTracker.new

property codegen_target = Config.host_target
getter codegen_target = Config.host_target

getter predefined_constants = Array(Const).new

Expand Down Expand Up @@ -289,6 +289,8 @@ module Crystal
define_crystal_string_constant "LIBRARY_RPATH", Crystal::CrystalLibraryPath.default_rpath
define_crystal_string_constant "VERSION", Crystal::Config.version
define_crystal_string_constant "LLVM_VERSION", Crystal::Config.llvm_version
define_crystal_string_constant "HOST_TRIPLE", Crystal::Config.host_target.to_s
define_crystal_string_constant "TARGET_TRIPLE", Crystal::Config.host_target.to_s
end

private def define_crystal_string_constant(name, value)
Expand All @@ -307,6 +309,11 @@ module Crystal

property(target_machine : LLVM::TargetMachine) { codegen_target.to_target_machine }

def codegen_target=(@codegen_target : Codegen::Target) : Codegen::Target
crystal.types["TARGET_TRIPLE"].as(Const).value.as(StringLiteral).value = codegen_target.to_s
@codegen_target
end

# Returns the `Type` for `Array(type)`
def array_of(type)
array.instantiate [type] of TypeVar
Expand Down

0 comments on commit 0bfb53b

Please sign in to comment.