Mercurial
comparison gui_ze/gui_ze.bzl @ 25:342726584be2
[Bun] Fixed how bun would be ran within bazel.
| author | June Park <parkjune1995@gmail.com> |
|---|---|
| date | Thu, 09 Oct 2025 06:41:02 -0700 |
| parents | 7d3fa1a7a854 |
| children | ccb42d5bf8fd |
comparison
equal
deleted
inserted
replaced
| 24:7d3fa1a7a854 | 25:342726584be2 |
|---|---|
| 73 outputs = [out], | 73 outputs = [out], |
| 74 command = """ | 74 command = """ |
| 75 mkdir -p {outdir} | 75 mkdir -p {outdir} |
| 76 unzip -j {src} {inner} -d {outdir} | 76 unzip -j {src} {inner} -d {outdir} |
| 77 chmod +x {outdir}/bun | 77 chmod +x {outdir}/bun |
| 78 mv {outdir}/bun {out} | |
| 79 """.format( | 78 """.format( |
| 80 outdir = out.dirname, | 79 outdir = out.dirname, |
| 81 src = ctx.files.srcs[0].path, | 80 src = ctx.files.srcs[0].path, |
| 82 inner = ctx.attr.src_folder, | 81 inner = ctx.attr.src_folder, |
| 83 out = out.path, | 82 out = out.path, |
| 89 ) | 88 ) |
| 90 | 89 |
| 91 bun_binary = rule( | 90 bun_binary = rule( |
| 92 implementation = _bun_binary_impl, | 91 implementation = _bun_binary_impl, |
| 93 attrs = { | 92 attrs = { |
| 94 "srcs": attr.label_list(allow_files=True), | 93 "srcs": attr.label_list(allow_files=True), |
| 95 "src_folder": attr.string(), | 94 "src_folder": attr.string(), |
| 96 }, | 95 }, |
| 97 executable = True, | 96 executable = True, |
| 98 ) | 97 ) |
| 99 | 98 |
| 100 def _bun_build_impl(ctx): | 99 def _bun_build_impl(ctx): |
| 102 Run bun build on the folder | 101 Run bun build on the folder |
| 103 | 102 |
| 104 This sucks because you need to either copy node module into the root folder where main.ts file | 103 This sucks because you need to either copy node module into the root folder where main.ts file |
| 105 exists or copy everything outwards. I chose to do it in this way. | 104 exists or copy everything outwards. I chose to do it in this way. |
| 106 | 105 |
| 107 TODO: If possible, maybe create a node_module inside of the main target path and create a symlink, | 106 TODO: If possible, maybe create a node_module inside of the main target path and create a symlink |
| 108 but I couldn't get it to work lol. | 107 TODO: Add a specific path for node_modules |
| 109 """ | 108 """ |
| 110 out = ctx.actions.declare_file(ctx.label.name + ".js") | 109 out = ctx.actions.declare_file(ctx.label.name + ".js") |
| 111 inputs = [ctx.file.src] + ctx.files.data | 110 inputs = [ctx.file.src] + ctx.files.data |
| 112 | 111 |
| 113 ctx.actions.run_shell( | 112 ctx.actions.run_shell( |
| 114 inputs = inputs, | 113 inputs = inputs, |
| 115 outputs = [out], | 114 outputs = [out], |
| 116 tools = [ctx.executable._bun] + inputs, | 115 tools = [ctx.executable._bun] + inputs, |
| 117 command = """ | 116 command = """ |
| 118 cp -r third_party/bun/** . \ | 117 cp -r third_party/bun/** . \ |
| 119 && cp -r playground/** . \ | 118 && cp -r {src_folder}/** . \ |
| 120 && {} build {} --outfile {} | 119 && export NODE_PATH=./node_modules && {bun_path} build {input_path} --outfile {output_path} |
| 121 """.format( | 120 """.format( |
| 122 ctx.executable._bun.path, | 121 bun_path = ctx.executable._bun.path, |
| 123 ctx.file.src.path.split("/")[-1], | 122 src_folder = ctx.attr.src_folder, |
| 124 out.path, | 123 input_path = ctx.file.src.path.split("/")[-1], |
| 124 output_path = out.path, | |
| 125 ), | 125 ), |
| 126 progress_message = "Bundling {} with Bun!\n\n".format(ctx.file.src.path), | 126 progress_message = "Bundling {} with Bun!\n\n".format(ctx.file.src.path), |
| 127 ) | 127 ) |
| 128 | 128 |
| 129 return [DefaultInfo(files=depset([out]))] | 129 return [DefaultInfo(files=depset([out]))] |
| 136 default = Label("//third_party/bun:bun"), | 136 default = Label("//third_party/bun:bun"), |
| 137 executable = True, | 137 executable = True, |
| 138 cfg = "exec", | 138 cfg = "exec", |
| 139 ), | 139 ), |
| 140 "data": attr.label_list(allow_files=True), | 140 "data": attr.label_list(allow_files=True), |
| 141 "src_folder": attr.string(), | |
| 141 }, | 142 }, |
| 142 ) | 143 ) |
| 143 | 144 |
| 144 def _move_files_into_dir_impl(ctx): | 145 def _move_files_into_dir_impl(ctx): |
| 145 srcs = ctx.files.srcs | 146 srcs = ctx.files.srcs |