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

Use improved libprism source to build Prism without dependency on Ruby #400

Merged
merged 3 commits into from
Jan 13, 2025
Merged
Show file tree
Hide file tree
Changes from 2 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
3 changes: 0 additions & 3 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,6 @@ on:
branches: [prism]
pull_request:
branches: [prism]
env:
RUBY_ROOT: '/opt/hostedtoolcache/Ruby/3.3.0/x64'

Choose a reason for hiding this comment

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

🏆


jobs:
tests:
runs-on: ubuntu-latest
Expand Down
2 changes: 0 additions & 2 deletions WORKSPACE
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,8 @@ workspace(name = "com_stripe_ruby_typer")

load("@bazel_tools//tools/build_defs/repo:http.bzl", "http_archive")
load("//third_party:externals.bzl", "register_sorbet_dependencies")
load("//third_party:ruby_root.bzl", "ruby_root")

register_sorbet_dependencies()
ruby_root(name = "ruby_root")

load("@rules_foreign_cc//foreign_cc:repositories.bzl", "rules_foreign_cc_dependencies")

Expand Down
6 changes: 3 additions & 3 deletions third_party/externals.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -12,10 +12,10 @@ def register_sorbet_dependencies():

http_archive(
name = "prism",
url = "https://github.com/ruby/prism/archive/v1.2.0.zip",
sha256 = "f398cdb0ed9e5f9b8f7127a8c180ed6a8a611ad4612dcdae8a91ebfc5ee0ed7c",
strip_prefix = "prism-1.2.0",
url = "https://github.com/Shopify/prism/releases/download/v1.3.2/libprism-src.tar.gz",
sha256 = "a2c5711fdd9609ec15970778d852104def39bbced1c86647ca1ecef28bf94839",
build_file = "@com_stripe_ruby_typer//third_party:prism.BUILD",
strip_prefix = "libprism-src",
)

http_archive(
Expand Down
55 changes: 2 additions & 53 deletions third_party/prism.BUILD
Original file line number Diff line number Diff line change
@@ -1,58 +1,7 @@
load("@ruby_root//:ruby_root.bzl", "RUBY_ROOT") # Get the RUBY_ROOT environment variable

GENERATED_SRCS = [
"src/diagnostic.c",
"src/node.c",
"src/prettyprint.c",
"src/serialize.c",
"src/token_type.c",
]

GENERATED_HDRS = [
"include/prism/ast.h",
"include/prism/diagnostic.h",
]

genrule(
name = "generate_templates",
srcs = [
"templates/template.rb",
"prism.gemspec",
"Gemfile",
"Gemfile.lock",
"config.yml", # Contains the data to populate the ERB templates.
] + \
["templates/{c_file}.erb".format(c_file = c_file) for c_file in GENERATED_SRCS] + \
["templates/{h_file}.erb".format(h_file = h_file) for h_file in GENERATED_HDRS],
outs = GENERATED_HDRS + GENERATED_SRCS,
cmd = """
# set -o xtrace # Uncomment this to debug the execution of this script.
# echo "PWD: $$PWD"
# echo "RULEDIR: $(RULEDIR)"

export PATH="{ruby_root}/bin:$$PATH"

gemfile="$(location Gemfile)"
script="$(location templates/template.rb)"

bundle install --gemfile="$$gemfile"

{template_render_commands}

""".format(
ruby_root = RUBY_ROOT,
template_render_commands = "\n ".join([
"""
bundle exec --gemfile="$$gemfile" ruby "$$script" {f} "$(location {f})"
""".format(f=f) for f in (GENERATED_SRCS + GENERATED_HDRS)
])
),
)

cc_library(
name = "prism",
srcs = glob(["src/**/*.c"], exclude=GENERATED_SRCS) + [":generate_templates"],
hdrs = glob(["include/**/*.h"], exclude=GENERATED_HDRS) + [":generate_templates"],
srcs = glob(["src/**/*.c"]),
hdrs = glob(["include/**/*.h"]),
visibility = ["//visibility:public"],
includes = ["include"],
copts = ["-Wno-implicit-fallthrough"],
Expand Down
20 changes: 0 additions & 20 deletions third_party/ruby_root.bzl

This file was deleted.

2 changes: 1 addition & 1 deletion tools/scripts/verify_prism_regression_tests.sh
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
set -euo pipefail

echo "Building Sorbet..."
./bazel build //main:sorbet --config=dbg --define RUBY_PATH=$RUBY_ROOT
./bazel build //main:sorbet --config=dbg

echo "Verifying parse trees..."

Expand Down
Loading