Mercurial
annotate gui_ze/gui_ze.bzl @ 243:823f2a8b16c8
[repo] Ignore Vim swap files
| author | MrJuneJune <me@mrjunejune.com> |
|---|---|
| date | Mon, 03 Aug 2026 15:26:44 -0700 |
| parents | 9c2eec61a152 |
| children | 70f2a3dafc1c |
| rev | line source |
|---|---|
|
8
98f96b8032e5
[GuiZe] Creating custom bazel rule to deploy to github easily.
June Park <parkjune1995@gmail.com>
parents:
diff
changeset
|
1 def _foo_impl(ctx): |
|
12
de54585a40f1
Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents:
8
diff
changeset
|
2 out = ctx.actions.declare_file(ctx.label.name) |
|
de54585a40f1
Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents:
8
diff
changeset
|
3 ctx.actions.write( |
|
de54585a40f1
Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents:
8
diff
changeset
|
4 output = out, |
|
de54585a40f1
Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents:
8
diff
changeset
|
5 content = "Hello!\n", |
|
de54585a40f1
Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents:
8
diff
changeset
|
6 ) |
|
de54585a40f1
Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents:
8
diff
changeset
|
7 return [DefaultInfo(files = depset([out]))] |
|
8
98f96b8032e5
[GuiZe] Creating custom bazel rule to deploy to github easily.
June Park <parkjune1995@gmail.com>
parents:
diff
changeset
|
8 |
|
98f96b8032e5
[GuiZe] Creating custom bazel rule to deploy to github easily.
June Park <parkjune1995@gmail.com>
parents:
diff
changeset
|
9 foo_binary = rule( |
|
98f96b8032e5
[GuiZe] Creating custom bazel rule to deploy to github easily.
June Park <parkjune1995@gmail.com>
parents:
diff
changeset
|
10 implementation = _foo_impl, |
|
98f96b8032e5
[GuiZe] Creating custom bazel rule to deploy to github easily.
June Park <parkjune1995@gmail.com>
parents:
diff
changeset
|
11 ) |
|
98f96b8032e5
[GuiZe] Creating custom bazel rule to deploy to github easily.
June Park <parkjune1995@gmail.com>
parents:
diff
changeset
|
12 |
|
12
de54585a40f1
Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents:
8
diff
changeset
|
13 def _bundle_impl(ctx): |
|
de54585a40f1
Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents:
8
diff
changeset
|
14 """ |
|
de54585a40f1
Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents:
8
diff
changeset
|
15 bundle binary target into a folder which can later be used to make a post to github easily. |
|
de54585a40f1
Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents:
8
diff
changeset
|
16 """ |
|
de54585a40f1
Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents:
8
diff
changeset
|
17 binary_target = ctx.attr.binary |
|
de54585a40f1
Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents:
8
diff
changeset
|
18 binary = binary_target[DefaultInfo].files.to_list()[0] # First files are binary |
|
de54585a40f1
Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents:
8
diff
changeset
|
19 runfiles_files = binary_target[DefaultInfo].default_runfiles.files.to_list() |
|
de54585a40f1
Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents:
8
diff
changeset
|
20 |
|
de54585a40f1
Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents:
8
diff
changeset
|
21 # Name as output directory |
|
de54585a40f1
Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents:
8
diff
changeset
|
22 out_dir = ctx.actions.declare_directory(ctx.label.name) |
|
de54585a40f1
Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents:
8
diff
changeset
|
23 |
|
de54585a40f1
Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents:
8
diff
changeset
|
24 copy_cmd = [] |
|
de54585a40f1
Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents:
8
diff
changeset
|
25 copy_cmd.append("mkdir -p {}".format(out_dir.path)) |
|
de54585a40f1
Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents:
8
diff
changeset
|
26 |
|
de54585a40f1
Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents:
8
diff
changeset
|
27 for f in runfiles_files: |
|
de54585a40f1
Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents:
8
diff
changeset
|
28 if f.path == binary.path: |
|
de54585a40f1
Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents:
8
diff
changeset
|
29 continue |
|
15
2b9e75756825
[GuiZe] Updated to handle bundling and created a shee
June Park <parkjune1995@gmail.com>
parents:
12
diff
changeset
|
30 |
|
2b9e75756825
[GuiZe] Updated to handle bundling and created a shee
June Park <parkjune1995@gmail.com>
parents:
12
diff
changeset
|
31 start = 0 |
|
2b9e75756825
[GuiZe] Updated to handle bundling and created a shee
June Park <parkjune1995@gmail.com>
parents:
12
diff
changeset
|
32 for directory in f.path.split("/"): |
|
2b9e75756825
[GuiZe] Updated to handle bundling and created a shee
June Park <parkjune1995@gmail.com>
parents:
12
diff
changeset
|
33 if directory == binary.short_path.split("/")[0]: |
|
2b9e75756825
[GuiZe] Updated to handle bundling and created a shee
June Park <parkjune1995@gmail.com>
parents:
12
diff
changeset
|
34 break |
|
2b9e75756825
[GuiZe] Updated to handle bundling and created a shee
June Park <parkjune1995@gmail.com>
parents:
12
diff
changeset
|
35 start += 1 |
|
2b9e75756825
[GuiZe] Updated to handle bundling and created a shee
June Park <parkjune1995@gmail.com>
parents:
12
diff
changeset
|
36 |
|
12
de54585a40f1
Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents:
8
diff
changeset
|
37 # Remove the first folder (output) and last file (actaul files that needed to be copied) |
|
15
2b9e75756825
[GuiZe] Updated to handle bundling and created a shee
June Park <parkjune1995@gmail.com>
parents:
12
diff
changeset
|
38 paths = "/".join(f.path.split("/")[start:-1]) |
|
12
de54585a40f1
Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents:
8
diff
changeset
|
39 full_path = "{}/{}".format(out_dir.path, paths) |
|
de54585a40f1
Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents:
8
diff
changeset
|
40 copy_cmd.append("mkdir -p {}".format(full_path)) |
|
de54585a40f1
Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents:
8
diff
changeset
|
41 copy_cmd.append("cp {} {}".format(f.path, full_path)) |
|
de54585a40f1
Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents:
8
diff
changeset
|
42 |
|
de54585a40f1
Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents:
8
diff
changeset
|
43 copy_cmd.append("cp {} {}".format(binary.path, out_dir.path)) |
|
de54585a40f1
Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents:
8
diff
changeset
|
44 |
|
de54585a40f1
Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents:
8
diff
changeset
|
45 ctx.actions.run_shell( |
|
de54585a40f1
Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents:
8
diff
changeset
|
46 inputs = runfiles_files, |
|
de54585a40f1
Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents:
8
diff
changeset
|
47 outputs = [out_dir], |
|
de54585a40f1
Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents:
8
diff
changeset
|
48 command = " && ".join(copy_cmd), |
|
de54585a40f1
Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents:
8
diff
changeset
|
49 progress_message = "Bundling {}".format(ctx.label.name), |
|
de54585a40f1
Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents:
8
diff
changeset
|
50 ) |
|
de54585a40f1
Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents:
8
diff
changeset
|
51 return [DefaultInfo(files = depset([out_dir]))] |
|
de54585a40f1
Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents:
8
diff
changeset
|
52 |
|
de54585a40f1
Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents:
8
diff
changeset
|
53 bundle = rule( |
|
de54585a40f1
Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents:
8
diff
changeset
|
54 implementation = _bundle_impl, |
|
de54585a40f1
Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents:
8
diff
changeset
|
55 attrs = { |
|
de54585a40f1
Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents:
8
diff
changeset
|
56 "binary": attr.label( |
|
de54585a40f1
Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents:
8
diff
changeset
|
57 doc = "The cc_binary target to bundle", |
|
de54585a40f1
Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents:
8
diff
changeset
|
58 providers = [DefaultInfo], |
|
de54585a40f1
Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents:
8
diff
changeset
|
59 ), |
|
de54585a40f1
Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents:
8
diff
changeset
|
60 }, |
|
de54585a40f1
Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents:
8
diff
changeset
|
61 ) |
|
de54585a40f1
Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents:
8
diff
changeset
|
62 |
|
de54585a40f1
Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents:
8
diff
changeset
|
63 |
|
de54585a40f1
Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents:
8
diff
changeset
|
64 def _bun_binary_impl(ctx): |
|
de54585a40f1
Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents:
8
diff
changeset
|
65 out = ctx.actions.declare_file("bun") |
|
de54585a40f1
Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents:
8
diff
changeset
|
66 ctx.actions.run_shell( |
|
de54585a40f1
Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents:
8
diff
changeset
|
67 inputs = ctx.files.srcs, |
|
de54585a40f1
Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents:
8
diff
changeset
|
68 outputs = [out], |
|
de54585a40f1
Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents:
8
diff
changeset
|
69 command = """ |
|
de54585a40f1
Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents:
8
diff
changeset
|
70 mkdir -p {outdir} |
|
de54585a40f1
Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents:
8
diff
changeset
|
71 unzip -j {src} {inner} -d {outdir} |
|
de54585a40f1
Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents:
8
diff
changeset
|
72 chmod +x {outdir}/bun |
|
de54585a40f1
Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents:
8
diff
changeset
|
73 """.format( |
|
de54585a40f1
Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents:
8
diff
changeset
|
74 outdir = out.dirname, |
|
de54585a40f1
Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents:
8
diff
changeset
|
75 src = ctx.files.srcs[0].path, |
|
24
7d3fa1a7a854
[GuiZe] Support x86 chip for bun.
June Park <parkjune1995@gmail.com>
parents:
15
diff
changeset
|
76 inner = ctx.attr.src_folder, |
|
12
de54585a40f1
Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents:
8
diff
changeset
|
77 out = out.path, |
|
de54585a40f1
Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents:
8
diff
changeset
|
78 ), |
|
de54585a40f1
Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents:
8
diff
changeset
|
79 ) |
|
de54585a40f1
Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents:
8
diff
changeset
|
80 return DefaultInfo( |
|
de54585a40f1
Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents:
8
diff
changeset
|
81 files = depset([out]), |
|
de54585a40f1
Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents:
8
diff
changeset
|
82 executable = out, |
|
de54585a40f1
Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents:
8
diff
changeset
|
83 ) |
|
de54585a40f1
Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents:
8
diff
changeset
|
84 |
|
de54585a40f1
Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents:
8
diff
changeset
|
85 bun_binary = rule( |
|
de54585a40f1
Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents:
8
diff
changeset
|
86 implementation = _bun_binary_impl, |
|
de54585a40f1
Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents:
8
diff
changeset
|
87 attrs = { |
|
25
342726584be2
[Bun] Fixed how bun would be ran within bazel.
June Park <parkjune1995@gmail.com>
parents:
24
diff
changeset
|
88 "srcs": attr.label_list(allow_files=True), |
|
342726584be2
[Bun] Fixed how bun would be ran within bazel.
June Park <parkjune1995@gmail.com>
parents:
24
diff
changeset
|
89 "src_folder": attr.string(), |
|
12
de54585a40f1
Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents:
8
diff
changeset
|
90 }, |
|
de54585a40f1
Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents:
8
diff
changeset
|
91 executable = True, |
|
de54585a40f1
Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents:
8
diff
changeset
|
92 ) |
|
de54585a40f1
Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents:
8
diff
changeset
|
93 |
|
190
a2725419f988
Updated so that bun builds will with already existing js files.
MrJuneJune <me@mrjunejune.com>
parents:
186
diff
changeset
|
94 def _bun_bundle_impl(ctx): |
|
a2725419f988
Updated so that bun builds will with already existing js files.
MrJuneJune <me@mrjunejune.com>
parents:
186
diff
changeset
|
95 """ |
|
a2725419f988
Updated so that bun builds will with already existing js files.
MrJuneJune <me@mrjunejune.com>
parents:
186
diff
changeset
|
96 Bundle TypeScript/JavaScript with Bun, resolving imports from bazel root. |
|
a2725419f988
Updated so that bun builds will with already existing js files.
MrJuneJune <me@mrjunejune.com>
parents:
186
diff
changeset
|
97 |
|
a2725419f988
Updated so that bun builds will with already existing js files.
MrJuneJune <me@mrjunejune.com>
parents:
186
diff
changeset
|
98 Copies all dependencies (dereferencing symlinks) to create a flat structure |
|
a2725419f988
Updated so that bun builds will with already existing js files.
MrJuneJune <me@mrjunejune.com>
parents:
186
diff
changeset
|
99 where imports can resolve correctly relative to the bazel workspace root. |
|
a2725419f988
Updated so that bun builds will with already existing js files.
MrJuneJune <me@mrjunejune.com>
parents:
186
diff
changeset
|
100 """ |
|
a2725419f988
Updated so that bun builds will with already existing js files.
MrJuneJune <me@mrjunejune.com>
parents:
186
diff
changeset
|
101 out = ctx.actions.declare_file(ctx.label.name + ".js") |
|
a2725419f988
Updated so that bun builds will with already existing js files.
MrJuneJune <me@mrjunejune.com>
parents:
186
diff
changeset
|
102 |
|
a2725419f988
Updated so that bun builds will with already existing js files.
MrJuneJune <me@mrjunejune.com>
parents:
186
diff
changeset
|
103 inputs = depset( |
|
a2725419f988
Updated so that bun builds will with already existing js files.
MrJuneJune <me@mrjunejune.com>
parents:
186
diff
changeset
|
104 direct = [ctx.file.src], |
|
a2725419f988
Updated so that bun builds will with already existing js files.
MrJuneJune <me@mrjunejune.com>
parents:
186
diff
changeset
|
105 transitive = [dep[DefaultInfo].files for dep in ctx.attr.deps] |
|
a2725419f988
Updated so that bun builds will with already existing js files.
MrJuneJune <me@mrjunejune.com>
parents:
186
diff
changeset
|
106 ) |
|
a2725419f988
Updated so that bun builds will with already existing js files.
MrJuneJune <me@mrjunejune.com>
parents:
186
diff
changeset
|
107 |
|
a2725419f988
Updated so that bun builds will with already existing js files.
MrJuneJune <me@mrjunejune.com>
parents:
186
diff
changeset
|
108 # Get the source file's package directory (e.g., "hg-web" from "hg-web/src/main.tsx") |
|
a2725419f988
Updated so that bun builds will with already existing js files.
MrJuneJune <me@mrjunejune.com>
parents:
186
diff
changeset
|
109 src_package = ctx.file.src.path.split("/")[0] |
|
a2725419f988
Updated so that bun builds will with already existing js files.
MrJuneJune <me@mrjunejune.com>
parents:
186
diff
changeset
|
110 |
|
a2725419f988
Updated so that bun builds will with already existing js files.
MrJuneJune <me@mrjunejune.com>
parents:
186
diff
changeset
|
111 # Collect unique root directories to copy (deduped), excluding src_package (handled separately) |
|
a2725419f988
Updated so that bun builds will with already existing js files.
MrJuneJune <me@mrjunejune.com>
parents:
186
diff
changeset
|
112 dirs_to_copy = {} |
|
a2725419f988
Updated so that bun builds will with already existing js files.
MrJuneJune <me@mrjunejune.com>
parents:
186
diff
changeset
|
113 for f in ctx.files.deps: |
|
a2725419f988
Updated so that bun builds will with already existing js files.
MrJuneJune <me@mrjunejune.com>
parents:
186
diff
changeset
|
114 # Find the root directory path by locating where short_path starts in full path |
|
a2725419f988
Updated so that bun builds will with already existing js files.
MrJuneJune <me@mrjunejune.com>
parents:
186
diff
changeset
|
115 short_path_suffix = "/".join(f.short_path.split("/")[1:]) |
|
a2725419f988
Updated so that bun builds will with already existing js files.
MrJuneJune <me@mrjunejune.com>
parents:
186
diff
changeset
|
116 pos = f.path.find(short_path_suffix) |
|
a2725419f988
Updated so that bun builds will with already existing js files.
MrJuneJune <me@mrjunejune.com>
parents:
186
diff
changeset
|
117 if pos > 0: |
|
a2725419f988
Updated so that bun builds will with already existing js files.
MrJuneJune <me@mrjunejune.com>
parents:
186
diff
changeset
|
118 root_dir = f.path[:pos].rstrip("/") |
|
a2725419f988
Updated so that bun builds will with already existing js files.
MrJuneJune <me@mrjunejune.com>
parents:
186
diff
changeset
|
119 # Skip src_package - it's a symlink that needs special handling |
|
a2725419f988
Updated so that bun builds will with already existing js files.
MrJuneJune <me@mrjunejune.com>
parents:
186
diff
changeset
|
120 if not root_dir.endswith(src_package): |
|
a2725419f988
Updated so that bun builds will with already existing js files.
MrJuneJune <me@mrjunejune.com>
parents:
186
diff
changeset
|
121 dirs_to_copy[root_dir] = True |
|
a2725419f988
Updated so that bun builds will with already existing js files.
MrJuneJune <me@mrjunejune.com>
parents:
186
diff
changeset
|
122 |
|
a2725419f988
Updated so that bun builds will with already existing js files.
MrJuneJune <me@mrjunejune.com>
parents:
186
diff
changeset
|
123 # Build copy commands for each unique directory |
|
a2725419f988
Updated so that bun builds will with already existing js files.
MrJuneJune <me@mrjunejune.com>
parents:
186
diff
changeset
|
124 copy_commands = ["cp -rL {dir} .".format(dir = d) for d in dirs_to_copy.keys()] |
|
a2725419f988
Updated so that bun builds will with already existing js files.
MrJuneJune <me@mrjunejune.com>
parents:
186
diff
changeset
|
125 |
|
a2725419f988
Updated so that bun builds will with already existing js files.
MrJuneJune <me@mrjunejune.com>
parents:
186
diff
changeset
|
126 ctx.actions.run_shell( |
|
a2725419f988
Updated so that bun builds will with already existing js files.
MrJuneJune <me@mrjunejune.com>
parents:
186
diff
changeset
|
127 inputs = inputs, |
|
a2725419f988
Updated so that bun builds will with already existing js files.
MrJuneJune <me@mrjunejune.com>
parents:
186
diff
changeset
|
128 outputs = [out], |
|
a2725419f988
Updated so that bun builds will with already existing js files.
MrJuneJune <me@mrjunejune.com>
parents:
186
diff
changeset
|
129 tools = [ctx.executable._bun] + [ctx.file.src] + ctx.files.deps + ctx.files.node_modules, |
|
a2725419f988
Updated so that bun builds will with already existing js files.
MrJuneJune <me@mrjunejune.com>
parents:
186
diff
changeset
|
130 command = """ |
|
a2725419f988
Updated so that bun builds will with already existing js files.
MrJuneJune <me@mrjunejune.com>
parents:
186
diff
changeset
|
131 cp -rL {src_package} {src_package}_tmp && rm -rf {src_package} && mv {src_package}_tmp {src_package} |
|
a2725419f988
Updated so that bun builds will with already existing js files.
MrJuneJune <me@mrjunejune.com>
parents:
186
diff
changeset
|
132 {copy_commands} |
|
a2725419f988
Updated so that bun builds will with already existing js files.
MrJuneJune <me@mrjunejune.com>
parents:
186
diff
changeset
|
133 export NODE_PATH=./third_party/bun/node_modules |
|
a2725419f988
Updated so that bun builds will with already existing js files.
MrJuneJune <me@mrjunejune.com>
parents:
186
diff
changeset
|
134 cp ./third_party/bun/tsconfig.json . |
| 193 | 135 {bun} build {entry} --outfile {output} --target browser |
|
190
a2725419f988
Updated so that bun builds will with already existing js files.
MrJuneJune <me@mrjunejune.com>
parents:
186
diff
changeset
|
136 """.format( |
|
a2725419f988
Updated so that bun builds will with already existing js files.
MrJuneJune <me@mrjunejune.com>
parents:
186
diff
changeset
|
137 copy_commands = "\n".join(copy_commands), |
|
a2725419f988
Updated so that bun builds will with already existing js files.
MrJuneJune <me@mrjunejune.com>
parents:
186
diff
changeset
|
138 src_package = src_package, |
|
a2725419f988
Updated so that bun builds will with already existing js files.
MrJuneJune <me@mrjunejune.com>
parents:
186
diff
changeset
|
139 bun = ctx.executable._bun.path, |
|
a2725419f988
Updated so that bun builds will with already existing js files.
MrJuneJune <me@mrjunejune.com>
parents:
186
diff
changeset
|
140 entry = ctx.file.src.path, |
|
a2725419f988
Updated so that bun builds will with already existing js files.
MrJuneJune <me@mrjunejune.com>
parents:
186
diff
changeset
|
141 output = out.path, |
|
a2725419f988
Updated so that bun builds will with already existing js files.
MrJuneJune <me@mrjunejune.com>
parents:
186
diff
changeset
|
142 ), |
|
a2725419f988
Updated so that bun builds will with already existing js files.
MrJuneJune <me@mrjunejune.com>
parents:
186
diff
changeset
|
143 progress_message = "Bundling %s with Bun" % ctx.file.src.short_path, |
|
a2725419f988
Updated so that bun builds will with already existing js files.
MrJuneJune <me@mrjunejune.com>
parents:
186
diff
changeset
|
144 ) |
|
a2725419f988
Updated so that bun builds will with already existing js files.
MrJuneJune <me@mrjunejune.com>
parents:
186
diff
changeset
|
145 |
|
a2725419f988
Updated so that bun builds will with already existing js files.
MrJuneJune <me@mrjunejune.com>
parents:
186
diff
changeset
|
146 return [DefaultInfo(files = depset([out]))] |
|
a2725419f988
Updated so that bun builds will with already existing js files.
MrJuneJune <me@mrjunejune.com>
parents:
186
diff
changeset
|
147 |
|
a2725419f988
Updated so that bun builds will with already existing js files.
MrJuneJune <me@mrjunejune.com>
parents:
186
diff
changeset
|
148 bun_bundle = rule( |
|
a2725419f988
Updated so that bun builds will with already existing js files.
MrJuneJune <me@mrjunejune.com>
parents:
186
diff
changeset
|
149 implementation = _bun_bundle_impl, |
|
a2725419f988
Updated so that bun builds will with already existing js files.
MrJuneJune <me@mrjunejune.com>
parents:
186
diff
changeset
|
150 attrs = { |
|
a2725419f988
Updated so that bun builds will with already existing js files.
MrJuneJune <me@mrjunejune.com>
parents:
186
diff
changeset
|
151 "src": attr.label( |
|
a2725419f988
Updated so that bun builds will with already existing js files.
MrJuneJune <me@mrjunejune.com>
parents:
186
diff
changeset
|
152 allow_single_file = [".ts", ".tsx", ".js", ".jsx"], |
|
a2725419f988
Updated so that bun builds will with already existing js files.
MrJuneJune <me@mrjunejune.com>
parents:
186
diff
changeset
|
153 doc = "Entry point file to bundle", |
|
a2725419f988
Updated so that bun builds will with already existing js files.
MrJuneJune <me@mrjunejune.com>
parents:
186
diff
changeset
|
154 ), |
|
a2725419f988
Updated so that bun builds will with already existing js files.
MrJuneJune <me@mrjunejune.com>
parents:
186
diff
changeset
|
155 "deps": attr.label_list( |
|
a2725419f988
Updated so that bun builds will with already existing js files.
MrJuneJune <me@mrjunejune.com>
parents:
186
diff
changeset
|
156 allow_files = True, |
|
a2725419f988
Updated so that bun builds will with already existing js files.
MrJuneJune <me@mrjunejune.com>
parents:
186
diff
changeset
|
157 doc = "Source files and other dependencies to include", |
|
a2725419f988
Updated so that bun builds will with already existing js files.
MrJuneJune <me@mrjunejune.com>
parents:
186
diff
changeset
|
158 ), |
|
a2725419f988
Updated so that bun builds will with already existing js files.
MrJuneJune <me@mrjunejune.com>
parents:
186
diff
changeset
|
159 "node_modules": attr.label_list( |
|
a2725419f988
Updated so that bun builds will with already existing js files.
MrJuneJune <me@mrjunejune.com>
parents:
186
diff
changeset
|
160 allow_files = True, |
|
a2725419f988
Updated so that bun builds will with already existing js files.
MrJuneJune <me@mrjunejune.com>
parents:
186
diff
changeset
|
161 default = [Label("//third_party/bun:bun_files")], |
|
a2725419f988
Updated so that bun builds will with already existing js files.
MrJuneJune <me@mrjunejune.com>
parents:
186
diff
changeset
|
162 doc = "Node modules for bundling (defaults to //third_party/bun:bun_files)", |
|
a2725419f988
Updated so that bun builds will with already existing js files.
MrJuneJune <me@mrjunejune.com>
parents:
186
diff
changeset
|
163 ), |
|
a2725419f988
Updated so that bun builds will with already existing js files.
MrJuneJune <me@mrjunejune.com>
parents:
186
diff
changeset
|
164 "_bun": attr.label( |
|
a2725419f988
Updated so that bun builds will with already existing js files.
MrJuneJune <me@mrjunejune.com>
parents:
186
diff
changeset
|
165 default = Label("//third_party/bun:bun"), |
|
a2725419f988
Updated so that bun builds will with already existing js files.
MrJuneJune <me@mrjunejune.com>
parents:
186
diff
changeset
|
166 executable = True, |
|
a2725419f988
Updated so that bun builds will with already existing js files.
MrJuneJune <me@mrjunejune.com>
parents:
186
diff
changeset
|
167 cfg = "exec", |
|
a2725419f988
Updated so that bun builds will with already existing js files.
MrJuneJune <me@mrjunejune.com>
parents:
186
diff
changeset
|
168 ), |
|
a2725419f988
Updated so that bun builds will with already existing js files.
MrJuneJune <me@mrjunejune.com>
parents:
186
diff
changeset
|
169 }, |
|
a2725419f988
Updated so that bun builds will with already existing js files.
MrJuneJune <me@mrjunejune.com>
parents:
186
diff
changeset
|
170 doc = "Bundle TypeScript/JavaScript using Bun with bazel root imports", |
|
a2725419f988
Updated so that bun builds will with already existing js files.
MrJuneJune <me@mrjunejune.com>
parents:
186
diff
changeset
|
171 ) |
|
a2725419f988
Updated so that bun builds will with already existing js files.
MrJuneJune <me@mrjunejune.com>
parents:
186
diff
changeset
|
172 |
|
a2725419f988
Updated so that bun builds will with already existing js files.
MrJuneJune <me@mrjunejune.com>
parents:
186
diff
changeset
|
173 |
|
a2725419f988
Updated so that bun builds will with already existing js files.
MrJuneJune <me@mrjunejune.com>
parents:
186
diff
changeset
|
174 |
|
12
de54585a40f1
Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents:
8
diff
changeset
|
175 def _bun_build_impl(ctx): |
|
15
2b9e75756825
[GuiZe] Updated to handle bundling and created a shee
June Park <parkjune1995@gmail.com>
parents:
12
diff
changeset
|
176 """ |
|
2b9e75756825
[GuiZe] Updated to handle bundling and created a shee
June Park <parkjune1995@gmail.com>
parents:
12
diff
changeset
|
177 Run bun build on the folder |
|
2b9e75756825
[GuiZe] Updated to handle bundling and created a shee
June Park <parkjune1995@gmail.com>
parents:
12
diff
changeset
|
178 |
|
2b9e75756825
[GuiZe] Updated to handle bundling and created a shee
June Park <parkjune1995@gmail.com>
parents:
12
diff
changeset
|
179 This sucks because you need to either copy node module into the root folder where main.ts file |
|
2b9e75756825
[GuiZe] Updated to handle bundling and created a shee
June Park <parkjune1995@gmail.com>
parents:
12
diff
changeset
|
180 exists or copy everything outwards. I chose to do it in this way. |
|
2b9e75756825
[GuiZe] Updated to handle bundling and created a shee
June Park <parkjune1995@gmail.com>
parents:
12
diff
changeset
|
181 |
|
25
342726584be2
[Bun] Fixed how bun would be ran within bazel.
June Park <parkjune1995@gmail.com>
parents:
24
diff
changeset
|
182 TODO: If possible, maybe create a node_module inside of the main target path and create a symlink |
|
342726584be2
[Bun] Fixed how bun would be ran within bazel.
June Park <parkjune1995@gmail.com>
parents:
24
diff
changeset
|
183 TODO: Add a specific path for node_modules |
|
15
2b9e75756825
[GuiZe] Updated to handle bundling and created a shee
June Park <parkjune1995@gmail.com>
parents:
12
diff
changeset
|
184 """ |
|
12
de54585a40f1
Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents:
8
diff
changeset
|
185 out = ctx.actions.declare_file(ctx.label.name + ".js") |
|
de54585a40f1
Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents:
8
diff
changeset
|
186 inputs = [ctx.file.src] + ctx.files.data |
|
de54585a40f1
Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents:
8
diff
changeset
|
187 |
|
de54585a40f1
Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents:
8
diff
changeset
|
188 ctx.actions.run_shell( |
|
de54585a40f1
Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents:
8
diff
changeset
|
189 inputs = inputs, |
|
de54585a40f1
Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents:
8
diff
changeset
|
190 outputs = [out], |
|
de54585a40f1
Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents:
8
diff
changeset
|
191 tools = [ctx.executable._bun] + inputs, |
|
de54585a40f1
Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents:
8
diff
changeset
|
192 command = """ |
|
de54585a40f1
Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents:
8
diff
changeset
|
193 cp -r third_party/bun/** . \ |
|
25
342726584be2
[Bun] Fixed how bun would be ran within bazel.
June Park <parkjune1995@gmail.com>
parents:
24
diff
changeset
|
194 && cp -r {src_folder}/** . \ |
|
176
fed99fc04e12
[HgWeb] Problem with the emscript lol
MrJuneJune <me@mrjunejune.com>
parents:
175
diff
changeset
|
195 && cp -r ./bazel-out/k8-fastbuild/bin/hg-web/src/** src \ |
|
fed99fc04e12
[HgWeb] Problem with the emscript lol
MrJuneJune <me@mrjunejune.com>
parents:
175
diff
changeset
|
196 && ls src \ |
|
190
a2725419f988
Updated so that bun builds will with already existing js files.
MrJuneJune <me@mrjunejune.com>
parents:
186
diff
changeset
|
197 && pwd \ |
|
175
71ad34a8bc9a
[HgWeb] Can stream hg response now. Added react page for hg web since we use json anyway.
MrJuneJune <me@mrjunejune.com>
parents:
168
diff
changeset
|
198 && export NODE_PATH=./node_modules && {bun_path} build {input_path} --outfile {output_path} --target browser |
|
12
de54585a40f1
Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents:
8
diff
changeset
|
199 """.format( |
|
25
342726584be2
[Bun] Fixed how bun would be ran within bazel.
June Park <parkjune1995@gmail.com>
parents:
24
diff
changeset
|
200 bun_path = ctx.executable._bun.path, |
|
342726584be2
[Bun] Fixed how bun would be ran within bazel.
June Park <parkjune1995@gmail.com>
parents:
24
diff
changeset
|
201 src_folder = ctx.attr.src_folder, |
|
175
71ad34a8bc9a
[HgWeb] Can stream hg response now. Added react page for hg web since we use json anyway.
MrJuneJune <me@mrjunejune.com>
parents:
168
diff
changeset
|
202 # Fix this lol |
|
71ad34a8bc9a
[HgWeb] Can stream hg response now. Added react page for hg web since we use json anyway.
MrJuneJune <me@mrjunejune.com>
parents:
168
diff
changeset
|
203 input_path = "/".join(ctx.file.src.path.split("/")[-2:]), |
|
25
342726584be2
[Bun] Fixed how bun would be ran within bazel.
June Park <parkjune1995@gmail.com>
parents:
24
diff
changeset
|
204 output_path = out.path, |
|
12
de54585a40f1
Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents:
8
diff
changeset
|
205 ), |
|
de54585a40f1
Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents:
8
diff
changeset
|
206 progress_message = "Bundling {} with Bun!\n\n".format(ctx.file.src.path), |
|
de54585a40f1
Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents:
8
diff
changeset
|
207 ) |
|
de54585a40f1
Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents:
8
diff
changeset
|
208 |
|
de54585a40f1
Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents:
8
diff
changeset
|
209 return [DefaultInfo(files=depset([out]))] |
|
de54585a40f1
Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents:
8
diff
changeset
|
210 |
|
de54585a40f1
Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents:
8
diff
changeset
|
211 bun_build = rule( |
|
de54585a40f1
Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents:
8
diff
changeset
|
212 implementation = _bun_build_impl, |
|
de54585a40f1
Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents:
8
diff
changeset
|
213 attrs = { |
|
de54585a40f1
Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents:
8
diff
changeset
|
214 "src": attr.label(allow_single_file = [".ts", ".tsx", ".js", ".jsx"]), |
|
de54585a40f1
Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents:
8
diff
changeset
|
215 "_bun": attr.label( |
|
de54585a40f1
Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents:
8
diff
changeset
|
216 default = Label("//third_party/bun:bun"), |
|
de54585a40f1
Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents:
8
diff
changeset
|
217 executable = True, |
|
de54585a40f1
Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents:
8
diff
changeset
|
218 cfg = "exec", |
|
de54585a40f1
Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents:
8
diff
changeset
|
219 ), |
|
de54585a40f1
Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents:
8
diff
changeset
|
220 "data": attr.label_list(allow_files=True), |
|
25
342726584be2
[Bun] Fixed how bun would be ran within bazel.
June Park <parkjune1995@gmail.com>
parents:
24
diff
changeset
|
221 "src_folder": attr.string(), |
|
12
de54585a40f1
Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents:
8
diff
changeset
|
222 }, |
|
de54585a40f1
Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents:
8
diff
changeset
|
223 ) |
|
de54585a40f1
Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents:
8
diff
changeset
|
224 |
|
156
cd35e600ae34
[MarkDown Converter] Fixed few things and made a test
June Park <parkjune1995@gmail.com>
parents:
154
diff
changeset
|
225 def _bun_run_impl(ctx): |
|
cd35e600ae34
[MarkDown Converter] Fixed few things and made a test
June Park <parkjune1995@gmail.com>
parents:
154
diff
changeset
|
226 actual_exe = ctx.actions.declare_file(ctx.label.name) |
|
cd35e600ae34
[MarkDown Converter] Fixed few things and made a test
June Park <parkjune1995@gmail.com>
parents:
154
diff
changeset
|
227 |
|
cd35e600ae34
[MarkDown Converter] Fixed few things and made a test
June Park <parkjune1995@gmail.com>
parents:
154
diff
changeset
|
228 # 1. Get the workspace name (crucial for runfiles paths) |
|
cd35e600ae34
[MarkDown Converter] Fixed few things and made a test
June Park <parkjune1995@gmail.com>
parents:
154
diff
changeset
|
229 workspace_name = ctx.workspace_name |
|
cd35e600ae34
[MarkDown Converter] Fixed few things and made a test
June Park <parkjune1995@gmail.com>
parents:
154
diff
changeset
|
230 |
|
cd35e600ae34
[MarkDown Converter] Fixed few things and made a test
June Park <parkjune1995@gmail.com>
parents:
154
diff
changeset
|
231 # 2. Define the paths relative to the runfiles root |
|
cd35e600ae34
[MarkDown Converter] Fixed few things and made a test
June Park <parkjune1995@gmail.com>
parents:
154
diff
changeset
|
232 bun_path = ctx.executable._bun.short_path |
|
cd35e600ae34
[MarkDown Converter] Fixed few things and made a test
June Park <parkjune1995@gmail.com>
parents:
154
diff
changeset
|
233 src_path = ctx.file.src.short_path |
|
cd35e600ae34
[MarkDown Converter] Fixed few things and made a test
June Park <parkjune1995@gmail.com>
parents:
154
diff
changeset
|
234 |
|
cd35e600ae34
[MarkDown Converter] Fixed few things and made a test
June Park <parkjune1995@gmail.com>
parents:
154
diff
changeset
|
235 # 3. Create the launcher script |
|
cd35e600ae34
[MarkDown Converter] Fixed few things and made a test
June Park <parkjune1995@gmail.com>
parents:
154
diff
changeset
|
236 # We use a template to handle the environment and pathing |
|
cd35e600ae34
[MarkDown Converter] Fixed few things and made a test
June Park <parkjune1995@gmail.com>
parents:
154
diff
changeset
|
237 script_content = """#!/bin/bash |
|
cd35e600ae34
[MarkDown Converter] Fixed few things and made a test
June Park <parkjune1995@gmail.com>
parents:
154
diff
changeset
|
238 # Find the runfiles directory |
|
cd35e600ae34
[MarkDown Converter] Fixed few things and made a test
June Park <parkjune1995@gmail.com>
parents:
154
diff
changeset
|
239 if [[ -z "$RUNFILES_DIR" ]]; then |
|
cd35e600ae34
[MarkDown Converter] Fixed few things and made a test
June Park <parkjune1995@gmail.com>
parents:
154
diff
changeset
|
240 if [[ -d "$0.runfiles" ]]; then |
|
cd35e600ae34
[MarkDown Converter] Fixed few things and made a test
June Park <parkjune1995@gmail.com>
parents:
154
diff
changeset
|
241 RUNFILES_DIR="$0.runfiles" |
|
cd35e600ae34
[MarkDown Converter] Fixed few things and made a test
June Park <parkjune1995@gmail.com>
parents:
154
diff
changeset
|
242 fi |
|
cd35e600ae34
[MarkDown Converter] Fixed few things and made a test
June Park <parkjune1995@gmail.com>
parents:
154
diff
changeset
|
243 fi |
|
cd35e600ae34
[MarkDown Converter] Fixed few things and made a test
June Park <parkjune1995@gmail.com>
parents:
154
diff
changeset
|
244 |
|
cd35e600ae34
[MarkDown Converter] Fixed few things and made a test
June Park <parkjune1995@gmail.com>
parents:
154
diff
changeset
|
245 # Navigate to the workspace root inside runfiles |
|
cd35e600ae34
[MarkDown Converter] Fixed few things and made a test
June Park <parkjune1995@gmail.com>
parents:
154
diff
changeset
|
246 cd "$RUNFILES_DIR/{workspace}" |
|
cd35e600ae34
[MarkDown Converter] Fixed few things and made a test
June Park <parkjune1995@gmail.com>
parents:
154
diff
changeset
|
247 pwd |
|
cd35e600ae34
[MarkDown Converter] Fixed few things and made a test
June Park <parkjune1995@gmail.com>
parents:
154
diff
changeset
|
248 # Execute bun with the src file and any extra arguments |
|
cd35e600ae34
[MarkDown Converter] Fixed few things and made a test
June Park <parkjune1995@gmail.com>
parents:
154
diff
changeset
|
249 exec "./{bun_bin}" run "./{src_file}" "$@" |
|
cd35e600ae34
[MarkDown Converter] Fixed few things and made a test
June Park <parkjune1995@gmail.com>
parents:
154
diff
changeset
|
250 """.format( |
|
cd35e600ae34
[MarkDown Converter] Fixed few things and made a test
June Park <parkjune1995@gmail.com>
parents:
154
diff
changeset
|
251 workspace = workspace_name, |
|
cd35e600ae34
[MarkDown Converter] Fixed few things and made a test
June Park <parkjune1995@gmail.com>
parents:
154
diff
changeset
|
252 bun_bin = bun_path, |
|
cd35e600ae34
[MarkDown Converter] Fixed few things and made a test
June Park <parkjune1995@gmail.com>
parents:
154
diff
changeset
|
253 src_file = src_path |
|
cd35e600ae34
[MarkDown Converter] Fixed few things and made a test
June Park <parkjune1995@gmail.com>
parents:
154
diff
changeset
|
254 ) |
|
cd35e600ae34
[MarkDown Converter] Fixed few things and made a test
June Park <parkjune1995@gmail.com>
parents:
154
diff
changeset
|
255 |
|
cd35e600ae34
[MarkDown Converter] Fixed few things and made a test
June Park <parkjune1995@gmail.com>
parents:
154
diff
changeset
|
256 ctx.actions.write( |
|
cd35e600ae34
[MarkDown Converter] Fixed few things and made a test
June Park <parkjune1995@gmail.com>
parents:
154
diff
changeset
|
257 output = actual_exe, |
|
cd35e600ae34
[MarkDown Converter] Fixed few things and made a test
June Park <parkjune1995@gmail.com>
parents:
154
diff
changeset
|
258 content = script_content, |
|
cd35e600ae34
[MarkDown Converter] Fixed few things and made a test
June Park <parkjune1995@gmail.com>
parents:
154
diff
changeset
|
259 is_executable = True, |
|
cd35e600ae34
[MarkDown Converter] Fixed few things and made a test
June Park <parkjune1995@gmail.com>
parents:
154
diff
changeset
|
260 ) |
|
cd35e600ae34
[MarkDown Converter] Fixed few things and made a test
June Park <parkjune1995@gmail.com>
parents:
154
diff
changeset
|
261 |
|
cd35e600ae34
[MarkDown Converter] Fixed few things and made a test
June Park <parkjune1995@gmail.com>
parents:
154
diff
changeset
|
262 return [ |
|
cd35e600ae34
[MarkDown Converter] Fixed few things and made a test
June Park <parkjune1995@gmail.com>
parents:
154
diff
changeset
|
263 DefaultInfo( |
|
cd35e600ae34
[MarkDown Converter] Fixed few things and made a test
June Park <parkjune1995@gmail.com>
parents:
154
diff
changeset
|
264 executable = actual_exe, |
|
cd35e600ae34
[MarkDown Converter] Fixed few things and made a test
June Park <parkjune1995@gmail.com>
parents:
154
diff
changeset
|
265 runfiles = ctx.runfiles( |
|
cd35e600ae34
[MarkDown Converter] Fixed few things and made a test
June Park <parkjune1995@gmail.com>
parents:
154
diff
changeset
|
266 files = [ctx.file.src] + ctx.files.data + ctx.files._bun_files |
|
cd35e600ae34
[MarkDown Converter] Fixed few things and made a test
June Park <parkjune1995@gmail.com>
parents:
154
diff
changeset
|
267 ).merge(ctx.attr._bun[DefaultInfo].default_runfiles), |
|
cd35e600ae34
[MarkDown Converter] Fixed few things and made a test
June Park <parkjune1995@gmail.com>
parents:
154
diff
changeset
|
268 ), |
|
cd35e600ae34
[MarkDown Converter] Fixed few things and made a test
June Park <parkjune1995@gmail.com>
parents:
154
diff
changeset
|
269 ] |
|
cd35e600ae34
[MarkDown Converter] Fixed few things and made a test
June Park <parkjune1995@gmail.com>
parents:
154
diff
changeset
|
270 |
|
cd35e600ae34
[MarkDown Converter] Fixed few things and made a test
June Park <parkjune1995@gmail.com>
parents:
154
diff
changeset
|
271 # TODO: Fix the rules so that it can do relative import. |
|
cd35e600ae34
[MarkDown Converter] Fixed few things and made a test
June Park <parkjune1995@gmail.com>
parents:
154
diff
changeset
|
272 bun_run = rule( |
|
cd35e600ae34
[MarkDown Converter] Fixed few things and made a test
June Park <parkjune1995@gmail.com>
parents:
154
diff
changeset
|
273 implementation = _bun_run_impl, |
|
cd35e600ae34
[MarkDown Converter] Fixed few things and made a test
June Park <parkjune1995@gmail.com>
parents:
154
diff
changeset
|
274 executable = True, |
|
cd35e600ae34
[MarkDown Converter] Fixed few things and made a test
June Park <parkjune1995@gmail.com>
parents:
154
diff
changeset
|
275 attrs = { |
|
cd35e600ae34
[MarkDown Converter] Fixed few things and made a test
June Park <parkjune1995@gmail.com>
parents:
154
diff
changeset
|
276 "src": attr.label(allow_single_file = True, mandatory = True), |
|
cd35e600ae34
[MarkDown Converter] Fixed few things and made a test
June Park <parkjune1995@gmail.com>
parents:
154
diff
changeset
|
277 "data": attr.label_list(allow_files = True), |
|
cd35e600ae34
[MarkDown Converter] Fixed few things and made a test
June Park <parkjune1995@gmail.com>
parents:
154
diff
changeset
|
278 "_bun": attr.label( |
|
cd35e600ae34
[MarkDown Converter] Fixed few things and made a test
June Park <parkjune1995@gmail.com>
parents:
154
diff
changeset
|
279 default = Label("//third_party/bun:bun"), |
|
cd35e600ae34
[MarkDown Converter] Fixed few things and made a test
June Park <parkjune1995@gmail.com>
parents:
154
diff
changeset
|
280 executable = True, |
|
cd35e600ae34
[MarkDown Converter] Fixed few things and made a test
June Park <parkjune1995@gmail.com>
parents:
154
diff
changeset
|
281 cfg = "exec" |
|
cd35e600ae34
[MarkDown Converter] Fixed few things and made a test
June Park <parkjune1995@gmail.com>
parents:
154
diff
changeset
|
282 ), |
|
cd35e600ae34
[MarkDown Converter] Fixed few things and made a test
June Park <parkjune1995@gmail.com>
parents:
154
diff
changeset
|
283 "_bun_files": attr.label(default = Label("//third_party/bun:bun_files")), |
|
cd35e600ae34
[MarkDown Converter] Fixed few things and made a test
June Park <parkjune1995@gmail.com>
parents:
154
diff
changeset
|
284 }, |
|
cd35e600ae34
[MarkDown Converter] Fixed few things and made a test
June Park <parkjune1995@gmail.com>
parents:
154
diff
changeset
|
285 ) |
|
cd35e600ae34
[MarkDown Converter] Fixed few things and made a test
June Park <parkjune1995@gmail.com>
parents:
154
diff
changeset
|
286 |
|
cd35e600ae34
[MarkDown Converter] Fixed few things and made a test
June Park <parkjune1995@gmail.com>
parents:
154
diff
changeset
|
287 |
|
12
de54585a40f1
Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents:
8
diff
changeset
|
288 def _move_files_into_dir_impl(ctx): |
|
de54585a40f1
Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents:
8
diff
changeset
|
289 srcs = ctx.files.srcs |
|
64
a30944e5719e
Added vibe coded markdown to html script since it is useful for me. Updated Dowa so that it can be compiled without dirnet for windows.
June Park <parkjune1995@gmail.com>
parents:
58
diff
changeset
|
290 outs = [] |
|
12
de54585a40f1
Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents:
8
diff
changeset
|
291 for src in srcs: |
|
de54585a40f1
Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents:
8
diff
changeset
|
292 out = ctx.actions.declare_file(ctx.attr.dest + "/" + src.basename) |
|
64
a30944e5719e
Added vibe coded markdown to html script since it is useful for me. Updated Dowa so that it can be compiled without dirnet for windows.
June Park <parkjune1995@gmail.com>
parents:
58
diff
changeset
|
293 ctx.actions.run_shell( |
|
a30944e5719e
Added vibe coded markdown to html script since it is useful for me. Updated Dowa so that it can be compiled without dirnet for windows.
June Park <parkjune1995@gmail.com>
parents:
58
diff
changeset
|
294 inputs = [src], |
|
a30944e5719e
Added vibe coded markdown to html script since it is useful for me. Updated Dowa so that it can be compiled without dirnet for windows.
June Park <parkjune1995@gmail.com>
parents:
58
diff
changeset
|
295 outputs = [out], |
|
176
fed99fc04e12
[HgWeb] Problem with the emscript lol
MrJuneJune <me@mrjunejune.com>
parents:
175
diff
changeset
|
296 command = "cp -r \"$1\" \"$2\"", |
|
64
a30944e5719e
Added vibe coded markdown to html script since it is useful for me. Updated Dowa so that it can be compiled without dirnet for windows.
June Park <parkjune1995@gmail.com>
parents:
58
diff
changeset
|
297 arguments = [src.path, out.path], |
|
12
de54585a40f1
Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents:
8
diff
changeset
|
298 ) |
|
64
a30944e5719e
Added vibe coded markdown to html script since it is useful for me. Updated Dowa so that it can be compiled without dirnet for windows.
June Park <parkjune1995@gmail.com>
parents:
58
diff
changeset
|
299 outs.append(out) |
|
190
a2725419f988
Updated so that bun builds will with already existing js files.
MrJuneJune <me@mrjunejune.com>
parents:
186
diff
changeset
|
300 return [DefaultInfo(files = depset(outs), runfiles = ctx.runfiles(files = outs))] |
|
12
de54585a40f1
Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents:
8
diff
changeset
|
301 |
|
de54585a40f1
Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents:
8
diff
changeset
|
302 move_files_into_dir = rule( |
|
de54585a40f1
Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents:
8
diff
changeset
|
303 implementation = _move_files_into_dir_impl, |
|
de54585a40f1
Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents:
8
diff
changeset
|
304 attrs = { |
|
de54585a40f1
Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents:
8
diff
changeset
|
305 "srcs": attr.label_list(allow_files=True), |
|
de54585a40f1
Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents:
8
diff
changeset
|
306 "dest": attr.string(), |
|
de54585a40f1
Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents:
8
diff
changeset
|
307 }, |
|
de54585a40f1
Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents:
8
diff
changeset
|
308 ) |
|
de54585a40f1
Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents:
8
diff
changeset
|
309 |
|
241
9c2eec61a152
[assets] Generate site images as WebP with Bazel
MrJuneJune <me@mrjunejune.com>
parents:
193
diff
changeset
|
310 def webp_image(name, src, out, quality = 90, lossless = False): |
|
9c2eec61a152
[assets] Generate site images as WebP with Bazel
MrJuneJune <me@mrjunejune.com>
parents:
193
diff
changeset
|
311 """Convert one image to WebP as a Bazel build action.""" |
|
9c2eec61a152
[assets] Generate site images as WebP with Bazel
MrJuneJune <me@mrjunejune.com>
parents:
193
diff
changeset
|
312 native.genrule( |
|
9c2eec61a152
[assets] Generate site images as WebP with Bazel
MrJuneJune <me@mrjunejune.com>
parents:
193
diff
changeset
|
313 name = name, |
|
9c2eec61a152
[assets] Generate site images as WebP with Bazel
MrJuneJune <me@mrjunejune.com>
parents:
193
diff
changeset
|
314 srcs = [src], |
|
9c2eec61a152
[assets] Generate site images as WebP with Bazel
MrJuneJune <me@mrjunejune.com>
parents:
193
diff
changeset
|
315 outs = [out], |
|
9c2eec61a152
[assets] Generate site images as WebP with Bazel
MrJuneJune <me@mrjunejune.com>
parents:
193
diff
changeset
|
316 tools = ["@libwebp_linux_x86_64//:bin/cwebp"], |
|
9c2eec61a152
[assets] Generate site images as WebP with Bazel
MrJuneJune <me@mrjunejune.com>
parents:
193
diff
changeset
|
317 cmd = "$(location @libwebp_linux_x86_64//:bin/cwebp) -quiet -m 6 {} -q {} $(location {}) -o $@".format( |
|
9c2eec61a152
[assets] Generate site images as WebP with Bazel
MrJuneJune <me@mrjunejune.com>
parents:
193
diff
changeset
|
318 "-lossless" if lossless else "", |
|
9c2eec61a152
[assets] Generate site images as WebP with Bazel
MrJuneJune <me@mrjunejune.com>
parents:
193
diff
changeset
|
319 quality, |
|
9c2eec61a152
[assets] Generate site images as WebP with Bazel
MrJuneJune <me@mrjunejune.com>
parents:
193
diff
changeset
|
320 src, |
|
9c2eec61a152
[assets] Generate site images as WebP with Bazel
MrJuneJune <me@mrjunejune.com>
parents:
193
diff
changeset
|
321 ), |
|
9c2eec61a152
[assets] Generate site images as WebP with Bazel
MrJuneJune <me@mrjunejune.com>
parents:
193
diff
changeset
|
322 ) |
|
9c2eec61a152
[assets] Generate site images as WebP with Bazel
MrJuneJune <me@mrjunejune.com>
parents:
193
diff
changeset
|
323 |
|
12
de54585a40f1
Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents:
8
diff
changeset
|
324 def _move_to_directory_impl(ctx): |
|
de54585a40f1
Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents:
8
diff
changeset
|
325 srcs = ctx.files.data |
|
de54585a40f1
Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents:
8
diff
changeset
|
326 res = [] |
|
de54585a40f1
Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents:
8
diff
changeset
|
327 for src in srcs: |
|
de54585a40f1
Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents:
8
diff
changeset
|
328 true = "/".join(src.path.split("/")[2:]) |
|
de54585a40f1
Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents:
8
diff
changeset
|
329 path = ctx.attr.dest + "/" + true if ctx.attr.dest != "" else true |
|
de54585a40f1
Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents:
8
diff
changeset
|
330 out = ctx.actions.declare_file( |
|
de54585a40f1
Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents:
8
diff
changeset
|
331 path |
|
de54585a40f1
Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents:
8
diff
changeset
|
332 ); |
|
de54585a40f1
Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents:
8
diff
changeset
|
333 ctx.actions.symlink( |
|
de54585a40f1
Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents:
8
diff
changeset
|
334 output = out, |
|
de54585a40f1
Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents:
8
diff
changeset
|
335 target_file = src, |
|
de54585a40f1
Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents:
8
diff
changeset
|
336 ) |
|
de54585a40f1
Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents:
8
diff
changeset
|
337 res.append(out) |
|
de54585a40f1
Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents:
8
diff
changeset
|
338 return [DefaultInfo(files = depset(res))] |
|
de54585a40f1
Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents:
8
diff
changeset
|
339 |
|
de54585a40f1
Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents:
8
diff
changeset
|
340 move_to_directory = rule( |
|
de54585a40f1
Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents:
8
diff
changeset
|
341 implementation = _move_to_directory_impl, |
|
de54585a40f1
Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents:
8
diff
changeset
|
342 attrs = { |
|
de54585a40f1
Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents:
8
diff
changeset
|
343 "data": attr.label_list(allow_files=True), |
|
de54585a40f1
Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents:
8
diff
changeset
|
344 "dest": attr.string(), |
|
de54585a40f1
Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents:
8
diff
changeset
|
345 }, |
|
de54585a40f1
Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents:
8
diff
changeset
|
346 ) |
|
58
ccb42d5bf8fd
[PostDog] Somewhat working copy. That would use for testing.
June Park <parkjune1995@gmail.com>
parents:
25
diff
changeset
|
347 |
|
ccb42d5bf8fd
[PostDog] Somewhat working copy. That would use for testing.
June Park <parkjune1995@gmail.com>
parents:
25
diff
changeset
|
348 |
|
ccb42d5bf8fd
[PostDog] Somewhat working copy. That would use for testing.
June Park <parkjune1995@gmail.com>
parents:
25
diff
changeset
|
349 def _macos_app_impl(ctx): |
|
ccb42d5bf8fd
[PostDog] Somewhat working copy. That would use for testing.
June Park <parkjune1995@gmail.com>
parents:
25
diff
changeset
|
350 """Implementation for creating a macOS .app bundle from a binary.""" |
|
ccb42d5bf8fd
[PostDog] Somewhat working copy. That would use for testing.
June Park <parkjune1995@gmail.com>
parents:
25
diff
changeset
|
351 binary = ctx.file.binary |
|
ccb42d5bf8fd
[PostDog] Somewhat working copy. That would use for testing.
June Park <parkjune1995@gmail.com>
parents:
25
diff
changeset
|
352 app_name = ctx.attr.app_name |
|
ccb42d5bf8fd
[PostDog] Somewhat working copy. That would use for testing.
June Park <parkjune1995@gmail.com>
parents:
25
diff
changeset
|
353 bundle_id = ctx.attr.bundle_id |
|
ccb42d5bf8fd
[PostDog] Somewhat working copy. That would use for testing.
June Park <parkjune1995@gmail.com>
parents:
25
diff
changeset
|
354 |
|
ccb42d5bf8fd
[PostDog] Somewhat working copy. That would use for testing.
June Park <parkjune1995@gmail.com>
parents:
25
diff
changeset
|
355 # Declare the .app directory as output |
|
ccb42d5bf8fd
[PostDog] Somewhat working copy. That would use for testing.
June Park <parkjune1995@gmail.com>
parents:
25
diff
changeset
|
356 app_dir = ctx.actions.declare_directory(app_name + ".app") |
|
ccb42d5bf8fd
[PostDog] Somewhat working copy. That would use for testing.
June Park <parkjune1995@gmail.com>
parents:
25
diff
changeset
|
357 |
|
ccb42d5bf8fd
[PostDog] Somewhat working copy. That would use for testing.
June Park <parkjune1995@gmail.com>
parents:
25
diff
changeset
|
358 ctx.actions.run_shell( |
|
ccb42d5bf8fd
[PostDog] Somewhat working copy. That would use for testing.
June Park <parkjune1995@gmail.com>
parents:
25
diff
changeset
|
359 inputs = [binary], |
|
ccb42d5bf8fd
[PostDog] Somewhat working copy. That would use for testing.
June Park <parkjune1995@gmail.com>
parents:
25
diff
changeset
|
360 outputs = [app_dir], |
|
ccb42d5bf8fd
[PostDog] Somewhat working copy. That would use for testing.
June Park <parkjune1995@gmail.com>
parents:
25
diff
changeset
|
361 command = """ |
|
ccb42d5bf8fd
[PostDog] Somewhat working copy. That would use for testing.
June Park <parkjune1995@gmail.com>
parents:
25
diff
changeset
|
362 set -e |
|
ccb42d5bf8fd
[PostDog] Somewhat working copy. That would use for testing.
June Park <parkjune1995@gmail.com>
parents:
25
diff
changeset
|
363 |
|
ccb42d5bf8fd
[PostDog] Somewhat working copy. That would use for testing.
June Park <parkjune1995@gmail.com>
parents:
25
diff
changeset
|
364 APPDIR="{app_dir}" |
|
ccb42d5bf8fd
[PostDog] Somewhat working copy. That would use for testing.
June Park <parkjune1995@gmail.com>
parents:
25
diff
changeset
|
365 |
|
ccb42d5bf8fd
[PostDog] Somewhat working copy. That would use for testing.
June Park <parkjune1995@gmail.com>
parents:
25
diff
changeset
|
366 rm -rf "$APPDIR" |
|
ccb42d5bf8fd
[PostDog] Somewhat working copy. That would use for testing.
June Park <parkjune1995@gmail.com>
parents:
25
diff
changeset
|
367 mkdir -p "$APPDIR/Contents/MacOS" |
|
ccb42d5bf8fd
[PostDog] Somewhat working copy. That would use for testing.
June Park <parkjune1995@gmail.com>
parents:
25
diff
changeset
|
368 mkdir -p "$APPDIR/Contents/Resources" |
|
ccb42d5bf8fd
[PostDog] Somewhat working copy. That would use for testing.
June Park <parkjune1995@gmail.com>
parents:
25
diff
changeset
|
369 |
|
ccb42d5bf8fd
[PostDog] Somewhat working copy. That would use for testing.
June Park <parkjune1995@gmail.com>
parents:
25
diff
changeset
|
370 cp {binary} "$APPDIR/Contents/MacOS/{app_name}" |
|
ccb42d5bf8fd
[PostDog] Somewhat working copy. That would use for testing.
June Park <parkjune1995@gmail.com>
parents:
25
diff
changeset
|
371 chmod +x "$APPDIR/Contents/MacOS/{app_name}" |
|
ccb42d5bf8fd
[PostDog] Somewhat working copy. That would use for testing.
June Park <parkjune1995@gmail.com>
parents:
25
diff
changeset
|
372 |
|
ccb42d5bf8fd
[PostDog] Somewhat working copy. That would use for testing.
June Park <parkjune1995@gmail.com>
parents:
25
diff
changeset
|
373 cat > "$APPDIR/Contents/Info.plist" <<EOF |
|
ccb42d5bf8fd
[PostDog] Somewhat working copy. That would use for testing.
June Park <parkjune1995@gmail.com>
parents:
25
diff
changeset
|
374 <?xml version="1.0" encoding="UTF-8"?> |
|
ccb42d5bf8fd
[PostDog] Somewhat working copy. That would use for testing.
June Park <parkjune1995@gmail.com>
parents:
25
diff
changeset
|
375 <!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" |
|
ccb42d5bf8fd
[PostDog] Somewhat working copy. That would use for testing.
June Park <parkjune1995@gmail.com>
parents:
25
diff
changeset
|
376 "http://www.apple.com/DTDs/PropertyList-1.0.dtd"> |
|
ccb42d5bf8fd
[PostDog] Somewhat working copy. That would use for testing.
June Park <parkjune1995@gmail.com>
parents:
25
diff
changeset
|
377 <plist version="1.0"> |
|
ccb42d5bf8fd
[PostDog] Somewhat working copy. That would use for testing.
June Park <parkjune1995@gmail.com>
parents:
25
diff
changeset
|
378 <dict> |
|
ccb42d5bf8fd
[PostDog] Somewhat working copy. That would use for testing.
June Park <parkjune1995@gmail.com>
parents:
25
diff
changeset
|
379 <key>CFBundleExecutable</key> |
|
ccb42d5bf8fd
[PostDog] Somewhat working copy. That would use for testing.
June Park <parkjune1995@gmail.com>
parents:
25
diff
changeset
|
380 <string>{app_name}</string> |
|
ccb42d5bf8fd
[PostDog] Somewhat working copy. That would use for testing.
June Park <parkjune1995@gmail.com>
parents:
25
diff
changeset
|
381 <key>CFBundleIdentifier</key> |
|
ccb42d5bf8fd
[PostDog] Somewhat working copy. That would use for testing.
June Park <parkjune1995@gmail.com>
parents:
25
diff
changeset
|
382 <string>{bundle_id}</string> |
|
ccb42d5bf8fd
[PostDog] Somewhat working copy. That would use for testing.
June Park <parkjune1995@gmail.com>
parents:
25
diff
changeset
|
383 <key>CFBundleName</key> |
|
ccb42d5bf8fd
[PostDog] Somewhat working copy. That would use for testing.
June Park <parkjune1995@gmail.com>
parents:
25
diff
changeset
|
384 <string>{app_name}</string> |
|
ccb42d5bf8fd
[PostDog] Somewhat working copy. That would use for testing.
June Park <parkjune1995@gmail.com>
parents:
25
diff
changeset
|
385 <key>CFBundleVersion</key> |
|
ccb42d5bf8fd
[PostDog] Somewhat working copy. That would use for testing.
June Park <parkjune1995@gmail.com>
parents:
25
diff
changeset
|
386 <string>1.0</string> |
|
ccb42d5bf8fd
[PostDog] Somewhat working copy. That would use for testing.
June Park <parkjune1995@gmail.com>
parents:
25
diff
changeset
|
387 </dict> |
|
ccb42d5bf8fd
[PostDog] Somewhat working copy. That would use for testing.
June Park <parkjune1995@gmail.com>
parents:
25
diff
changeset
|
388 </plist> |
|
ccb42d5bf8fd
[PostDog] Somewhat working copy. That would use for testing.
June Park <parkjune1995@gmail.com>
parents:
25
diff
changeset
|
389 EOF |
|
ccb42d5bf8fd
[PostDog] Somewhat working copy. That would use for testing.
June Park <parkjune1995@gmail.com>
parents:
25
diff
changeset
|
390 """.format( |
|
ccb42d5bf8fd
[PostDog] Somewhat working copy. That would use for testing.
June Park <parkjune1995@gmail.com>
parents:
25
diff
changeset
|
391 app_dir = app_dir.path, |
|
ccb42d5bf8fd
[PostDog] Somewhat working copy. That would use for testing.
June Park <parkjune1995@gmail.com>
parents:
25
diff
changeset
|
392 binary = binary.path, |
|
ccb42d5bf8fd
[PostDog] Somewhat working copy. That would use for testing.
June Park <parkjune1995@gmail.com>
parents:
25
diff
changeset
|
393 app_name = app_name, |
|
ccb42d5bf8fd
[PostDog] Somewhat working copy. That would use for testing.
June Park <parkjune1995@gmail.com>
parents:
25
diff
changeset
|
394 bundle_id = bundle_id, |
|
ccb42d5bf8fd
[PostDog] Somewhat working copy. That would use for testing.
June Park <parkjune1995@gmail.com>
parents:
25
diff
changeset
|
395 ), |
|
ccb42d5bf8fd
[PostDog] Somewhat working copy. That would use for testing.
June Park <parkjune1995@gmail.com>
parents:
25
diff
changeset
|
396 progress_message = "Creating macOS app bundle for {}".format(app_name), |
|
ccb42d5bf8fd
[PostDog] Somewhat working copy. That would use for testing.
June Park <parkjune1995@gmail.com>
parents:
25
diff
changeset
|
397 ) |
|
ccb42d5bf8fd
[PostDog] Somewhat working copy. That would use for testing.
June Park <parkjune1995@gmail.com>
parents:
25
diff
changeset
|
398 |
|
ccb42d5bf8fd
[PostDog] Somewhat working copy. That would use for testing.
June Park <parkjune1995@gmail.com>
parents:
25
diff
changeset
|
399 return [DefaultInfo(files = depset([app_dir]))] |
|
ccb42d5bf8fd
[PostDog] Somewhat working copy. That would use for testing.
June Park <parkjune1995@gmail.com>
parents:
25
diff
changeset
|
400 |
|
ccb42d5bf8fd
[PostDog] Somewhat working copy. That would use for testing.
June Park <parkjune1995@gmail.com>
parents:
25
diff
changeset
|
401 _macos_app = rule( |
|
ccb42d5bf8fd
[PostDog] Somewhat working copy. That would use for testing.
June Park <parkjune1995@gmail.com>
parents:
25
diff
changeset
|
402 implementation = _macos_app_impl, |
|
ccb42d5bf8fd
[PostDog] Somewhat working copy. That would use for testing.
June Park <parkjune1995@gmail.com>
parents:
25
diff
changeset
|
403 attrs = { |
|
ccb42d5bf8fd
[PostDog] Somewhat working copy. That would use for testing.
June Park <parkjune1995@gmail.com>
parents:
25
diff
changeset
|
404 "binary": attr.label( |
|
ccb42d5bf8fd
[PostDog] Somewhat working copy. That would use for testing.
June Park <parkjune1995@gmail.com>
parents:
25
diff
changeset
|
405 allow_single_file = True, |
|
ccb42d5bf8fd
[PostDog] Somewhat working copy. That would use for testing.
June Park <parkjune1995@gmail.com>
parents:
25
diff
changeset
|
406 mandatory = True, |
|
ccb42d5bf8fd
[PostDog] Somewhat working copy. That would use for testing.
June Park <parkjune1995@gmail.com>
parents:
25
diff
changeset
|
407 doc = "The binary to bundle into a .app", |
|
ccb42d5bf8fd
[PostDog] Somewhat working copy. That would use for testing.
June Park <parkjune1995@gmail.com>
parents:
25
diff
changeset
|
408 ), |
|
ccb42d5bf8fd
[PostDog] Somewhat working copy. That would use for testing.
June Park <parkjune1995@gmail.com>
parents:
25
diff
changeset
|
409 "app_name": attr.string( |
|
ccb42d5bf8fd
[PostDog] Somewhat working copy. That would use for testing.
June Park <parkjune1995@gmail.com>
parents:
25
diff
changeset
|
410 mandatory = True, |
|
ccb42d5bf8fd
[PostDog] Somewhat working copy. That would use for testing.
June Park <parkjune1995@gmail.com>
parents:
25
diff
changeset
|
411 doc = "Name of the application", |
|
ccb42d5bf8fd
[PostDog] Somewhat working copy. That would use for testing.
June Park <parkjune1995@gmail.com>
parents:
25
diff
changeset
|
412 ), |
|
ccb42d5bf8fd
[PostDog] Somewhat working copy. That would use for testing.
June Park <parkjune1995@gmail.com>
parents:
25
diff
changeset
|
413 "bundle_id": attr.string( |
|
ccb42d5bf8fd
[PostDog] Somewhat working copy. That would use for testing.
June Park <parkjune1995@gmail.com>
parents:
25
diff
changeset
|
414 mandatory = True, |
|
ccb42d5bf8fd
[PostDog] Somewhat working copy. That would use for testing.
June Park <parkjune1995@gmail.com>
parents:
25
diff
changeset
|
415 doc = "Bundle identifier (e.g., com.example.app)", |
|
ccb42d5bf8fd
[PostDog] Somewhat working copy. That would use for testing.
June Park <parkjune1995@gmail.com>
parents:
25
diff
changeset
|
416 ), |
|
ccb42d5bf8fd
[PostDog] Somewhat working copy. That would use for testing.
June Park <parkjune1995@gmail.com>
parents:
25
diff
changeset
|
417 }, |
|
ccb42d5bf8fd
[PostDog] Somewhat working copy. That would use for testing.
June Park <parkjune1995@gmail.com>
parents:
25
diff
changeset
|
418 ) |
|
ccb42d5bf8fd
[PostDog] Somewhat working copy. That would use for testing.
June Park <parkjune1995@gmail.com>
parents:
25
diff
changeset
|
419 |
|
ccb42d5bf8fd
[PostDog] Somewhat working copy. That would use for testing.
June Park <parkjune1995@gmail.com>
parents:
25
diff
changeset
|
420 def _macos_signed_app_impl(ctx): |
|
ccb42d5bf8fd
[PostDog] Somewhat working copy. That would use for testing.
June Park <parkjune1995@gmail.com>
parents:
25
diff
changeset
|
421 """Implementation for signing a macOS .app bundle.""" |
|
ccb42d5bf8fd
[PostDog] Somewhat working copy. That would use for testing.
June Park <parkjune1995@gmail.com>
parents:
25
diff
changeset
|
422 app_dir = ctx.file.app |
|
ccb42d5bf8fd
[PostDog] Somewhat working copy. That would use for testing.
June Park <parkjune1995@gmail.com>
parents:
25
diff
changeset
|
423 app_name = ctx.attr.app_name |
|
ccb42d5bf8fd
[PostDog] Somewhat working copy. That would use for testing.
June Park <parkjune1995@gmail.com>
parents:
25
diff
changeset
|
424 |
|
ccb42d5bf8fd
[PostDog] Somewhat working copy. That would use for testing.
June Park <parkjune1995@gmail.com>
parents:
25
diff
changeset
|
425 # Declare the signed .app directory as output |
|
ccb42d5bf8fd
[PostDog] Somewhat working copy. That would use for testing.
June Park <parkjune1995@gmail.com>
parents:
25
diff
changeset
|
426 signed_app_dir = ctx.actions.declare_directory(app_name + "_signed.app") |
|
ccb42d5bf8fd
[PostDog] Somewhat working copy. That would use for testing.
June Park <parkjune1995@gmail.com>
parents:
25
diff
changeset
|
427 |
|
ccb42d5bf8fd
[PostDog] Somewhat working copy. That would use for testing.
June Park <parkjune1995@gmail.com>
parents:
25
diff
changeset
|
428 ctx.actions.run_shell( |
|
ccb42d5bf8fd
[PostDog] Somewhat working copy. That would use for testing.
June Park <parkjune1995@gmail.com>
parents:
25
diff
changeset
|
429 inputs = [app_dir], |
|
ccb42d5bf8fd
[PostDog] Somewhat working copy. That would use for testing.
June Park <parkjune1995@gmail.com>
parents:
25
diff
changeset
|
430 outputs = [signed_app_dir], |
|
ccb42d5bf8fd
[PostDog] Somewhat working copy. That would use for testing.
June Park <parkjune1995@gmail.com>
parents:
25
diff
changeset
|
431 command = """ |
|
ccb42d5bf8fd
[PostDog] Somewhat working copy. That would use for testing.
June Park <parkjune1995@gmail.com>
parents:
25
diff
changeset
|
432 set -e |
|
ccb42d5bf8fd
[PostDog] Somewhat working copy. That would use for testing.
June Park <parkjune1995@gmail.com>
parents:
25
diff
changeset
|
433 |
|
ccb42d5bf8fd
[PostDog] Somewhat working copy. That would use for testing.
June Park <parkjune1995@gmail.com>
parents:
25
diff
changeset
|
434 APPDIR="{app_dir}" |
|
ccb42d5bf8fd
[PostDog] Somewhat working copy. That would use for testing.
June Park <parkjune1995@gmail.com>
parents:
25
diff
changeset
|
435 SIGNEDDIR="{signed_dir}" |
|
ccb42d5bf8fd
[PostDog] Somewhat working copy. That would use for testing.
June Park <parkjune1995@gmail.com>
parents:
25
diff
changeset
|
436 |
|
ccb42d5bf8fd
[PostDog] Somewhat working copy. That would use for testing.
June Park <parkjune1995@gmail.com>
parents:
25
diff
changeset
|
437 rm -rf "$SIGNEDDIR" |
|
ccb42d5bf8fd
[PostDog] Somewhat working copy. That would use for testing.
June Park <parkjune1995@gmail.com>
parents:
25
diff
changeset
|
438 # Use -L to dereference symlinks, as codesign doesn't work with symlinks |
|
ccb42d5bf8fd
[PostDog] Somewhat working copy. That would use for testing.
June Park <parkjune1995@gmail.com>
parents:
25
diff
changeset
|
439 cp -RL "$APPDIR" "$SIGNEDDIR" |
|
ccb42d5bf8fd
[PostDog] Somewhat working copy. That would use for testing.
June Park <parkjune1995@gmail.com>
parents:
25
diff
changeset
|
440 |
|
ccb42d5bf8fd
[PostDog] Somewhat working copy. That would use for testing.
June Park <parkjune1995@gmail.com>
parents:
25
diff
changeset
|
441 codesign --deep --force --sign - "$SIGNEDDIR" |
|
ccb42d5bf8fd
[PostDog] Somewhat working copy. That would use for testing.
June Park <parkjune1995@gmail.com>
parents:
25
diff
changeset
|
442 """.format( |
|
ccb42d5bf8fd
[PostDog] Somewhat working copy. That would use for testing.
June Park <parkjune1995@gmail.com>
parents:
25
diff
changeset
|
443 app_dir = app_dir.path, |
|
ccb42d5bf8fd
[PostDog] Somewhat working copy. That would use for testing.
June Park <parkjune1995@gmail.com>
parents:
25
diff
changeset
|
444 signed_dir = signed_app_dir.path, |
|
ccb42d5bf8fd
[PostDog] Somewhat working copy. That would use for testing.
June Park <parkjune1995@gmail.com>
parents:
25
diff
changeset
|
445 ), |
|
ccb42d5bf8fd
[PostDog] Somewhat working copy. That would use for testing.
June Park <parkjune1995@gmail.com>
parents:
25
diff
changeset
|
446 progress_message = "Signing macOS app bundle {}".format(app_name), |
|
ccb42d5bf8fd
[PostDog] Somewhat working copy. That would use for testing.
June Park <parkjune1995@gmail.com>
parents:
25
diff
changeset
|
447 ) |
|
ccb42d5bf8fd
[PostDog] Somewhat working copy. That would use for testing.
June Park <parkjune1995@gmail.com>
parents:
25
diff
changeset
|
448 |
|
ccb42d5bf8fd
[PostDog] Somewhat working copy. That would use for testing.
June Park <parkjune1995@gmail.com>
parents:
25
diff
changeset
|
449 return [DefaultInfo(files = depset([signed_app_dir]))] |
|
ccb42d5bf8fd
[PostDog] Somewhat working copy. That would use for testing.
June Park <parkjune1995@gmail.com>
parents:
25
diff
changeset
|
450 |
|
ccb42d5bf8fd
[PostDog] Somewhat working copy. That would use for testing.
June Park <parkjune1995@gmail.com>
parents:
25
diff
changeset
|
451 _macos_signed_app = rule( |
|
ccb42d5bf8fd
[PostDog] Somewhat working copy. That would use for testing.
June Park <parkjune1995@gmail.com>
parents:
25
diff
changeset
|
452 implementation = _macos_signed_app_impl, |
|
ccb42d5bf8fd
[PostDog] Somewhat working copy. That would use for testing.
June Park <parkjune1995@gmail.com>
parents:
25
diff
changeset
|
453 attrs = { |
|
ccb42d5bf8fd
[PostDog] Somewhat working copy. That would use for testing.
June Park <parkjune1995@gmail.com>
parents:
25
diff
changeset
|
454 "app": attr.label( |
|
ccb42d5bf8fd
[PostDog] Somewhat working copy. That would use for testing.
June Park <parkjune1995@gmail.com>
parents:
25
diff
changeset
|
455 allow_single_file = True, |
|
ccb42d5bf8fd
[PostDog] Somewhat working copy. That would use for testing.
June Park <parkjune1995@gmail.com>
parents:
25
diff
changeset
|
456 mandatory = True, |
|
ccb42d5bf8fd
[PostDog] Somewhat working copy. That would use for testing.
June Park <parkjune1995@gmail.com>
parents:
25
diff
changeset
|
457 doc = "The .app directory to sign", |
|
ccb42d5bf8fd
[PostDog] Somewhat working copy. That would use for testing.
June Park <parkjune1995@gmail.com>
parents:
25
diff
changeset
|
458 ), |
|
ccb42d5bf8fd
[PostDog] Somewhat working copy. That would use for testing.
June Park <parkjune1995@gmail.com>
parents:
25
diff
changeset
|
459 "app_name": attr.string( |
|
ccb42d5bf8fd
[PostDog] Somewhat working copy. That would use for testing.
June Park <parkjune1995@gmail.com>
parents:
25
diff
changeset
|
460 mandatory = True, |
|
ccb42d5bf8fd
[PostDog] Somewhat working copy. That would use for testing.
June Park <parkjune1995@gmail.com>
parents:
25
diff
changeset
|
461 doc = "Name of the application", |
|
ccb42d5bf8fd
[PostDog] Somewhat working copy. That would use for testing.
June Park <parkjune1995@gmail.com>
parents:
25
diff
changeset
|
462 ), |
|
ccb42d5bf8fd
[PostDog] Somewhat working copy. That would use for testing.
June Park <parkjune1995@gmail.com>
parents:
25
diff
changeset
|
463 }, |
|
ccb42d5bf8fd
[PostDog] Somewhat working copy. That would use for testing.
June Park <parkjune1995@gmail.com>
parents:
25
diff
changeset
|
464 ) |
|
ccb42d5bf8fd
[PostDog] Somewhat working copy. That would use for testing.
June Park <parkjune1995@gmail.com>
parents:
25
diff
changeset
|
465 |
|
ccb42d5bf8fd
[PostDog] Somewhat working copy. That would use for testing.
June Park <parkjune1995@gmail.com>
parents:
25
diff
changeset
|
466 def macos_app_and_dmg(name, binary, bundle_id = "com.example.app"): |
|
ccb42d5bf8fd
[PostDog] Somewhat working copy. That would use for testing.
June Park <parkjune1995@gmail.com>
parents:
25
diff
changeset
|
467 """ |
|
ccb42d5bf8fd
[PostDog] Somewhat working copy. That would use for testing.
June Park <parkjune1995@gmail.com>
parents:
25
diff
changeset
|
468 Creates a macOS .app bundle, signs it, and packages it into a DMG. |
|
ccb42d5bf8fd
[PostDog] Somewhat working copy. That would use for testing.
June Park <parkjune1995@gmail.com>
parents:
25
diff
changeset
|
469 |
|
ccb42d5bf8fd
[PostDog] Somewhat working copy. That would use for testing.
June Park <parkjune1995@gmail.com>
parents:
25
diff
changeset
|
470 Args: |
|
ccb42d5bf8fd
[PostDog] Somewhat working copy. That would use for testing.
June Park <parkjune1995@gmail.com>
parents:
25
diff
changeset
|
471 name: Base name for the generated targets |
|
ccb42d5bf8fd
[PostDog] Somewhat working copy. That would use for testing.
June Park <parkjune1995@gmail.com>
parents:
25
diff
changeset
|
472 binary: Label of the binary target to bundle |
|
ccb42d5bf8fd
[PostDog] Somewhat working copy. That would use for testing.
June Park <parkjune1995@gmail.com>
parents:
25
diff
changeset
|
473 bundle_id: Bundle identifier for the app (default: com.example.app) |
|
ccb42d5bf8fd
[PostDog] Somewhat working copy. That would use for testing.
June Park <parkjune1995@gmail.com>
parents:
25
diff
changeset
|
474 |
|
ccb42d5bf8fd
[PostDog] Somewhat working copy. That would use for testing.
June Park <parkjune1995@gmail.com>
parents:
25
diff
changeset
|
475 Generates: |
|
ccb42d5bf8fd
[PostDog] Somewhat working copy. That would use for testing.
June Park <parkjune1995@gmail.com>
parents:
25
diff
changeset
|
476 {name}_app: The .app bundle |
|
ccb42d5bf8fd
[PostDog] Somewhat working copy. That would use for testing.
June Park <parkjune1995@gmail.com>
parents:
25
diff
changeset
|
477 {name}_signed_app: The signed .app bundle |
|
ccb42d5bf8fd
[PostDog] Somewhat working copy. That would use for testing.
June Park <parkjune1995@gmail.com>
parents:
25
diff
changeset
|
478 {name}_dmg: The final DMG file |
|
ccb42d5bf8fd
[PostDog] Somewhat working copy. That would use for testing.
June Park <parkjune1995@gmail.com>
parents:
25
diff
changeset
|
479 """ |
|
168
f3084bca7317
[Misc] Fixed all errors and all tests should pass now.
MrJuneJune <me@mrjunejune.com>
parents:
156
diff
changeset
|
480 macos_constraint = ["@platforms//os:macos"] |
|
f3084bca7317
[Misc] Fixed all errors and all tests should pass now.
MrJuneJune <me@mrjunejune.com>
parents:
156
diff
changeset
|
481 |
|
58
ccb42d5bf8fd
[PostDog] Somewhat working copy. That would use for testing.
June Park <parkjune1995@gmail.com>
parents:
25
diff
changeset
|
482 # 1. Build the .app bundle |
|
ccb42d5bf8fd
[PostDog] Somewhat working copy. That would use for testing.
June Park <parkjune1995@gmail.com>
parents:
25
diff
changeset
|
483 _macos_app( |
|
ccb42d5bf8fd
[PostDog] Somewhat working copy. That would use for testing.
June Park <parkjune1995@gmail.com>
parents:
25
diff
changeset
|
484 name = name + "_app", |
|
ccb42d5bf8fd
[PostDog] Somewhat working copy. That would use for testing.
June Park <parkjune1995@gmail.com>
parents:
25
diff
changeset
|
485 binary = binary, |
|
ccb42d5bf8fd
[PostDog] Somewhat working copy. That would use for testing.
June Park <parkjune1995@gmail.com>
parents:
25
diff
changeset
|
486 app_name = name, |
|
ccb42d5bf8fd
[PostDog] Somewhat working copy. That would use for testing.
June Park <parkjune1995@gmail.com>
parents:
25
diff
changeset
|
487 bundle_id = bundle_id, |
|
168
f3084bca7317
[Misc] Fixed all errors and all tests should pass now.
MrJuneJune <me@mrjunejune.com>
parents:
156
diff
changeset
|
488 target_compatible_with = macos_constraint, |
|
58
ccb42d5bf8fd
[PostDog] Somewhat working copy. That would use for testing.
June Park <parkjune1995@gmail.com>
parents:
25
diff
changeset
|
489 ) |
|
ccb42d5bf8fd
[PostDog] Somewhat working copy. That would use for testing.
June Park <parkjune1995@gmail.com>
parents:
25
diff
changeset
|
490 |
|
ccb42d5bf8fd
[PostDog] Somewhat working copy. That would use for testing.
June Park <parkjune1995@gmail.com>
parents:
25
diff
changeset
|
491 # 2. Sign the .app |
|
ccb42d5bf8fd
[PostDog] Somewhat working copy. That would use for testing.
June Park <parkjune1995@gmail.com>
parents:
25
diff
changeset
|
492 _macos_signed_app( |
|
ccb42d5bf8fd
[PostDog] Somewhat working copy. That would use for testing.
June Park <parkjune1995@gmail.com>
parents:
25
diff
changeset
|
493 name = name + "_signed_app", |
|
ccb42d5bf8fd
[PostDog] Somewhat working copy. That would use for testing.
June Park <parkjune1995@gmail.com>
parents:
25
diff
changeset
|
494 app = ":" + name + "_app", |
|
ccb42d5bf8fd
[PostDog] Somewhat working copy. That would use for testing.
June Park <parkjune1995@gmail.com>
parents:
25
diff
changeset
|
495 app_name = name, |
|
168
f3084bca7317
[Misc] Fixed all errors and all tests should pass now.
MrJuneJune <me@mrjunejune.com>
parents:
156
diff
changeset
|
496 target_compatible_with = macos_constraint, |
|
58
ccb42d5bf8fd
[PostDog] Somewhat working copy. That would use for testing.
June Park <parkjune1995@gmail.com>
parents:
25
diff
changeset
|
497 ) |
|
ccb42d5bf8fd
[PostDog] Somewhat working copy. That would use for testing.
June Park <parkjune1995@gmail.com>
parents:
25
diff
changeset
|
498 |
|
ccb42d5bf8fd
[PostDog] Somewhat working copy. That would use for testing.
June Park <parkjune1995@gmail.com>
parents:
25
diff
changeset
|
499 # 3. Create the DMG |
|
ccb42d5bf8fd
[PostDog] Somewhat working copy. That would use for testing.
June Park <parkjune1995@gmail.com>
parents:
25
diff
changeset
|
500 native.genrule( |
|
ccb42d5bf8fd
[PostDog] Somewhat working copy. That would use for testing.
June Park <parkjune1995@gmail.com>
parents:
25
diff
changeset
|
501 name = name + "_dmg", |
|
ccb42d5bf8fd
[PostDog] Somewhat working copy. That would use for testing.
June Park <parkjune1995@gmail.com>
parents:
25
diff
changeset
|
502 srcs = [":" + name + "_signed_app"], |
|
ccb42d5bf8fd
[PostDog] Somewhat working copy. That would use for testing.
June Park <parkjune1995@gmail.com>
parents:
25
diff
changeset
|
503 outs = [name + ".dmg"], |
|
ccb42d5bf8fd
[PostDog] Somewhat working copy. That would use for testing.
June Park <parkjune1995@gmail.com>
parents:
25
diff
changeset
|
504 cmd = """ |
|
ccb42d5bf8fd
[PostDog] Somewhat working copy. That would use for testing.
June Park <parkjune1995@gmail.com>
parents:
25
diff
changeset
|
505 set -e |
|
ccb42d5bf8fd
[PostDog] Somewhat working copy. That would use for testing.
June Park <parkjune1995@gmail.com>
parents:
25
diff
changeset
|
506 |
|
ccb42d5bf8fd
[PostDog] Somewhat working copy. That would use for testing.
June Park <parkjune1995@gmail.com>
parents:
25
diff
changeset
|
507 SIGNEDDIR="$(location :{name}_signed_app)" |
|
ccb42d5bf8fd
[PostDog] Somewhat working copy. That would use for testing.
June Park <parkjune1995@gmail.com>
parents:
25
diff
changeset
|
508 |
|
ccb42d5bf8fd
[PostDog] Somewhat working copy. That would use for testing.
June Park <parkjune1995@gmail.com>
parents:
25
diff
changeset
|
509 hdiutil create \ |
|
ccb42d5bf8fd
[PostDog] Somewhat working copy. That would use for testing.
June Park <parkjune1995@gmail.com>
parents:
25
diff
changeset
|
510 -volname {name} \ |
|
ccb42d5bf8fd
[PostDog] Somewhat working copy. That would use for testing.
June Park <parkjune1995@gmail.com>
parents:
25
diff
changeset
|
511 -srcfolder "$$SIGNEDDIR" \ |
|
ccb42d5bf8fd
[PostDog] Somewhat working copy. That would use for testing.
June Park <parkjune1995@gmail.com>
parents:
25
diff
changeset
|
512 -ov -format UDZO "$@" |
|
ccb42d5bf8fd
[PostDog] Somewhat working copy. That would use for testing.
June Park <parkjune1995@gmail.com>
parents:
25
diff
changeset
|
513 """.format(name = name), |
|
ccb42d5bf8fd
[PostDog] Somewhat working copy. That would use for testing.
June Park <parkjune1995@gmail.com>
parents:
25
diff
changeset
|
514 local = 1, # Disable sandboxing for hdiutil |
|
ccb42d5bf8fd
[PostDog] Somewhat working copy. That would use for testing.
June Park <parkjune1995@gmail.com>
parents:
25
diff
changeset
|
515 tags = ["no-sandbox"], |
|
168
f3084bca7317
[Misc] Fixed all errors and all tests should pass now.
MrJuneJune <me@mrjunejune.com>
parents:
156
diff
changeset
|
516 target_compatible_with = macos_constraint, |
|
58
ccb42d5bf8fd
[PostDog] Somewhat working copy. That would use for testing.
June Park <parkjune1995@gmail.com>
parents:
25
diff
changeset
|
517 ) |