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

extconf.rb: Send RbConfig preferences to #make via env vars #2705

Merged
merged 1 commit into from
Apr 17, 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.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
19 changes: 11 additions & 8 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -8,13 +8,16 @@ ECHO1 = $(V:1=@ :)
ECHO = $(ECHO1:0=@ echo)
FUZZ_OUTPUT_DIR = $(CURDIR)/fuzz/output

SOEXT := $(shell ruby -e 'puts RbConfig::CONFIG["SOEXT"]')
SOEXT ?= $(shell ruby -e 'puts RbConfig::CONFIG["SOEXT"]')
ParadoxV5 marked this conversation as resolved.
Show resolved Hide resolved

CPPFLAGS := -Iinclude $(CPPFLAGS)
CFLAGS := -g -O2 -std=c99 -Wall -Werror -Wextra -Wpedantic -Wundef -Wconversion -Wno-missing-braces -fPIC -fvisibility=hidden $(CFLAGS)
ParadoxV5 marked this conversation as resolved.
Show resolved Hide resolved
CC := cc
CC ?= cc
WASI_SDK_PATH := /opt/wasi-sdk

MAKEDIRS ?= mkdir -p
RMALL ?= rm -f -r

ParadoxV5 marked this conversation as resolved.
Show resolved Hide resolved
HEADERS := $(wildcard include/*.h include/*/*.h include/*/*/*.h')
SOURCES := $(wildcard src/*.c src/*/*.c)
SHARED_OBJECTS := $(subst src/,build/shared/,$(SOURCES:.c=.o))
Expand Down Expand Up @@ -45,17 +48,17 @@ java-wasm/src/test/resources/prism.wasm: Makefile $(SOURCES) $(HEADERS)

build/shared/%.o: src/%.c Makefile $(HEADERS)
$(ECHO) "compiling $@"
$(Q) mkdir -p $(@D)
$(Q) $(MAKEDIRS) $(@D)
$(Q) $(CC) $(DEBUG_FLAGS) -DPRISM_EXPORT_SYMBOLS $(CPPFLAGS) $(CFLAGS) -c -o $@ $<

build/static/%.o: src/%.c Makefile $(HEADERS)
$(ECHO) "compiling $@"
$(Q) mkdir -p $(@D)
$(Q) $(MAKEDIRS) $(@D)
$(Q) $(CC) $(DEBUG_FLAGS) $(CPPFLAGS) $(CFLAGS) -c -o $@ $<

build/fuzz.%: $(SOURCES) fuzz/%.c fuzz/fuzz.c
$(ECHO) "building $* fuzzer"
$(Q) mkdir -p $(@D)
$(Q) $(MAKEDIRS) $(@D)
$(ECHO) "building main fuzz binary"
$(Q) AFL_HARDEN=1 afl-clang-lto $(DEBUG_FLAGS) $(CPPFLAGS) $(CFLAGS) $(FUZZ_FLAGS) -O0 -fsanitize-ignorelist=fuzz/asan.ignore -fsanitize=fuzzer,address -ggdb3 -std=c99 -Iinclude -o $@ $^
$(ECHO) "building cmplog binary"
Expand All @@ -78,15 +81,15 @@ fuzz-run-%: FORCE fuzz-docker-build
$(ECHO) "running $* fuzzer"
$(Q) docker run --rm -v $(CURDIR):/prism prism/fuzz /bin/bash -c "FUZZ_FLAGS=\"$(FUZZ_FLAGS)\" make build/fuzz.$*"
$(ECHO) "starting AFL++ run"
$(Q) mkdir -p $(FUZZ_OUTPUT_DIR)/$*
$(Q) $(MAKEDIRS) $(FUZZ_OUTPUT_DIR)/$*
$(Q) docker run -it --rm -v $(CURDIR):/prism -v $(FUZZ_OUTPUT_DIR):/fuzz_output prism/fuzz /bin/bash -c "./fuzz/$*.sh /fuzz_output/$*"
FORCE:

fuzz-clean:
$(Q) rm -f -r fuzz/output
$(Q) $(RMALL) fuzz/output

clean:
$(Q) rm -f -r build
$(Q) $(RMALL) build

.PHONY: clean fuzz-clean

Expand Down
11 changes: 8 additions & 3 deletions ext/prism/extconf.rb
Original file line number Diff line number Diff line change
Expand Up @@ -40,17 +40,22 @@ def generate_templates
end
end

require "rbconfig"

# 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)
Dir.chdir(File.expand_path("../..", __dir__)) do
system(RUBY_PLATFORM.include?("openbsd") ? "gmake" : "make", target, exception: true)
system(
RbConfig::CONFIG.slice(*%w[SOEXT CPPFLAGS CFLAGS CC AR ARFLAGS MAKEDIRS RMALL]), # env
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Should we extract this operation out so it’s not re-#sliced on every call?

Copy link
Collaborator

Choose a reason for hiding this comment

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

That's okay, it's not a big deal

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Actually, on hindsight, should we send RbConfig::MAKEFILE_CONFIG (unexpanded Makefile includes) over rather than RbConfig::CONFIG (expanded Makefile values)?

Copy link
Collaborator

Choose a reason for hiding this comment

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

I assume it wouldn't make a difference right?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

The difference would be if the RbConfig::MAKEFILE_CONFIG values were expanded from variables that

  • our hand-written Makefile does not cover / cover differently, or
  • interpret users’ env vars on a finer level

RUBY_PLATFORM.include?("openbsd") ? "gmake" : "make",
target,
exception: true
)
end
end

require "rbconfig"

# On non-CRuby we only need the shared library since we'll interface with it
# through FFI, so we'll build only that and not the C extension. We also avoid
# `require "mkmf"` as that prepends the LLVM toolchain to PATH on TruffleRuby,
Expand Down