Skip to content

Commit 3b72b32

Browse files
committed
[GR-45043] Build YARP using configure and its Makefile
PullRequest: truffleruby/3891
2 parents 555d379 + 152ffac commit 3b72b32

File tree

134 files changed

+33157
-25301
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

134 files changed

+33157
-25301
lines changed

ci/common.jsonnet

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -42,17 +42,15 @@ local common_json = import "../common.json";
4242
},
4343
for name in std.objectFields(jdks_data)
4444
} + {
45-
local latestJDKCE = self["labsjdk-ce-20"],
46-
local latestJDKEE = self["labsjdk-ee-20"],
4745
# Some convenient JDK aliases which don't require ["name"] for frequently-used JDKs
4846
labsjdk17ce: self["labsjdk-ce-17"],
4947
labsjdk17ee: self["labsjdk-ee-17"],
5048

51-
labsjdk20ce: latestJDKCE,
52-
labsjdk20ee: latestJDKEE,
49+
labsjdk20ce: self["labsjdk-ce-20"],
50+
labsjdk20ee: self["labsjdk-ee-20"],
5351

54-
labsjdkLatestCE: latestJDKCE,
55-
labsjdkLatestEE: latestJDKEE,
52+
labsjdkLatestCE: self["labsjdk-ce-21"],
53+
labsjdkLatestEE: self["labsjdk-ee-21"],
5654
},
5755

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

7069
# Dependencies

common.json

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
"Jsonnet files should not include this file directly but use ci/common.jsonnet instead."
55
],
66

7-
"mx_version": "6.27.3",
7+
"mx_version": "6.27.5",
88

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

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

4545
"oraclejdk22": {"name": "jpg-jdk", "version": "22", "build_id": "1", "release": true, "platformspecific": true, "extrabundles": ["static-libs"]}
4646
},

mx.truffleruby/mx_truffleruby.py

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -121,6 +121,29 @@ def contents(self, result):
121121
command = [jdk.java] + jvm_args + [main_class] + ruby_options + ['"$@"']
122122
return "#!/usr/bin/env bash\n" + "exec " + " ".join(command) + "\n"
123123

124+
125+
class YARPNativeProject(mx.NativeProject):
126+
def __init__(self, suite, name, deps, workingSets, output=None, **kwArgs):
127+
path = join(root, kwArgs.pop('dir'))
128+
super(YARPNativeProject, self).__init__(
129+
suite, name, subDir=None, srcDirs=[path], deps=deps, workingSets=workingSets,
130+
results=kwArgs.pop('results'),
131+
output=path, d=path, vpath=False, **kwArgs)
132+
133+
def getBuildTask(self, args):
134+
return YARPNativeBuildTask(args, self)
135+
136+
class YARPNativeBuildTask(mx.NativeBuildTask):
137+
def build(self):
138+
mx.run(['./configure'], cwd=self.subject.dir)
139+
super(YARPNativeBuildTask, self).build() # make
140+
141+
def clean(self, forBuild=False):
142+
if exists(join(self.subject.dir, 'Makefile')):
143+
super(YARPNativeBuildTask, self).clean(forBuild=forBuild)
144+
else:
145+
pass
146+
124147
# Commands
125148

126149
def jt(*args):

mx.truffleruby/suite.py

Lines changed: 16 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,13 @@
11
suite = {
2-
"mxversion": "6.16.6",
2+
"mxversion": "6.27.5",
33
"name": "truffleruby",
44

55
"imports": {
66
"suites": [
77
{
88
"name": "regex",
99
"subdir": True,
10-
"version": "f2f88bb722a6d10e714fa96351835a84f77d5e15",
10+
"version": "f49685115ed0669641559593242832e06a437278",
1111
"urls": [
1212
{"url": "https://github.com/oracle/graal.git", "kind": "git"},
1313
{"url": "https://curio.ssw.jku.at/nexus/content/repositories/snapshots", "kind": "binary"},
@@ -16,7 +16,7 @@
1616
{
1717
"name": "sulong",
1818
"subdir": True,
19-
"version": "f2f88bb722a6d10e714fa96351835a84f77d5e15",
19+
"version": "f49685115ed0669641559593242832e06a437278",
2020
"urls": [
2121
{"url": "https://github.com/oracle/graal.git", "kind": "git"},
2222
{"url": "https://curio.ssw.jku.at/nexus/content/repositories/snapshots", "kind": "binary"},
@@ -204,16 +204,26 @@
204204
},
205205

206206
"org.yarp.libyarp": {
207+
"class": "YARPNativeProject",
207208
"dir": "src/main/c/yarp",
209+
"makeTarget": "all-no-debug", # Comment this out to build with asserts and no optimizations
210+
"results": ["build/librubyparser.a"],
211+
"description": "YARP used as a static library"
212+
},
213+
214+
"org.truffleruby.yarp.bindings": {
215+
"dir": "src/main/c/yarp_bindings",
208216
"native": "shared_lib",
209217
"deliverable": "yarp",
210218
"buildDependencies": [
219+
"org.yarp.libyarp", # librubyparser.a
211220
"org.yarp", # for the generated JNI header file
212221
],
213222
"use_jdk_headers": True, # the generated JNI header includes jni.h
214-
"cflags": ["-g", "-Wall", "-Werror", "-pthread"],
223+
"cflags": ["-g", "-Wall", "-Werror", "-pthread", "-I<path:org.yarp.libyarp>/include"],
215224
"ldflags": ["-pthread"],
216-
"description": "YARP + JNI bindings as a single lib"
225+
"ldlibs": ["<path:org.yarp.libyarp>/build/librubyparser.a"],
226+
"description": "JNI bindings for YARP"
217227
},
218228

219229
"org.truffleruby": {
@@ -485,7 +495,7 @@
485495
"file:lib/mri",
486496
"file:lib/patches",
487497
"file:lib/truffle",
488-
"dependency:org.yarp.libyarp",
498+
"dependency:org.truffleruby.yarp.bindings",
489499
],
490500
"lib/cext/": [
491501
"file:lib/cext/*.rb",

spec/truffle/yarp_spec.rb

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
# truffleruby_primitives: true
2+
3+
# Copyright (c) 2023 Oracle and/or its affiliates. All rights reserved. This
4+
# code is released under a tri EPL/GPL/LGPL license. You can use it,
5+
# redistribute it and/or modify it under the terms of the:
6+
#
7+
# Eclipse Public License version 2.0, or
8+
# GNU General Public License version 2, or
9+
# GNU Lesser General Public License version 2.1.
10+
11+
require_relative '../ruby/spec_helper'
12+
13+
# Similar tests as in https://github.com/ruby/yarp/blob/main/.github/workflows/truffleruby.yml
14+
describe "YARP" do
15+
root = File.expand_path("../..", __dir__)
16+
17+
guard -> { Dir.exist?("#{root}/src/main/ruby/truffleruby") } do
18+
it "can parse core files" do
19+
Dir.glob("#{root}/src/main/ruby/truffleruby/**/*.rb") do |file|
20+
Truffle::Debug.yarp_parse(File.read(file)).should.include?("Node")
21+
end
22+
end
23+
end
24+
25+
it "can execute simple code" do
26+
-> {
27+
-> {
28+
Truffle::Debug.yarp_execute("p 1+2").should == 3
29+
}.should output_to_fd(/^YARP AST:.+Truffle AST:/m, STDERR)
30+
}.should output("3\n")
31+
end
32+
end

src/main/c/yarp/.gitignore

Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
/.bundle/
2+
/.idea/
3+
/.yardoc
4+
/_yardoc/
5+
/coverage/
6+
/doc/
7+
/pkg/
8+
/spec/reports/
9+
/top-100-gems/
10+
/tmp/
11+
/vendor/bundle
12+
13+
/build/
14+
/lib/yarp/yarp.*
15+
/lib/yarp.bundle
16+
/lib/yarp.so
17+
test.rb
18+
*.dSYM
19+
*~
20+
21+
test.c
22+
a.out
23+
24+
/ext/yarp/api_node.c
25+
/fuzz/output/
26+
/include/yarp/ast.h
27+
/java/org/yarp/AbstractNodeVisitor.java
28+
/java/org/yarp/Loader.java
29+
/java/org/yarp/Nodes.java
30+
/lib/yarp/node.rb
31+
/lib/yarp/serialize.rb
32+
/src/node.c
33+
/src/prettyprint.c
34+
/src/serialize.c
35+
/src/token_type.c
36+
/src/**/*.o
37+
38+
compile_commands.json
39+
.cache/
40+
41+
autom4te.cache
42+
configure
43+
config.log
44+
config.status
45+
Makefile
46+
/include/yarp/config.h
47+
/config.h.in
48+
49+
tags

src/main/c/yarp/LICENSE.md

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
Copyright 2022-present, Shopify Inc.
2+
3+
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:
4+
5+
The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
6+
7+
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.

src/main/c/yarp/Makefile.in

Lines changed: 79 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,79 @@
1+
2+
# V=0 quiet, V=1 verbose. other values don't work.
3+
V = 0
4+
V0 = $(V:0=)
5+
Q1 = $(V:1=)
6+
Q = $(Q1:0=@)
7+
ECHO1 = $(V:1=@ :)
8+
ECHO = $(ECHO1:0=@ echo)
9+
FUZZ_OUTPUT_DIR = $(shell pwd)/fuzz/output
10+
11+
SOEXT := $(shell ruby -e 'puts RbConfig::CONFIG["SOEXT"]')
12+
13+
DEFS := @DEFS@
14+
CPPFLAGS := @DEFS@ -Iinclude
15+
CFLAGS := @CFLAGS@ -std=c99 -Wall -Werror -Wextra -Wpedantic -Wundef -Wsign-conversion -fPIC -fvisibility=hidden
16+
CC := @CC@
17+
18+
HEADERS := $(shell find include -name '*.h')
19+
SOURCES := $(shell find src -name '*.c')
20+
SHARED_OBJECTS := $(subst src/,build/shared/,$(SOURCES:.c=.o))
21+
STATIC_OBJECTS := $(subst src/,build/static/,$(SOURCES:.c=.o))
22+
23+
all: shared static
24+
25+
shared: build/librubyparser.$(SOEXT)
26+
static: build/librubyparser.a
27+
28+
build/librubyparser.$(SOEXT): $(SHARED_OBJECTS)
29+
$(ECHO) "linking $@"
30+
$(Q) $(CC) $(DEBUG_FLAGS) $(CFLAGS) -shared -o $@ $(SHARED_OBJECTS)
31+
32+
build/librubyparser.a: $(STATIC_OBJECTS)
33+
$(ECHO) "building $@"
34+
$(Q) $(AR) $(ARFLAGS) $@ $(STATIC_OBJECTS) $(Q1:0=>/dev/null)
35+
36+
build/shared/%.o: src/%.c Makefile $(HEADERS)
37+
$(ECHO) "compiling $@"
38+
$(Q) mkdir -p $(@D)
39+
$(Q) $(CC) $(DEBUG_FLAGS) $(CPPFLAGS) $(CFLAGS) -c -o $@ $<
40+
41+
build/static/%.o: src/%.c Makefile $(HEADERS)
42+
$(ECHO) "compiling $@"
43+
$(Q) mkdir -p $(@D)
44+
$(Q) $(CC) $(DEBUG_FLAGS) -DYP_STATIC $(CPPFLAGS) $(CFLAGS) -c -o $@ $<
45+
46+
build/fuzz.%: $(SOURCES) fuzz/%.c fuzz/fuzz.c
47+
$(ECHO) "building $* fuzzer"
48+
$(ECHO) "building main fuzz binary"
49+
$(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 $@ $^
50+
$(ECHO) "building cmplog binary"
51+
$(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 $@.cmplog $^
52+
53+
build/fuzz.heisenbug.%: $(SOURCES) fuzz/%.c fuzz/heisenbug.c
54+
$(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 $@ $^
55+
56+
fuzz-debug:
57+
$(ECHO) "entering debug shell"
58+
$(Q) docker run -it --rm -e HISTFILE=/yarp/fuzz/output/.bash_history -v $(shell pwd):/yarp -v $(FUZZ_OUTPUT_DIR):/fuzz_output yarp/fuzz
59+
60+
fuzz-docker-build: fuzz/docker/Dockerfile
61+
$(ECHO) "building docker image"
62+
$(Q) docker build -t yarp/fuzz fuzz/docker/
63+
64+
fuzz-run-%: FORCE fuzz-docker-build
65+
$(ECHO) "running $* fuzzer"
66+
$(Q) docker run --rm -v $(shell pwd):/yarp yarp/fuzz /bin/bash -c "FUZZ_FLAGS=\"$(FUZZ_FLAGS)\" make build/fuzz.$*"
67+
$(ECHO) "starting AFL++ run"
68+
$(Q) mkdir -p $(FUZZ_OUTPUT_DIR)/$*
69+
$(Q) docker run -it --rm -v $(shell pwd):/yarp -v $(FUZZ_OUTPUT_DIR):/fuzz_output yarp/fuzz /bin/bash -c "./fuzz/$*.sh /fuzz_output/$*"
70+
FORCE:
71+
72+
clean:
73+
$(Q) rm -f -r build
74+
75+
.PHONY: clean
76+
77+
all-no-debug: DEBUG_FLAGS := -DNDEBUG=1
78+
all-no-debug: OPTFLAGS := -O3
79+
all-no-debug: all

src/main/c/yarp/config.h.in

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
/* config.h.in. Generated from configure.ac by autoheader. */
2+
3+
/* Define to 1 if you have the `mmap' function. */
4+
#undef HAVE_MMAP
5+
6+
/* Define to 1 if you have the `snprintf' function. */
7+
#undef HAVE_SNPRINTF
8+
9+
/* Define to 1 if you have the `strncasecmp' function. */
10+
#undef HAVE_STRNCASECMP
11+
12+
/* Define to the address where bug reports for this package should be sent. */
13+
#undef PACKAGE_BUGREPORT
14+
15+
/* Define to the full name of this package. */
16+
#undef PACKAGE_NAME
17+
18+
/* Define to the full name and version of this package. */
19+
#undef PACKAGE_STRING
20+
21+
/* Define to the one symbol short name of this package. */
22+
#undef PACKAGE_TARNAME
23+
24+
/* Define to the home page for this package. */
25+
#undef PACKAGE_URL
26+
27+
/* Define to the version of this package. */
28+
#undef PACKAGE_VERSION
29+
30+
/* YP_VERSION */
31+
#undef YP_VERSION
32+
33+
/* YP_VERSION_MAJOR */
34+
#undef YP_VERSION_MAJOR
35+
36+
/* YP_VERSION_MINOR */
37+
#undef YP_VERSION_MINOR
38+
39+
/* YP_VERSION_PATCH */
40+
#undef YP_VERSION_PATCH
41+
42+
/* _XOPEN_SOURCE */
43+
#undef _XOPEN_SOURCE

0 commit comments

Comments
 (0)