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

[GR-45043] Build YARP using configure and its Makefile #3140

Merged
merged 10 commits into from
Jul 3, 2023
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
11 changes: 5 additions & 6 deletions ci/common.jsonnet
Original file line number Diff line number Diff line change
Expand Up @@ -42,17 +42,15 @@ local common_json = import "../common.json";
},
for name in std.objectFields(jdks_data)
} + {
local latestJDKCE = self["labsjdk-ce-20"],
local latestJDKEE = self["labsjdk-ee-20"],
# Some convenient JDK aliases which don't require ["name"] for frequently-used JDKs
labsjdk17ce: self["labsjdk-ce-17"],
labsjdk17ee: self["labsjdk-ee-17"],

labsjdk20ce: latestJDKCE,
labsjdk20ee: latestJDKEE,
labsjdk20ce: self["labsjdk-ce-20"],
labsjdk20ee: self["labsjdk-ee-20"],

labsjdkLatestCE: latestJDKCE,
labsjdkLatestEE: latestJDKEE,
labsjdkLatestCE: self["labsjdk-ce-21"],
labsjdkLatestEE: self["labsjdk-ee-21"],
},

# The devkits versions reflect those used to build the JVMCI JDKs (e.g., see devkit_platform_revisions in <jdk>/make/conf/jib-profiles.js)
Expand All @@ -65,6 +63,7 @@ local common_json = import "../common.json";
"linux-jdk17": { packages+: { "devkit:gcc11.2.0-OL6.4+1": "==0" }},
"linux-jdk19": { packages+: { "devkit:gcc11.2.0-OL6.4+1": "==0" }},
"linux-jdk20": { packages+: { "devkit:gcc11.2.0-OL6.4+1": "==0" }},
"linux-jdk21": { packages+: { "devkit:gcc11.2.0-OL6.4+1": "==0" }},
},

# Dependencies
Expand Down
16 changes: 8 additions & 8 deletions common.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
"Jsonnet files should not include this file directly but use ci/common.jsonnet instead."
],

"mx_version": "6.27.3",
"mx_version": "6.27.5",

"COMMENT.jdks": "When adding or removing JDKs keep in sync with JDKs in ci/common.jsonnet",
"jdks": {
Expand Down Expand Up @@ -34,13 +34,13 @@
"labsjdk-ee-20Debug": {"name": "labsjdk", "version": "ee-20.0.2+2-jvmci-23.1-b02-debug", "platformspecific": true },
"labsjdk-ee-20-llvm": {"name": "labsjdk", "version": "ee-20.0.2+2-jvmci-23.1-b02-sulong", "platformspecific": true },

"oraclejdk21": {"name": "jpg-jdk", "version": "21", "build_id": "27", "release": true, "platformspecific": true, "extrabundles": ["static-libs"]},
"labsjdk-ce-21": {"name": "labsjdk", "version": "ce-21+27-jvmci-23.1-b08", "platformspecific": true },
"labsjdk-ce-21Debug": {"name": "labsjdk", "version": "ce-21+27-jvmci-23.1-b08-debug", "platformspecific": true },
"labsjdk-ce-21-llvm": {"name": "labsjdk", "version": "ce-21+27-jvmci-23.1-b08-sulong", "platformspecific": true },
"labsjdk-ee-21": {"name": "labsjdk", "version": "ee-21+27-jvmci-23.1-b08", "platformspecific": true },
"labsjdk-ee-21Debug": {"name": "labsjdk", "version": "ee-21+27-jvmci-23.1-b08-debug", "platformspecific": true },
"labsjdk-ee-21-llvm": {"name": "labsjdk", "version": "ee-21+27-jvmci-23.1-b08-sulong", "platformspecific": true },
"oraclejdk21": {"name": "jpg-jdk", "version": "21", "build_id": "28", "release": true, "platformspecific": true, "extrabundles": ["static-libs"]},
"labsjdk-ce-21": {"name": "labsjdk", "version": "ce-21+28-jvmci-23.1-b09", "platformspecific": true },
"labsjdk-ce-21Debug": {"name": "labsjdk", "version": "ce-21+28-jvmci-23.1-b09-debug", "platformspecific": true },
"labsjdk-ce-21-llvm": {"name": "labsjdk", "version": "ce-21+28-jvmci-23.1-b09-sulong", "platformspecific": true },
"labsjdk-ee-21": {"name": "labsjdk", "version": "ee-21+28-jvmci-23.1-b09", "platformspecific": true },
"labsjdk-ee-21Debug": {"name": "labsjdk", "version": "ee-21+28-jvmci-23.1-b09-debug", "platformspecific": true },
"labsjdk-ee-21-llvm": {"name": "labsjdk", "version": "ee-21+28-jvmci-23.1-b09-sulong", "platformspecific": true },

"oraclejdk22": {"name": "jpg-jdk", "version": "22", "build_id": "1", "release": true, "platformspecific": true, "extrabundles": ["static-libs"]}
},
Expand Down
23 changes: 23 additions & 0 deletions mx.truffleruby/mx_truffleruby.py
Original file line number Diff line number Diff line change
Expand Up @@ -121,6 +121,29 @@ def contents(self, result):
command = [jdk.java] + jvm_args + [main_class] + ruby_options + ['"$@"']
return "#!/usr/bin/env bash\n" + "exec " + " ".join(command) + "\n"


class YARPNativeProject(mx.NativeProject):
def __init__(self, suite, name, deps, workingSets, output=None, **kwArgs):
path = join(root, kwArgs.pop('dir'))
super(YARPNativeProject, self).__init__(
suite, name, subDir=None, srcDirs=[path], deps=deps, workingSets=workingSets,
results=kwArgs.pop('results'),
output=path, d=path, vpath=False, **kwArgs)

def getBuildTask(self, args):
return YARPNativeBuildTask(args, self)

class YARPNativeBuildTask(mx.NativeBuildTask):
def build(self):
mx.run(['./configure'], cwd=self.subject.dir)
super(YARPNativeBuildTask, self).build() # make

def clean(self, forBuild=False):
if exists(join(self.subject.dir, 'Makefile')):
super(YARPNativeBuildTask, self).clean(forBuild=forBuild)
else:
pass

# Commands

def jt(*args):
Expand Down
22 changes: 16 additions & 6 deletions mx.truffleruby/suite.py
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
suite = {
"mxversion": "6.16.6",
"mxversion": "6.27.5",
"name": "truffleruby",

"imports": {
"suites": [
{
"name": "regex",
"subdir": True,
"version": "f2f88bb722a6d10e714fa96351835a84f77d5e15",
"version": "f49685115ed0669641559593242832e06a437278",
"urls": [
{"url": "https://github.com/oracle/graal.git", "kind": "git"},
{"url": "https://curio.ssw.jku.at/nexus/content/repositories/snapshots", "kind": "binary"},
Expand All @@ -16,7 +16,7 @@
{
"name": "sulong",
"subdir": True,
"version": "f2f88bb722a6d10e714fa96351835a84f77d5e15",
"version": "f49685115ed0669641559593242832e06a437278",
"urls": [
{"url": "https://github.com/oracle/graal.git", "kind": "git"},
{"url": "https://curio.ssw.jku.at/nexus/content/repositories/snapshots", "kind": "binary"},
Expand Down Expand Up @@ -204,16 +204,26 @@
},

"org.yarp.libyarp": {
"class": "YARPNativeProject",
"dir": "src/main/c/yarp",
"makeTarget": "all-no-debug", # Comment this out to build with asserts and no optimizations
"results": ["build/librubyparser.a"],
"description": "YARP used as a static library"
},

"org.truffleruby.yarp.bindings": {
"dir": "src/main/c/yarp_bindings",
"native": "shared_lib",
"deliverable": "yarp",
"buildDependencies": [
"org.yarp.libyarp", # librubyparser.a
"org.yarp", # for the generated JNI header file
],
"use_jdk_headers": True, # the generated JNI header includes jni.h
"cflags": ["-g", "-Wall", "-Werror", "-pthread"],
"cflags": ["-g", "-Wall", "-Werror", "-pthread", "-I<path:org.yarp.libyarp>/include"],
"ldflags": ["-pthread"],
"description": "YARP + JNI bindings as a single lib"
"ldlibs": ["<path:org.yarp.libyarp>/build/librubyparser.a"],
"description": "JNI bindings for YARP"
},

"org.truffleruby": {
Expand Down Expand Up @@ -485,7 +495,7 @@
"file:lib/mri",
"file:lib/patches",
"file:lib/truffle",
"dependency:org.yarp.libyarp",
"dependency:org.truffleruby.yarp.bindings",
],
"lib/cext/": [
"file:lib/cext/*.rb",
Expand Down
32 changes: 32 additions & 0 deletions spec/truffle/yarp_spec.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
# truffleruby_primitives: true

# Copyright (c) 2023 Oracle and/or its affiliates. All rights reserved. This
# code is released under a tri EPL/GPL/LGPL license. You can use it,
# redistribute it and/or modify it under the terms of the:
#
# Eclipse Public License version 2.0, or
# GNU General Public License version 2, or
# GNU Lesser General Public License version 2.1.

require_relative '../ruby/spec_helper'

# Similar tests as in https://github.com/ruby/yarp/blob/main/.github/workflows/truffleruby.yml
describe "YARP" do
root = File.expand_path("../..", __dir__)

guard -> { Dir.exist?("#{root}/src/main/ruby/truffleruby") } do
it "can parse core files" do
Dir.glob("#{root}/src/main/ruby/truffleruby/**/*.rb") do |file|
Truffle::Debug.yarp_parse(File.read(file)).should.include?("Node")
end
end
end

it "can execute simple code" do
-> {
-> {
Truffle::Debug.yarp_execute("p 1+2").should == 3
}.should output_to_fd(/^YARP AST:.+Truffle AST:/m, STDERR)
}.should output("3\n")
end
end
49 changes: 49 additions & 0 deletions src/main/c/yarp/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
/.bundle/
/.idea/
/.yardoc
/_yardoc/
/coverage/
/doc/
/pkg/
/spec/reports/
/top-100-gems/
/tmp/
/vendor/bundle

/build/
/lib/yarp/yarp.*
/lib/yarp.bundle
/lib/yarp.so
test.rb
*.dSYM
*~

test.c
a.out

/ext/yarp/api_node.c
/fuzz/output/
/include/yarp/ast.h
/java/org/yarp/AbstractNodeVisitor.java
/java/org/yarp/Loader.java
/java/org/yarp/Nodes.java
/lib/yarp/node.rb
/lib/yarp/serialize.rb
/src/node.c
/src/prettyprint.c
/src/serialize.c
/src/token_type.c
/src/**/*.o

compile_commands.json
.cache/

autom4te.cache
configure
config.log
config.status
Makefile
/include/yarp/config.h
/config.h.in

tags
7 changes: 7 additions & 0 deletions src/main/c/yarp/LICENSE.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
Copyright 2022-present, Shopify Inc.

Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
79 changes: 79 additions & 0 deletions src/main/c/yarp/Makefile.in
Original file line number Diff line number Diff line change
@@ -0,0 +1,79 @@

# V=0 quiet, V=1 verbose. other values don't work.
V = 0
V0 = $(V:0=)
Q1 = $(V:1=)
Q = $(Q1:0=@)
ECHO1 = $(V:1=@ :)
ECHO = $(ECHO1:0=@ echo)
FUZZ_OUTPUT_DIR = $(shell pwd)/fuzz/output

SOEXT := $(shell ruby -e 'puts RbConfig::CONFIG["SOEXT"]')

DEFS := @DEFS@
CPPFLAGS := @DEFS@ -Iinclude
CFLAGS := @CFLAGS@ -std=c99 -Wall -Werror -Wextra -Wpedantic -Wundef -Wsign-conversion -fPIC -fvisibility=hidden
CC := @CC@

HEADERS := $(shell find include -name '*.h')
SOURCES := $(shell find src -name '*.c')
SHARED_OBJECTS := $(subst src/,build/shared/,$(SOURCES:.c=.o))
STATIC_OBJECTS := $(subst src/,build/static/,$(SOURCES:.c=.o))

all: shared static

shared: build/librubyparser.$(SOEXT)
static: build/librubyparser.a

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

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

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

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

build/fuzz.%: $(SOURCES) fuzz/%.c fuzz/fuzz.c
$(ECHO) "building $* fuzzer"
$(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"
$(Q) AFL_HARDEN=1 AFL_LLVM_CMPLOG=1 afl-clang-lto $(DEBUG_FLAGS) $(CPPFLAGS) $(CFLAGS) $(FUZZ_FLAGS) -O0 -fsanitize-ignorelist=fuzz/asan.ignore -fsanitize=fuzzer,address -ggdb3 -std=c99 -Iinclude -o [email protected] $^

build/fuzz.heisenbug.%: $(SOURCES) fuzz/%.c fuzz/heisenbug.c
$(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 $@ $^

fuzz-debug:
$(ECHO) "entering debug shell"
$(Q) docker run -it --rm -e HISTFILE=/yarp/fuzz/output/.bash_history -v $(shell pwd):/yarp -v $(FUZZ_OUTPUT_DIR):/fuzz_output yarp/fuzz

fuzz-docker-build: fuzz/docker/Dockerfile
$(ECHO) "building docker image"
$(Q) docker build -t yarp/fuzz fuzz/docker/

fuzz-run-%: FORCE fuzz-docker-build
$(ECHO) "running $* fuzzer"
$(Q) docker run --rm -v $(shell pwd):/yarp yarp/fuzz /bin/bash -c "FUZZ_FLAGS=\"$(FUZZ_FLAGS)\" make build/fuzz.$*"
$(ECHO) "starting AFL++ run"
$(Q) mkdir -p $(FUZZ_OUTPUT_DIR)/$*
$(Q) docker run -it --rm -v $(shell pwd):/yarp -v $(FUZZ_OUTPUT_DIR):/fuzz_output yarp/fuzz /bin/bash -c "./fuzz/$*.sh /fuzz_output/$*"
FORCE:

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

.PHONY: clean

all-no-debug: DEBUG_FLAGS := -DNDEBUG=1
all-no-debug: OPTFLAGS := -O3
all-no-debug: all
43 changes: 43 additions & 0 deletions src/main/c/yarp/config.h.in
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
/* config.h.in. Generated from configure.ac by autoheader. */

/* Define to 1 if you have the `mmap' function. */
#undef HAVE_MMAP

/* Define to 1 if you have the `snprintf' function. */
#undef HAVE_SNPRINTF

/* Define to 1 if you have the `strncasecmp' function. */
#undef HAVE_STRNCASECMP

/* Define to the address where bug reports for this package should be sent. */
#undef PACKAGE_BUGREPORT

/* Define to the full name of this package. */
#undef PACKAGE_NAME

/* Define to the full name and version of this package. */
#undef PACKAGE_STRING

/* Define to the one symbol short name of this package. */
#undef PACKAGE_TARNAME

/* Define to the home page for this package. */
#undef PACKAGE_URL

/* Define to the version of this package. */
#undef PACKAGE_VERSION

/* YP_VERSION */
#undef YP_VERSION

/* YP_VERSION_MAJOR */
#undef YP_VERSION_MAJOR

/* YP_VERSION_MINOR */
#undef YP_VERSION_MINOR

/* YP_VERSION_PATCH */
#undef YP_VERSION_PATCH

/* _XOPEN_SOURCE */
#undef _XOPEN_SOURCE
Loading