compiler checks should support cross-compilers and freestanding compilers - close #118

This commit is contained in:
Josh Holtrop 2020-10-08 19:23:17 -04:00
parent 5ec74604c6
commit bbe9563ceb

View File

@ -408,22 +408,17 @@ module Rscons
def test_c_compiler(cc) def test_c_compiler(cc)
File.open("#{@work_dir}/cfgtest.c", "wb") do |fh| File.open("#{@work_dir}/cfgtest.c", "wb") do |fh|
fh.puts <<-EOF fh.puts <<-EOF
#include <stdio.h> int fun(int val) {
int main(int argc, char * argv[]) { return val * 2;
printf("Success.\\n");
return 0;
} }
EOF EOF
end end
command = %W[#{cc} -o #{@work_dir}/cfgtest.exe #{@work_dir}/cfgtest.c] command = %W[#{cc} -c -o #{@work_dir}/cfgtest.o #{@work_dir}/cfgtest.c]
merge = {"CC" => cc} merge = {"CC" => cc}
_, _, status = log_and_test_command(command) _, _, status = log_and_test_command(command)
if status == 0 if status == 0
stdout, _, status = log_and_test_command(["#{@work_dir}/cfgtest.exe"]) store_merge(merge)
if status == 0 and stdout =~ /Success/ true
store_merge(merge)
true
end
end end
end end
@ -437,23 +432,18 @@ module Rscons
def test_cxx_compiler(cc) def test_cxx_compiler(cc)
File.open("#{@work_dir}/cfgtest.cxx", "wb") do |fh| File.open("#{@work_dir}/cfgtest.cxx", "wb") do |fh|
fh.puts <<-EOF fh.puts <<-EOF
#include <iostream> template<typename T>
using namespace std; T fun(T val) {
int main(int argc, char * argv[]) { return val * 2;
cout << "Success." << endl;
return 0;
} }
EOF EOF
end end
command = %W[#{cc} -o #{@work_dir}/cfgtest.exe #{@work_dir}/cfgtest.cxx] command = %W[#{cc} -c -o #{@work_dir}/cfgtest.o #{@work_dir}/cfgtest.cxx]
merge = {"CXX" => cc} merge = {"CXX" => cc}
_, _, status = log_and_test_command(command) _, _, status = log_and_test_command(command)
if status == 0 if status == 0
stdout, _, status = log_and_test_command(["#{@work_dir}/cfgtest.exe"]) store_merge(merge)
if status == 0 and stdout =~ /Success/ true
store_merge(merge)
true
end
end end
end end
@ -467,9 +457,8 @@ module Rscons
def test_d_compiler(dc) def test_d_compiler(dc)
File.open("#{@work_dir}/cfgtest.d", "wb") do |fh| File.open("#{@work_dir}/cfgtest.d", "wb") do |fh|
fh.puts <<-EOF fh.puts <<-EOF
import std.stdio; import core.math;
int main() { int fun() {
writeln("Success.");
return 0; return 0;
} }
EOF EOF
@ -477,29 +466,25 @@ module Rscons
[:gdc, :ldc2].find do |dc_test| [:gdc, :ldc2].find do |dc_test|
case dc_test case dc_test
when :gdc when :gdc
command = %W[#{dc} -o #{@work_dir}/cfgtest.exe #{@work_dir}/cfgtest.d] command = %W[#{dc} -c -o #{@work_dir}/cfgtest.o #{@work_dir}/cfgtest.d]
merge = {"DC" => dc} merge = {"DC" => dc}
when :ldc2 when :ldc2
command = %W[#{dc} -of #{@work_dir}/cfgtest.exe #{@work_dir}/cfgtest.d] # ldc2 on Windows expect an object file suffix of .obj.
ldc_objsuffix = RUBY_PLATFORM =~ /mingw|msys/ ? ".obj" : ".o"
command = %W[#{dc} -c -of #{@work_dir}/cfgtest#{ldc_objsuffix} #{@work_dir}/cfgtest.d]
env = BasicEnvironment.new env = BasicEnvironment.new
merge = { merge = {
"DC" => dc, "DC" => dc,
"DCCMD" => env["DCCMD"].map {|e| if e == "-o"; "-of"; else; e; end}, "DCCMD" => env["DCCMD"].map {|e| e.sub(/^-o$/, "-of")},
"LDCMD" => env["LDCMD"].map {|e| if e == "-o"; "-of"; else; e; end}, "LDCMD" => env["LDCMD"].map {|e| e.sub(/^-o$/, "-of")},
"DDEPGEN" => ["-deps=${_DEPFILE}"], "DDEPGEN" => ["-deps=${_DEPFILE}"],
} }
if RUBY_PLATFORM =~ /mingw/ merge["OBJSUFFIX"] = [ldc_objsuffix]
# ldc2 on Windows expect an object file suffix of .obj.
merge["OBJSUFFIX"] = %w[.obj]
end
end end
_, _, status = log_and_test_command(command) _, _, status = log_and_test_command(command)
if status == 0 if status == 0
stdout, _, status = log_and_test_command(["#{@work_dir}/cfgtest.exe"]) store_merge(merge)
if status == 0 and stdout =~ /Success/ true
store_merge(merge)
true
end
end end
end end
end end