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

Fall back to default AR and CC #2725

Merged
merged 1 commit into from
Apr 23, 2024
Merged
Show file tree
Hide file tree
Changes from all 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
5 changes: 3 additions & 2 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ SOEXT ?= $(shell ruby -e 'puts RbConfig::CONFIG["SOEXT"]')
CPPFLAGS := -Iinclude $(CPPFLAGS)
CFLAGS := -g -O2 -std=c99 -Wall -Werror -Wextra -Wpedantic -Wundef -Wconversion -Wno-missing-braces -fPIC -fvisibility=hidden $(CFLAGS)
CC ?= cc
AR ?= ar
Comment on lines 15 to +16
Copy link
Contributor

@ParadoxV5 ParadoxV5 Apr 22, 2024

Choose a reason for hiding this comment

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

As discovered in #2711 (comment), CC ?= cc and AR ?= ar has no effect, whether run from make directly (because GNU make already preconfigures them to cc and ar respectively) or from extconf.rb (as it’ll override them with rbconfig values)

Suggested change
CC ?= cc
AR ?= ar

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

I agree with you in theory, but something else must be going on here, because after lots of back and forth with @forthrin this is what finally resolved the issue. I'm assuming there's something else here going on.

WASI_SDK_PATH := /opt/wasi-sdk

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

build/libprism.$(SOEXT): $(SHARED_OBJECTS)
$(ECHO) "linking $@"
$(ECHO) "linking $@ with $(CC)"
$(Q) $(CC) $(DEBUG_FLAGS) $(CFLAGS) -shared -o $@ $(SHARED_OBJECTS)

build/libprism.a: $(STATIC_OBJECTS)
$(ECHO) "building $@"
$(ECHO) "building $@ with $(AR)"
$(Q) $(AR) $(ARFLAGS) $@ $(STATIC_OBJECTS) $(Q1:0=>/dev/null)

javascript/src/prism.wasm: Makefile $(SOURCES) $(HEADERS)
Expand Down
27 changes: 23 additions & 4 deletions ext/prism/extconf.rb
Original file line number Diff line number Diff line change
Expand Up @@ -40,15 +40,34 @@ def generate_templates
end
end

# We're going to need to run `make` using prism's `Makefile`. We want to match
# up as much of the configuration to the configuration that built the current
# version of Ruby as possible.
require "rbconfig"
env = RbConfig::CONFIG.slice("SOEXT", "CPPFLAGS", "CFLAGS", "CC", "AR", "ARFLAGS", "MAKEDIRS", "RMALL")
Copy link
Contributor

Choose a reason for hiding this comment

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


# It's possible that the Ruby that is being run wasn't actually compiled on this
# machine, in which case the configuration might be incorrect. In this case
# we'll need to do some additional checks and potentially fall back to defaults.
if env.key?("CC") && !File.exist?(env["CC"])
env.delete("CC")
env.delete("CFLAGS")
env.delete("CPPFLAGS")
end

if env.key?("AR") && !File.exist?(env["AR"])
env.delete("AR")
env.delete("ARFLAGS")
end

# Runs `make` in the root directory of the project. Note that this is the
# `Makefile` for the overall project, not the `Makefile` that is being generated
# by this script.`
def make(target)
def make(env, target)
puts "Running make #{target} with #{env.inspect}"
Dir.chdir(File.expand_path("../..", __dir__)) do
system(
RbConfig::CONFIG.slice(*%w[SOEXT CPPFLAGS CFLAGS CC AR ARFLAGS MAKEDIRS RMALL]), # env
env,
RUBY_PLATFORM.include?("openbsd") ? "gmake" : "make",
target,
exception: true
Expand All @@ -62,7 +81,7 @@ def make(target)
# but we want to use the native toolchain here since libprism is run natively.
if RUBY_ENGINE != "ruby"
generate_templates
make("build/libprism.#{RbConfig::CONFIG["SOEXT"]}")
make(env, "build/libprism.#{RbConfig::CONFIG["SOEXT"]}")
File.write("Makefile", "all install clean:\n\t@#{RbConfig::CONFIG["NULLCMD"]}\n")
return
end
Expand Down Expand Up @@ -110,7 +129,7 @@ def make(target)
archive_target = "build/libprism.a"
archive_path = File.expand_path("../../#{archive_target}", __dir__)

make(archive_target) unless File.exist?(archive_path)
make(env, archive_target) unless File.exist?(archive_path)
$LOCAL_LIBS << " #{archive_path}"

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