Skip to content

Commit e0ceb8f

Browse files
authored
Merge pull request #2725 from ruby/fallback
Fall back to default AR and CC
2 parents 7142b76 + e700d0d commit e0ceb8f

File tree

2 files changed

+26
-6
lines changed

2 files changed

+26
-6
lines changed

Makefile

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ SOEXT ?= $(shell ruby -e 'puts RbConfig::CONFIG["SOEXT"]')
1313
CPPFLAGS := -Iinclude $(CPPFLAGS)
1414
CFLAGS := -g -O2 -std=c99 -Wall -Werror -Wextra -Wpedantic -Wundef -Wconversion -Wno-missing-braces -fPIC -fvisibility=hidden $(CFLAGS)
1515
CC ?= cc
16+
AR ?= ar
1617
WASI_SDK_PATH := /opt/wasi-sdk
1718

1819
MAKEDIRS ?= mkdir -p
@@ -31,11 +32,11 @@ wasm: javascript/src/prism.wasm
3132
java-wasm: java-wasm/src/test/resources/prism.wasm
3233

3334
build/libprism.$(SOEXT): $(SHARED_OBJECTS)
34-
$(ECHO) "linking $@"
35+
$(ECHO) "linking $@ with $(CC)"
3536
$(Q) $(CC) $(DEBUG_FLAGS) $(CFLAGS) -shared -o $@ $(SHARED_OBJECTS)
3637

3738
build/libprism.a: $(STATIC_OBJECTS)
38-
$(ECHO) "building $@"
39+
$(ECHO) "building $@ with $(AR)"
3940
$(Q) $(AR) $(ARFLAGS) $@ $(STATIC_OBJECTS) $(Q1:0=>/dev/null)
4041

4142
javascript/src/prism.wasm: Makefile $(SOURCES) $(HEADERS)

ext/prism/extconf.rb

Lines changed: 23 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -40,15 +40,34 @@ def generate_templates
4040
end
4141
end
4242

43+
# We're going to need to run `make` using prism's `Makefile`. We want to match
44+
# up as much of the configuration to the configuration that built the current
45+
# version of Ruby as possible.
4346
require "rbconfig"
47+
env = RbConfig::CONFIG.slice("SOEXT", "CPPFLAGS", "CFLAGS", "CC", "AR", "ARFLAGS", "MAKEDIRS", "RMALL")
48+
49+
# It's possible that the Ruby that is being run wasn't actually compiled on this
50+
# machine, in which case the configuration might be incorrect. In this case
51+
# we'll need to do some additional checks and potentially fall back to defaults.
52+
if env.key?("CC") && !File.exist?(env["CC"])
53+
env.delete("CC")
54+
env.delete("CFLAGS")
55+
env.delete("CPPFLAGS")
56+
end
57+
58+
if env.key?("AR") && !File.exist?(env["AR"])
59+
env.delete("AR")
60+
env.delete("ARFLAGS")
61+
end
4462

4563
# Runs `make` in the root directory of the project. Note that this is the
4664
# `Makefile` for the overall project, not the `Makefile` that is being generated
4765
# by this script.`
48-
def make(target)
66+
def make(env, target)
67+
puts "Running make #{target} with #{env.inspect}"
4968
Dir.chdir(File.expand_path("../..", __dir__)) do
5069
system(
51-
RbConfig::CONFIG.slice(*%w[SOEXT CPPFLAGS CFLAGS CC AR ARFLAGS MAKEDIRS RMALL]), # env
70+
env,
5271
RUBY_PLATFORM.include?("openbsd") ? "gmake" : "make",
5372
target,
5473
exception: true
@@ -62,7 +81,7 @@ def make(target)
6281
# but we want to use the native toolchain here since libprism is run natively.
6382
if RUBY_ENGINE != "ruby"
6483
generate_templates
65-
make("build/libprism.#{RbConfig::CONFIG["SOEXT"]}")
84+
make(env, "build/libprism.#{RbConfig::CONFIG["SOEXT"]}")
6685
File.write("Makefile", "all install clean:\n\t@#{RbConfig::CONFIG["NULLCMD"]}\n")
6786
return
6887
end
@@ -110,7 +129,7 @@ def make(target)
110129
archive_target = "build/libprism.a"
111130
archive_path = File.expand_path("../../#{archive_target}", __dir__)
112131

113-
make(archive_target) unless File.exist?(archive_path)
132+
make(env, archive_target) unless File.exist?(archive_path)
114133
$LOCAL_LIBS << " #{archive_path}"
115134

116135
# Finally, we'll create the `Makefile` that is going to be used to configure and

0 commit comments

Comments
 (0)