Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add Crystal::HOST_TRIPLE and TARGET_TRIPLE #13823

Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions spec/compiler/config_spec.cr
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ describe Crystal::Config do
{% begin %}
# TODO: CRYSTAL_SPEC_COMPILER_BIN must be quoted (#11456)
{% compiler = (env("CRYSTAL_SPEC_COMPILER_BIN") || "bin/crystal").id %}
# TODO: check against Crystal::HOST_TRIPLE instead
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I would like to add some context as to when this TODO should be applied. It's effectively after we drop forward compatibility with Crystal < 1.10 (assuming HOST_TARGET gets released in 1.10).
Not sure how to best express that though...
Maybe we could add a macro to already use HOST_TRIPLE when available? ({% if Crystal.has_constant?(:HOST_TRIPLE) %})

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We could also put the Crystal:: constant tests inside the primitive specs since they require a fresh compiler. Not sure if that'll look odd to some people

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah, such specs could be a supplemenatry addition.
This spec is just using the constant for calculating the expected value, it's not testing the constant itself.

Crystal::Config.host_target.should eq Crystal::Codegen::Target.new({{ `#{compiler} --version`.lines[-1] }}.lchop("Default target: "))
{% 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