Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
Add configurable default target (#4874)
This supports, for example, a compiler compiled for the
x86_64-unknown-linux-musl architecture which doesn't require the --target
commandline option to be set when ran on x86_64-unknown-linux-gnu. This is
equivalent to the --target configure option in autoconf.
  • Loading branch information
RX14 committed Aug 23, 2017
1 parent 1754ec0 commit d3537fc
Show file tree
Hide file tree
Showing 4 changed files with 15 additions and 9 deletions.
2 changes: 1 addition & 1 deletion src/compiler/crystal/compiler.cr
Expand Up @@ -435,7 +435,7 @@ module Crystal

protected def target_machine
@target_machine ||= begin
triple = @target_triple || LLVM.default_target_triple
triple = @target_triple || Crystal::Config.default_target_triple
TargetMachine.create(triple, @mcpu || "", @mattr || "", @release)
end
rescue ex : ArgumentError
Expand Down
16 changes: 11 additions & 5 deletions src/compiler/crystal/config.cr
Expand Up @@ -14,11 +14,13 @@ module Crystal

def self.description
version, sha = version_and_sha
if sha
"Crystal #{version} [#{sha}] (#{date}) LLVM #{llvm_version}"
else
"Crystal #{version} (#{date}) LLVM #{llvm_version}"
end
formatted_sha = "[#{sha}] " if sha
<<-DOC
Crystal #{version} #{formatted_sha}(#{date})
LLVM: #{llvm_version}
Default target: #{self.default_target_triple}
DOC
end

@@version_and_sha : {String, String?}?
Expand Down Expand Up @@ -54,5 +56,9 @@ module Crystal
def self.date
{{ `date "+%Y-%m-%d"`.stringify.chomp }}
end

def self.default_target_triple
{{env("CRYSTAL_CONFIG_TARGET")}} || LLVM.default_target_triple
end
end
end
4 changes: 2 additions & 2 deletions src/compiler/crystal/crystal_path.cr
Expand Up @@ -11,12 +11,12 @@ module Crystal

@crystal_path : Array(String)

def initialize(path = CrystalPath.default_path, target_triple = LLVM.default_target_triple)
def initialize(path = CrystalPath.default_path, target_triple = Crystal::Config.default_target_triple)
@crystal_path = path.split(':').reject &.empty?
add_target_path(target_triple)
end

private def add_target_path(target_triple = LLVM.default_target_triple)
private def add_target_path(target_triple = Crystal::Config.default_target_triple)
triple = target_triple.split('-')
triple.delete(triple[1]) if triple.size == 4 # skip vendor

Expand Down
2 changes: 1 addition & 1 deletion src/compiler/crystal/program.cr
Expand Up @@ -258,7 +258,7 @@ module Crystal

setter target_machine : LLVM::TargetMachine?

getter(target_machine) { TargetMachine.create(LLVM.default_target_triple) }
getter(target_machine) { TargetMachine.create(Crystal::Config.default_target_triple) }

# Returns the `Type` for `Array(type)`
def array_of(type)
Expand Down

0 comments on commit d3537fc

Please sign in to comment.