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

feat: basic support for buck2 #3294

Closed
wants to merge 15 commits into from
Closed
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
The table of contents is too big for display.
Diff view
Diff view
  •  
  •  
  •  
21 changes: 21 additions & 0 deletions .buckconfig
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
[repositories]
root = .
prelude = prelude
toolchains = toolchains
none = none

[repository_aliases]
config = prelude
fbcode = none
fbsource = none
buck = none

[parser]
target_platform_detector_spec = target:root//...->prelude//platforms:default

[project]
ignore = \
.git, \
core/**/node_modules, \
shim/custom-third-party/node/**/node_modules

Empty file added .buckroot
Empty file.
63 changes: 63 additions & 0 deletions .editorconfig
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
root = true

[*]
charset = utf-8
tab_width = 4
end_of_line = lf
insert_final_newline = true
trim_trailing_whitespace = true

[*.nix]
indent_style = space
indent_size = 2
tab_width = 2
max_line_length = 80

[*.rs]
indent_style = space
tab_width = 4
insert_final_newline = true
end_of_line = lf

[*.sh]
indent_style = space
indent_size = 2
max_line_length = 80
binary_next_line = true
switch_case_indent = true

[*.py]
indent_style = space
indent_size = 4
tab_width = 4
max_line_length = 80

[BUCK]
indent_style = space
indent_size = 4
tab_width = 4
max_line_length = 100

[*.bzl]
indent_style = space
indent_size = 4
tab_width = 4
max_line_length = 100

[*.bxl]
indent_style = space
indent_size = 4
tab_width = 4
max_line_length = 100

[Tiltfile]
indent_style = space
indent_size = 4
tab_width = 4
max_line_length = 100

[Dockerfile]
indent_style = space
indent_size = 4
max_line_length = 80

19 changes: 19 additions & 0 deletions .github/workflows/buck2-build.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
name: "Buck2 build"

on:
pull_request:
branches: [main]

jobs:
buck2_build:
name: Buck2 Build
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
with:
ref: ${{ github.event.pull_request.head.sha }}
- uses: cachix/install-nix-action@v22
with:
github_access_token: ${{ secrets.GITHUB_TOKEN }}
- name: Buck2 build
run: nix develop -c buck2 build //core/api:api
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -46,3 +46,5 @@ junit.xml

.direnv
.env.local

buck-out
9 changes: 9 additions & 0 deletions BUCK
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
load("@toolchains//workspace-pnpm:macros.bzl", "pnpm_workspace")

pnpm_workspace(
name = "workspace",
child_packages = [
"//core/api:package.json"
],
visibility = ["PUBLIC"],
)
37 changes: 37 additions & 0 deletions core/api/BUCK
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
load("@toolchains//workspace-pnpm:macros.bzl", "build_node_modules", "tsc_build")

export_file(
name = "package.json",
visibility = ["PUBLIC"],
)

build_node_modules(
name = "node_modules",
)

filegroup(
name = "src",
srcs = glob([
"src/**",
"tsconfig.json",
"tsconfig-build.json",
]),
)

tsc_build(
name = "api",
tsconfig = "tsconfig-build.json",
srcs = [":src"],
)

# // install deps
# // ^^ simple toolchain
# // compile via tsc
# // ^^ tsc_bin
# // ^^ tsc_compile
# // run via node
# // ^^ exec via pnpm toolchain?

# npm_bin(
# name = "api"
# )
2 changes: 1 addition & 1 deletion core/api/package.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
{
"name": "galoy",
"name": "api",
"scripts": {
"tsc-check-noimplicitany": "tsc --noEmit -p tsconfig.no-implicit-any.json",
"tsc-check": "tsc --noEmit -p tsconfig.d.json && tsc --noEmit",
Expand Down
11 changes: 11 additions & 0 deletions dev/BUCK
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
load( ":tilt.bzl", "tilt_down", "tilt_up",)

# Bring up the full set of services for development
tilt_up(
name = "up",
)

# Bring down any remaining/running services
tilt_down(
name = "down",
)
7 changes: 7 additions & 0 deletions dev/Tiltfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
api_target = "//core/api:api"
local_resource(
"api",
labels = ["frontend"],
cmd = "buck2 build {}".format(api_target),
serve_cmd = "buck2 run {}".format(api_target),
)
69 changes: 69 additions & 0 deletions dev/tilt.bzl
Original file line number Diff line number Diff line change
@@ -0,0 +1,69 @@
def tilt_up_impl(ctx: AnalysisContext) -> list[[DefaultInfo, RunInfo]]:
return _invoke_tilt(ctx, "up")

tilt_up = rule(
impl = tilt_up_impl,
attrs = {
"tiltfile": attrs.string(
default = "Tiltfile",
doc = """The Tiltfile to run.""",
),
"args": attrs.list(
attrs.string(),
default = [],
doc = """Additional arguments passed as <Tiltfile args>.""",
),
"tilt_args": attrs.list(
attrs.string(),
default = [],
doc = """Additional arguments passed as `tilt` arguments.""",
),
},
)

def tilt_down_impl(ctx: AnalysisContext) -> list[[DefaultInfo, RunInfo]]:
return _invoke_tilt(ctx, "down")

tilt_down = rule(
impl = tilt_down_impl,
attrs = {
"tiltfile": attrs.string(
default = "Tiltfile",
doc = """The Tiltfile to run.""",
),
"args": attrs.list(
attrs.string(),
default = [],
doc = """Additional arguments passed as <Tiltfile args>.""",
),
"tilt_args": attrs.list(
attrs.string(),
default = [],
doc = """Additional arguments passed as `tilt` arguments.""",
),
},
)

def _invoke_tilt(ctx: AnalysisContext, subcmd: str) -> list[[DefaultInfo, RunInfo]]:
tiltfile = "{}/{}".format(
ctx.label.package,
ctx.attrs.tiltfile,
)

run_cmd_args = cmd_args([
"tilt",
subcmd,
"--file",
tiltfile,
])
run_cmd_args.add(ctx.attrs.tilt_args)
run_cmd_args.add("--")
run_cmd_args.add(ctx.attrs.args)

args_file = ctx.actions.write("tilt-args.txt", run_cmd_args)

return [
DefaultInfo(default_output = args_file),
RunInfo(run_cmd_args),
]

6 changes: 3 additions & 3 deletions flake.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 2 additions & 0 deletions flake.nix
Original file line number Diff line number Diff line change
Expand Up @@ -42,10 +42,12 @@
jq
ytt
];
buck2Version = pkgs.buck2.version;
in
with pkgs; {
devShells.default = mkShell {
inherit nativeBuildInputs;
BUCK2_VERSION = buck2Version;
};

formatter = alejandra;
Expand Down
21 changes: 21 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
{
"name": "si",
"version": "1.0.0",
"description": "galoy monorepo",
"scripts": {
"preinstall": "npx only-allow pnpm",
"nodev": "node -v",
"whichnode": "which node"
},
"engines": {
"node": "20",
"pnpm": "8"
},
"resolutions": {
"protobufjs": "7.2.5",
"http-cache-semantics": "4.1.1",
"import-in-the-middle": "1.4.2"
},
"packageManager": "[email protected]"
}

Loading