Skip to content

Commit d3537fc

Browse files
authoredAug 23, 2017
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.
1 parent 1754ec0 commit d3537fc

File tree

4 files changed

+15
-9
lines changed

4 files changed

+15
-9
lines changed
 

Diff for: ‎src/compiler/crystal/compiler.cr

+1-1
Original file line numberDiff line numberDiff line change
@@ -435,7 +435,7 @@ module Crystal
435435

436436
protected def target_machine
437437
@target_machine ||= begin
438-
triple = @target_triple || LLVM.default_target_triple
438+
triple = @target_triple || Crystal::Config.default_target_triple
439439
TargetMachine.create(triple, @mcpu || "", @mattr || "", @release)
440440
end
441441
rescue ex : ArgumentError

Diff for: ‎src/compiler/crystal/config.cr

+11-5
Original file line numberDiff line numberDiff line change
@@ -14,11 +14,13 @@ module Crystal
1414

1515
def self.description
1616
version, sha = version_and_sha
17-
if sha
18-
"Crystal #{version} [#{sha}] (#{date}) LLVM #{llvm_version}"
19-
else
20-
"Crystal #{version} (#{date}) LLVM #{llvm_version}"
21-
end
17+
formatted_sha = "[#{sha}] " if sha
18+
<<-DOC
19+
Crystal #{version} #{formatted_sha}(#{date})
20+
21+
LLVM: #{llvm_version}
22+
Default target: #{self.default_target_triple}
23+
DOC
2224
end
2325

2426
@@version_and_sha : {String, String?}?
@@ -54,5 +56,9 @@ module Crystal
5456
def self.date
5557
{{ `date "+%Y-%m-%d"`.stringify.chomp }}
5658
end
59+
60+
def self.default_target_triple
61+
{{env("CRYSTAL_CONFIG_TARGET")}} || LLVM.default_target_triple
62+
end
5763
end
5864
end

Diff for: ‎src/compiler/crystal/crystal_path.cr

+2-2
Original file line numberDiff line numberDiff line change
@@ -11,12 +11,12 @@ module Crystal
1111

1212
@crystal_path : Array(String)
1313

14-
def initialize(path = CrystalPath.default_path, target_triple = LLVM.default_target_triple)
14+
def initialize(path = CrystalPath.default_path, target_triple = Crystal::Config.default_target_triple)
1515
@crystal_path = path.split(':').reject &.empty?
1616
add_target_path(target_triple)
1717
end
1818

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

Diff for: ‎src/compiler/crystal/program.cr

+1-1
Original file line numberDiff line numberDiff line change
@@ -258,7 +258,7 @@ module Crystal
258258

259259
setter target_machine : LLVM::TargetMachine?
260260

261-
getter(target_machine) { TargetMachine.create(LLVM.default_target_triple) }
261+
getter(target_machine) { TargetMachine.create(Crystal::Config.default_target_triple) }
262262

263263
# Returns the `Type` for `Array(type)`
264264
def array_of(type)

0 commit comments

Comments
 (0)
Please sign in to comment.