annotate gui_ze/gui_ze.bzl @ 158:1c0878eb17de

[MrJuneJune] Readme file gets compiled in server side.
author June Park <parkjune1995@gmail.com>
date Wed, 14 Jan 2026 07:59:19 -0800
parents cd35e600ae34
children f3084bca7317
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
154
bdcc610eeed8 [Markdown Converter][GuiZe] Added markdown coverter in C and wasm rule sets. Needs further view on this as I haven't taken a look. Written by Claude.
June Park <parkjune1995@gmail.com>
parents: 128
diff changeset
1 def _wasm_binary_impl(ctx):
bdcc610eeed8 [Markdown Converter][GuiZe] Added markdown coverter in C and wasm rule sets. Needs further view on this as I haven't taken a look. Written by Claude.
June Park <parkjune1995@gmail.com>
parents: 128
diff changeset
2 """
bdcc610eeed8 [Markdown Converter][GuiZe] Added markdown coverter in C and wasm rule sets. Needs further view on this as I haven't taken a look. Written by Claude.
June Park <parkjune1995@gmail.com>
parents: 128
diff changeset
3 Compile C source to WASM using clang --target=wasm32.
bdcc610eeed8 [Markdown Converter][GuiZe] Added markdown coverter in C and wasm rule sets. Needs further view on this as I haven't taken a look. Written by Claude.
June Park <parkjune1995@gmail.com>
parents: 128
diff changeset
4 No libc - suitable for standalone WASM modules.
bdcc610eeed8 [Markdown Converter][GuiZe] Added markdown coverter in C and wasm rule sets. Needs further view on this as I haven't taken a look. Written by Claude.
June Park <parkjune1995@gmail.com>
parents: 128
diff changeset
5
bdcc610eeed8 [Markdown Converter][GuiZe] Added markdown coverter in C and wasm rule sets. Needs further view on this as I haven't taken a look. Written by Claude.
June Park <parkjune1995@gmail.com>
parents: 128
diff changeset
6 Requires LLVM with wasm32 support (e.g., Homebrew LLVM on macOS).
bdcc610eeed8 [Markdown Converter][GuiZe] Added markdown coverter in C and wasm rule sets. Needs further view on this as I haven't taken a look. Written by Claude.
June Park <parkjune1995@gmail.com>
parents: 128
diff changeset
7 """
bdcc610eeed8 [Markdown Converter][GuiZe] Added markdown coverter in C and wasm rule sets. Needs further view on this as I haven't taken a look. Written by Claude.
June Park <parkjune1995@gmail.com>
parents: 128
diff changeset
8 src = ctx.file.src
bdcc610eeed8 [Markdown Converter][GuiZe] Added markdown coverter in C and wasm rule sets. Needs further view on this as I haven't taken a look. Written by Claude.
June Park <parkjune1995@gmail.com>
parents: 128
diff changeset
9 out = ctx.actions.declare_file(ctx.label.name + ".wasm")
bdcc610eeed8 [Markdown Converter][GuiZe] Added markdown coverter in C and wasm rule sets. Needs further view on this as I haven't taken a look. Written by Claude.
June Park <parkjune1995@gmail.com>
parents: 128
diff changeset
10
bdcc610eeed8 [Markdown Converter][GuiZe] Added markdown coverter in C and wasm rule sets. Needs further view on this as I haven't taken a look. Written by Claude.
June Park <parkjune1995@gmail.com>
parents: 128
diff changeset
11 # Shell script to find clang with wasm support and set PATH for wasm-ld
bdcc610eeed8 [Markdown Converter][GuiZe] Added markdown coverter in C and wasm rule sets. Needs further view on this as I haven't taken a look. Written by Claude.
June Park <parkjune1995@gmail.com>
parents: 128
diff changeset
12 setup_cmd = """
bdcc610eeed8 [Markdown Converter][GuiZe] Added markdown coverter in C and wasm rule sets. Needs further view on this as I haven't taken a look. Written by Claude.
June Park <parkjune1995@gmail.com>
parents: 128
diff changeset
13 export PATH="/opt/homebrew/bin:/usr/local/bin:$PATH"
bdcc610eeed8 [Markdown Converter][GuiZe] Added markdown coverter in C and wasm rule sets. Needs further view on this as I haven't taken a look. Written by Claude.
June Park <parkjune1995@gmail.com>
parents: 128
diff changeset
14 if [ -x /opt/homebrew/opt/llvm/bin/clang ]; then
bdcc610eeed8 [Markdown Converter][GuiZe] Added markdown coverter in C and wasm rule sets. Needs further view on this as I haven't taken a look. Written by Claude.
June Park <parkjune1995@gmail.com>
parents: 128
diff changeset
15 CLANG=/opt/homebrew/opt/llvm/bin/clang
bdcc610eeed8 [Markdown Converter][GuiZe] Added markdown coverter in C and wasm rule sets. Needs further view on this as I haven't taken a look. Written by Claude.
June Park <parkjune1995@gmail.com>
parents: 128
diff changeset
16 elif [ -x /usr/local/opt/llvm/bin/clang ]; then
bdcc610eeed8 [Markdown Converter][GuiZe] Added markdown coverter in C and wasm rule sets. Needs further view on this as I haven't taken a look. Written by Claude.
June Park <parkjune1995@gmail.com>
parents: 128
diff changeset
17 CLANG=/usr/local/opt/llvm/bin/clang
bdcc610eeed8 [Markdown Converter][GuiZe] Added markdown coverter in C and wasm rule sets. Needs further view on this as I haven't taken a look. Written by Claude.
June Park <parkjune1995@gmail.com>
parents: 128
diff changeset
18 else
bdcc610eeed8 [Markdown Converter][GuiZe] Added markdown coverter in C and wasm rule sets. Needs further view on this as I haven't taken a look. Written by Claude.
June Park <parkjune1995@gmail.com>
parents: 128
diff changeset
19 CLANG=clang
bdcc610eeed8 [Markdown Converter][GuiZe] Added markdown coverter in C and wasm rule sets. Needs further view on this as I haven't taken a look. Written by Claude.
June Park <parkjune1995@gmail.com>
parents: 128
diff changeset
20 fi
bdcc610eeed8 [Markdown Converter][GuiZe] Added markdown coverter in C and wasm rule sets. Needs further view on this as I haven't taken a look. Written by Claude.
June Park <parkjune1995@gmail.com>
parents: 128
diff changeset
21 """
bdcc610eeed8 [Markdown Converter][GuiZe] Added markdown coverter in C and wasm rule sets. Needs further view on this as I haven't taken a look. Written by Claude.
June Park <parkjune1995@gmail.com>
parents: 128
diff changeset
22
bdcc610eeed8 [Markdown Converter][GuiZe] Added markdown coverter in C and wasm rule sets. Needs further view on this as I haven't taken a look. Written by Claude.
June Park <parkjune1995@gmail.com>
parents: 128
diff changeset
23 # Build clang command
bdcc610eeed8 [Markdown Converter][GuiZe] Added markdown coverter in C and wasm rule sets. Needs further view on this as I haven't taken a look. Written by Claude.
June Park <parkjune1995@gmail.com>
parents: 128
diff changeset
24 cmd_parts = [
bdcc610eeed8 [Markdown Converter][GuiZe] Added markdown coverter in C and wasm rule sets. Needs further view on this as I haven't taken a look. Written by Claude.
June Park <parkjune1995@gmail.com>
parents: 128
diff changeset
25 setup_cmd,
bdcc610eeed8 [Markdown Converter][GuiZe] Added markdown coverter in C and wasm rule sets. Needs further view on this as I haven't taken a look. Written by Claude.
June Park <parkjune1995@gmail.com>
parents: 128
diff changeset
26 "$CLANG",
bdcc610eeed8 [Markdown Converter][GuiZe] Added markdown coverter in C and wasm rule sets. Needs further view on this as I haven't taken a look. Written by Claude.
June Park <parkjune1995@gmail.com>
parents: 128
diff changeset
27 "--target=wasm32",
bdcc610eeed8 [Markdown Converter][GuiZe] Added markdown coverter in C and wasm rule sets. Needs further view on this as I haven't taken a look. Written by Claude.
June Park <parkjune1995@gmail.com>
parents: 128
diff changeset
28 "-nostdlib",
bdcc610eeed8 [Markdown Converter][GuiZe] Added markdown coverter in C and wasm rule sets. Needs further view on this as I haven't taken a look. Written by Claude.
June Park <parkjune1995@gmail.com>
parents: 128
diff changeset
29 "-O2",
bdcc610eeed8 [Markdown Converter][GuiZe] Added markdown coverter in C and wasm rule sets. Needs further view on this as I haven't taken a look. Written by Claude.
June Park <parkjune1995@gmail.com>
parents: 128
diff changeset
30 "-Wl,--no-entry",
bdcc610eeed8 [Markdown Converter][GuiZe] Added markdown coverter in C and wasm rule sets. Needs further view on this as I haven't taken a look. Written by Claude.
June Park <parkjune1995@gmail.com>
parents: 128
diff changeset
31 "-Wl,--export-dynamic",
bdcc610eeed8 [Markdown Converter][GuiZe] Added markdown coverter in C and wasm rule sets. Needs further view on this as I haven't taken a look. Written by Claude.
June Park <parkjune1995@gmail.com>
parents: 128
diff changeset
32 ]
bdcc610eeed8 [Markdown Converter][GuiZe] Added markdown coverter in C and wasm rule sets. Needs further view on this as I haven't taken a look. Written by Claude.
June Park <parkjune1995@gmail.com>
parents: 128
diff changeset
33
bdcc610eeed8 [Markdown Converter][GuiZe] Added markdown coverter in C and wasm rule sets. Needs further view on this as I haven't taken a look. Written by Claude.
June Park <parkjune1995@gmail.com>
parents: 128
diff changeset
34 # Add exported functions
bdcc610eeed8 [Markdown Converter][GuiZe] Added markdown coverter in C and wasm rule sets. Needs further view on this as I haven't taken a look. Written by Claude.
June Park <parkjune1995@gmail.com>
parents: 128
diff changeset
35 for fn in ctx.attr.exports:
bdcc610eeed8 [Markdown Converter][GuiZe] Added markdown coverter in C and wasm rule sets. Needs further view on this as I haven't taken a look. Written by Claude.
June Park <parkjune1995@gmail.com>
parents: 128
diff changeset
36 cmd_parts.append("-Wl,--export=" + fn)
bdcc610eeed8 [Markdown Converter][GuiZe] Added markdown coverter in C and wasm rule sets. Needs further view on this as I haven't taken a look. Written by Claude.
June Park <parkjune1995@gmail.com>
parents: 128
diff changeset
37
bdcc610eeed8 [Markdown Converter][GuiZe] Added markdown coverter in C and wasm rule sets. Needs further view on this as I haven't taken a look. Written by Claude.
June Park <parkjune1995@gmail.com>
parents: 128
diff changeset
38 cmd_parts.append("-o")
bdcc610eeed8 [Markdown Converter][GuiZe] Added markdown coverter in C and wasm rule sets. Needs further view on this as I haven't taken a look. Written by Claude.
June Park <parkjune1995@gmail.com>
parents: 128
diff changeset
39 cmd_parts.append(out.path)
bdcc610eeed8 [Markdown Converter][GuiZe] Added markdown coverter in C and wasm rule sets. Needs further view on this as I haven't taken a look. Written by Claude.
June Park <parkjune1995@gmail.com>
parents: 128
diff changeset
40 cmd_parts.append(src.path)
bdcc610eeed8 [Markdown Converter][GuiZe] Added markdown coverter in C and wasm rule sets. Needs further view on this as I haven't taken a look. Written by Claude.
June Park <parkjune1995@gmail.com>
parents: 128
diff changeset
41
bdcc610eeed8 [Markdown Converter][GuiZe] Added markdown coverter in C and wasm rule sets. Needs further view on this as I haven't taken a look. Written by Claude.
June Park <parkjune1995@gmail.com>
parents: 128
diff changeset
42 ctx.actions.run_shell(
bdcc610eeed8 [Markdown Converter][GuiZe] Added markdown coverter in C and wasm rule sets. Needs further view on this as I haven't taken a look. Written by Claude.
June Park <parkjune1995@gmail.com>
parents: 128
diff changeset
43 inputs = [src],
bdcc610eeed8 [Markdown Converter][GuiZe] Added markdown coverter in C and wasm rule sets. Needs further view on this as I haven't taken a look. Written by Claude.
June Park <parkjune1995@gmail.com>
parents: 128
diff changeset
44 outputs = [out],
bdcc610eeed8 [Markdown Converter][GuiZe] Added markdown coverter in C and wasm rule sets. Needs further view on this as I haven't taken a look. Written by Claude.
June Park <parkjune1995@gmail.com>
parents: 128
diff changeset
45 command = " ".join(cmd_parts),
bdcc610eeed8 [Markdown Converter][GuiZe] Added markdown coverter in C and wasm rule sets. Needs further view on this as I haven't taken a look. Written by Claude.
June Park <parkjune1995@gmail.com>
parents: 128
diff changeset
46 progress_message = "Compiling {} to WASM".format(src.basename),
bdcc610eeed8 [Markdown Converter][GuiZe] Added markdown coverter in C and wasm rule sets. Needs further view on this as I haven't taken a look. Written by Claude.
June Park <parkjune1995@gmail.com>
parents: 128
diff changeset
47 execution_requirements = {"no-sandbox": "1"},
bdcc610eeed8 [Markdown Converter][GuiZe] Added markdown coverter in C and wasm rule sets. Needs further view on this as I haven't taken a look. Written by Claude.
June Park <parkjune1995@gmail.com>
parents: 128
diff changeset
48 )
bdcc610eeed8 [Markdown Converter][GuiZe] Added markdown coverter in C and wasm rule sets. Needs further view on this as I haven't taken a look. Written by Claude.
June Park <parkjune1995@gmail.com>
parents: 128
diff changeset
49
bdcc610eeed8 [Markdown Converter][GuiZe] Added markdown coverter in C and wasm rule sets. Needs further view on this as I haven't taken a look. Written by Claude.
June Park <parkjune1995@gmail.com>
parents: 128
diff changeset
50 return [DefaultInfo(files = depset([out]))]
bdcc610eeed8 [Markdown Converter][GuiZe] Added markdown coverter in C and wasm rule sets. Needs further view on this as I haven't taken a look. Written by Claude.
June Park <parkjune1995@gmail.com>
parents: 128
diff changeset
51
bdcc610eeed8 [Markdown Converter][GuiZe] Added markdown coverter in C and wasm rule sets. Needs further view on this as I haven't taken a look. Written by Claude.
June Park <parkjune1995@gmail.com>
parents: 128
diff changeset
52 wasm_binary = rule(
bdcc610eeed8 [Markdown Converter][GuiZe] Added markdown coverter in C and wasm rule sets. Needs further view on this as I haven't taken a look. Written by Claude.
June Park <parkjune1995@gmail.com>
parents: 128
diff changeset
53 implementation = _wasm_binary_impl,
bdcc610eeed8 [Markdown Converter][GuiZe] Added markdown coverter in C and wasm rule sets. Needs further view on this as I haven't taken a look. Written by Claude.
June Park <parkjune1995@gmail.com>
parents: 128
diff changeset
54 attrs = {
bdcc610eeed8 [Markdown Converter][GuiZe] Added markdown coverter in C and wasm rule sets. Needs further view on this as I haven't taken a look. Written by Claude.
June Park <parkjune1995@gmail.com>
parents: 128
diff changeset
55 "src": attr.label(
bdcc610eeed8 [Markdown Converter][GuiZe] Added markdown coverter in C and wasm rule sets. Needs further view on this as I haven't taken a look. Written by Claude.
June Park <parkjune1995@gmail.com>
parents: 128
diff changeset
56 allow_single_file = [".c"],
bdcc610eeed8 [Markdown Converter][GuiZe] Added markdown coverter in C and wasm rule sets. Needs further view on this as I haven't taken a look. Written by Claude.
June Park <parkjune1995@gmail.com>
parents: 128
diff changeset
57 mandatory = True,
bdcc610eeed8 [Markdown Converter][GuiZe] Added markdown coverter in C and wasm rule sets. Needs further view on this as I haven't taken a look. Written by Claude.
June Park <parkjune1995@gmail.com>
parents: 128
diff changeset
58 doc = "The C source file to compile",
bdcc610eeed8 [Markdown Converter][GuiZe] Added markdown coverter in C and wasm rule sets. Needs further view on this as I haven't taken a look. Written by Claude.
June Park <parkjune1995@gmail.com>
parents: 128
diff changeset
59 ),
bdcc610eeed8 [Markdown Converter][GuiZe] Added markdown coverter in C and wasm rule sets. Needs further view on this as I haven't taken a look. Written by Claude.
June Park <parkjune1995@gmail.com>
parents: 128
diff changeset
60 "exports": attr.string_list(
bdcc610eeed8 [Markdown Converter][GuiZe] Added markdown coverter in C and wasm rule sets. Needs further view on this as I haven't taken a look. Written by Claude.
June Park <parkjune1995@gmail.com>
parents: 128
diff changeset
61 default = [],
bdcc610eeed8 [Markdown Converter][GuiZe] Added markdown coverter in C and wasm rule sets. Needs further view on this as I haven't taken a look. Written by Claude.
June Park <parkjune1995@gmail.com>
parents: 128
diff changeset
62 doc = "List of function names to export (without leading underscore)",
bdcc610eeed8 [Markdown Converter][GuiZe] Added markdown coverter in C and wasm rule sets. Needs further view on this as I haven't taken a look. Written by Claude.
June Park <parkjune1995@gmail.com>
parents: 128
diff changeset
63 ),
bdcc610eeed8 [Markdown Converter][GuiZe] Added markdown coverter in C and wasm rule sets. Needs further view on this as I haven't taken a look. Written by Claude.
June Park <parkjune1995@gmail.com>
parents: 128
diff changeset
64 },
bdcc610eeed8 [Markdown Converter][GuiZe] Added markdown coverter in C and wasm rule sets. Needs further view on this as I haven't taken a look. Written by Claude.
June Park <parkjune1995@gmail.com>
parents: 128
diff changeset
65 )
bdcc610eeed8 [Markdown Converter][GuiZe] Added markdown coverter in C and wasm rule sets. Needs further view on this as I haven't taken a look. Written by Claude.
June Park <parkjune1995@gmail.com>
parents: 128
diff changeset
66
8
98f96b8032e5 [GuiZe] Creating custom bazel rule to deploy to github easily.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
67 def _foo_impl(ctx):
12
de54585a40f1 Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents: 8
diff changeset
68 out = ctx.actions.declare_file(ctx.label.name)
de54585a40f1 Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents: 8
diff changeset
69 ctx.actions.write(
de54585a40f1 Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents: 8
diff changeset
70 output = out,
de54585a40f1 Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents: 8
diff changeset
71 content = "Hello!\n",
de54585a40f1 Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents: 8
diff changeset
72 )
de54585a40f1 Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents: 8
diff changeset
73 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
74
98f96b8032e5 [GuiZe] Creating custom bazel rule to deploy to github easily.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
75 foo_binary = rule(
98f96b8032e5 [GuiZe] Creating custom bazel rule to deploy to github easily.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
76 implementation = _foo_impl,
98f96b8032e5 [GuiZe] Creating custom bazel rule to deploy to github easily.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
77 )
98f96b8032e5 [GuiZe] Creating custom bazel rule to deploy to github easily.
June Park <parkjune1995@gmail.com>
parents:
diff changeset
78
12
de54585a40f1 Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents: 8
diff changeset
79 def _bundle_impl(ctx):
de54585a40f1 Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents: 8
diff changeset
80 """
de54585a40f1 Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents: 8
diff changeset
81 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
82 """
de54585a40f1 Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents: 8
diff changeset
83 binary_target = ctx.attr.binary
de54585a40f1 Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents: 8
diff changeset
84 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
85 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
86
de54585a40f1 Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents: 8
diff changeset
87 # Name as output directory
de54585a40f1 Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents: 8
diff changeset
88 out_dir = ctx.actions.declare_directory(ctx.label.name)
de54585a40f1 Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents: 8
diff changeset
89
de54585a40f1 Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents: 8
diff changeset
90 copy_cmd = []
de54585a40f1 Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents: 8
diff changeset
91 copy_cmd.append("mkdir -p {}".format(out_dir.path))
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 for f in runfiles_files:
de54585a40f1 Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents: 8
diff changeset
94 if f.path == binary.path:
de54585a40f1 Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents: 8
diff changeset
95 continue
15
2b9e75756825 [GuiZe] Updated to handle bundling and created a shee
June Park <parkjune1995@gmail.com>
parents: 12
diff changeset
96
2b9e75756825 [GuiZe] Updated to handle bundling and created a shee
June Park <parkjune1995@gmail.com>
parents: 12
diff changeset
97 start = 0
2b9e75756825 [GuiZe] Updated to handle bundling and created a shee
June Park <parkjune1995@gmail.com>
parents: 12
diff changeset
98 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
99 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
100 break
2b9e75756825 [GuiZe] Updated to handle bundling and created a shee
June Park <parkjune1995@gmail.com>
parents: 12
diff changeset
101 start += 1
2b9e75756825 [GuiZe] Updated to handle bundling and created a shee
June Park <parkjune1995@gmail.com>
parents: 12
diff changeset
102
12
de54585a40f1 Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents: 8
diff changeset
103 # 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
104 paths = "/".join(f.path.split("/")[start:-1])
12
de54585a40f1 Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents: 8
diff changeset
105 full_path = "{}/{}".format(out_dir.path, paths)
de54585a40f1 Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents: 8
diff changeset
106 copy_cmd.append("mkdir -p {}".format(full_path))
de54585a40f1 Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents: 8
diff changeset
107 copy_cmd.append("cp {} {}".format(f.path, full_path))
de54585a40f1 Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents: 8
diff changeset
108
de54585a40f1 Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents: 8
diff changeset
109 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
110
de54585a40f1 Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents: 8
diff changeset
111 ctx.actions.run_shell(
de54585a40f1 Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents: 8
diff changeset
112 inputs = runfiles_files,
de54585a40f1 Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents: 8
diff changeset
113 outputs = [out_dir],
de54585a40f1 Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents: 8
diff changeset
114 command = " && ".join(copy_cmd),
de54585a40f1 Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents: 8
diff changeset
115 progress_message = "Bundling {}".format(ctx.label.name),
de54585a40f1 Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents: 8
diff changeset
116 )
de54585a40f1 Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents: 8
diff changeset
117 return [DefaultInfo(files = depset([out_dir]))]
de54585a40f1 Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents: 8
diff changeset
118
de54585a40f1 Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents: 8
diff changeset
119 bundle = rule(
de54585a40f1 Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents: 8
diff changeset
120 implementation = _bundle_impl,
de54585a40f1 Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents: 8
diff changeset
121 attrs = {
de54585a40f1 Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents: 8
diff changeset
122 "binary": attr.label(
de54585a40f1 Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents: 8
diff changeset
123 doc = "The cc_binary target to bundle",
de54585a40f1 Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents: 8
diff changeset
124 providers = [DefaultInfo],
de54585a40f1 Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents: 8
diff changeset
125 ),
de54585a40f1 Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents: 8
diff changeset
126 },
de54585a40f1 Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents: 8
diff changeset
127 )
de54585a40f1 Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents: 8
diff changeset
128
de54585a40f1 Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents: 8
diff changeset
129
de54585a40f1 Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents: 8
diff changeset
130 def _bun_binary_impl(ctx):
de54585a40f1 Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents: 8
diff changeset
131 out = ctx.actions.declare_file("bun")
de54585a40f1 Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents: 8
diff changeset
132 ctx.actions.run_shell(
de54585a40f1 Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents: 8
diff changeset
133 inputs = ctx.files.srcs,
de54585a40f1 Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents: 8
diff changeset
134 outputs = [out],
de54585a40f1 Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents: 8
diff changeset
135 command = """
de54585a40f1 Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents: 8
diff changeset
136 mkdir -p {outdir}
de54585a40f1 Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents: 8
diff changeset
137 unzip -j {src} {inner} -d {outdir}
de54585a40f1 Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents: 8
diff changeset
138 chmod +x {outdir}/bun
de54585a40f1 Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents: 8
diff changeset
139 """.format(
de54585a40f1 Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents: 8
diff changeset
140 outdir = out.dirname,
de54585a40f1 Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents: 8
diff changeset
141 src = ctx.files.srcs[0].path,
24
7d3fa1a7a854 [GuiZe] Support x86 chip for bun.
June Park <parkjune1995@gmail.com>
parents: 15
diff changeset
142 inner = ctx.attr.src_folder,
12
de54585a40f1 Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents: 8
diff changeset
143 out = out.path,
de54585a40f1 Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents: 8
diff changeset
144 ),
de54585a40f1 Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents: 8
diff changeset
145 )
de54585a40f1 Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents: 8
diff changeset
146 return DefaultInfo(
de54585a40f1 Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents: 8
diff changeset
147 files = depset([out]),
de54585a40f1 Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents: 8
diff changeset
148 executable = out,
de54585a40f1 Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents: 8
diff changeset
149 )
de54585a40f1 Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents: 8
diff changeset
150
de54585a40f1 Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents: 8
diff changeset
151 bun_binary = rule(
de54585a40f1 Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents: 8
diff changeset
152 implementation = _bun_binary_impl,
de54585a40f1 Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents: 8
diff changeset
153 attrs = {
25
342726584be2 [Bun] Fixed how bun would be ran within bazel.
June Park <parkjune1995@gmail.com>
parents: 24
diff changeset
154 "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
155 "src_folder": attr.string(),
12
de54585a40f1 Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents: 8
diff changeset
156 },
de54585a40f1 Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents: 8
diff changeset
157 executable = True,
de54585a40f1 Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents: 8
diff changeset
158 )
de54585a40f1 Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents: 8
diff changeset
159
de54585a40f1 Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents: 8
diff changeset
160 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
161 """
2b9e75756825 [GuiZe] Updated to handle bundling and created a shee
June Park <parkjune1995@gmail.com>
parents: 12
diff changeset
162 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
163
2b9e75756825 [GuiZe] Updated to handle bundling and created a shee
June Park <parkjune1995@gmail.com>
parents: 12
diff changeset
164 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
165 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
166
25
342726584be2 [Bun] Fixed how bun would be ran within bazel.
June Park <parkjune1995@gmail.com>
parents: 24
diff changeset
167 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
168 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
169 """
12
de54585a40f1 Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents: 8
diff changeset
170 out = ctx.actions.declare_file(ctx.label.name + ".js")
de54585a40f1 Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents: 8
diff changeset
171 inputs = [ctx.file.src] + ctx.files.data
de54585a40f1 Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents: 8
diff changeset
172
de54585a40f1 Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents: 8
diff changeset
173 ctx.actions.run_shell(
de54585a40f1 Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents: 8
diff changeset
174 inputs = inputs,
de54585a40f1 Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents: 8
diff changeset
175 outputs = [out],
de54585a40f1 Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents: 8
diff changeset
176 tools = [ctx.executable._bun] + inputs,
de54585a40f1 Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents: 8
diff changeset
177 command = """
de54585a40f1 Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents: 8
diff changeset
178 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
179 && cp -r {src_folder}/** . \
342726584be2 [Bun] Fixed how bun would be ran within bazel.
June Park <parkjune1995@gmail.com>
parents: 24
diff changeset
180 && export NODE_PATH=./node_modules && {bun_path} build {input_path} --outfile {output_path}
12
de54585a40f1 Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents: 8
diff changeset
181 """.format(
25
342726584be2 [Bun] Fixed how bun would be ran within bazel.
June Park <parkjune1995@gmail.com>
parents: 24
diff changeset
182 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
183 src_folder = ctx.attr.src_folder,
342726584be2 [Bun] Fixed how bun would be ran within bazel.
June Park <parkjune1995@gmail.com>
parents: 24
diff changeset
184 input_path = ctx.file.src.path.split("/")[-1],
342726584be2 [Bun] Fixed how bun would be ran within bazel.
June Park <parkjune1995@gmail.com>
parents: 24
diff changeset
185 output_path = out.path,
12
de54585a40f1 Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents: 8
diff changeset
186 ),
de54585a40f1 Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents: 8
diff changeset
187 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
188 )
de54585a40f1 Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents: 8
diff changeset
189
de54585a40f1 Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents: 8
diff changeset
190 return [DefaultInfo(files=depset([out]))]
de54585a40f1 Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents: 8
diff changeset
191
de54585a40f1 Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents: 8
diff changeset
192 bun_build = rule(
de54585a40f1 Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents: 8
diff changeset
193 implementation = _bun_build_impl,
de54585a40f1 Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents: 8
diff changeset
194 attrs = {
de54585a40f1 Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents: 8
diff changeset
195 "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
196 "_bun": attr.label(
de54585a40f1 Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents: 8
diff changeset
197 default = Label("//third_party/bun:bun"),
de54585a40f1 Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents: 8
diff changeset
198 executable = True,
de54585a40f1 Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents: 8
diff changeset
199 cfg = "exec",
de54585a40f1 Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents: 8
diff changeset
200 ),
de54585a40f1 Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents: 8
diff changeset
201 "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
202 "src_folder": attr.string(),
12
de54585a40f1 Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents: 8
diff changeset
203 },
de54585a40f1 Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents: 8
diff changeset
204 )
de54585a40f1 Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents: 8
diff changeset
205
156
cd35e600ae34 [MarkDown Converter] Fixed few things and made a test
June Park <parkjune1995@gmail.com>
parents: 154
diff changeset
206 def _bun_run_impl(ctx):
cd35e600ae34 [MarkDown Converter] Fixed few things and made a test
June Park <parkjune1995@gmail.com>
parents: 154
diff changeset
207 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
208
cd35e600ae34 [MarkDown Converter] Fixed few things and made a test
June Park <parkjune1995@gmail.com>
parents: 154
diff changeset
209 # 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
210 workspace_name = ctx.workspace_name
cd35e600ae34 [MarkDown Converter] Fixed few things and made a test
June Park <parkjune1995@gmail.com>
parents: 154
diff changeset
211
cd35e600ae34 [MarkDown Converter] Fixed few things and made a test
June Park <parkjune1995@gmail.com>
parents: 154
diff changeset
212 # 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
213 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
214 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
215
cd35e600ae34 [MarkDown Converter] Fixed few things and made a test
June Park <parkjune1995@gmail.com>
parents: 154
diff changeset
216 # 3. Create the launcher script
cd35e600ae34 [MarkDown Converter] Fixed few things and made a test
June Park <parkjune1995@gmail.com>
parents: 154
diff changeset
217 # 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
218 script_content = """#!/bin/bash
cd35e600ae34 [MarkDown Converter] Fixed few things and made a test
June Park <parkjune1995@gmail.com>
parents: 154
diff changeset
219 # Find the runfiles directory
cd35e600ae34 [MarkDown Converter] Fixed few things and made a test
June Park <parkjune1995@gmail.com>
parents: 154
diff changeset
220 if [[ -z "$RUNFILES_DIR" ]]; then
cd35e600ae34 [MarkDown Converter] Fixed few things and made a test
June Park <parkjune1995@gmail.com>
parents: 154
diff changeset
221 if [[ -d "$0.runfiles" ]]; then
cd35e600ae34 [MarkDown Converter] Fixed few things and made a test
June Park <parkjune1995@gmail.com>
parents: 154
diff changeset
222 RUNFILES_DIR="$0.runfiles"
cd35e600ae34 [MarkDown Converter] Fixed few things and made a test
June Park <parkjune1995@gmail.com>
parents: 154
diff changeset
223 fi
cd35e600ae34 [MarkDown Converter] Fixed few things and made a test
June Park <parkjune1995@gmail.com>
parents: 154
diff changeset
224 fi
cd35e600ae34 [MarkDown Converter] Fixed few things and made a test
June Park <parkjune1995@gmail.com>
parents: 154
diff changeset
225
cd35e600ae34 [MarkDown Converter] Fixed few things and made a test
June Park <parkjune1995@gmail.com>
parents: 154
diff changeset
226 # 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
227 cd "$RUNFILES_DIR/{workspace}"
cd35e600ae34 [MarkDown Converter] Fixed few things and made a test
June Park <parkjune1995@gmail.com>
parents: 154
diff changeset
228 pwd
cd35e600ae34 [MarkDown Converter] Fixed few things and made a test
June Park <parkjune1995@gmail.com>
parents: 154
diff changeset
229 # 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
230 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
231 """.format(
cd35e600ae34 [MarkDown Converter] Fixed few things and made a test
June Park <parkjune1995@gmail.com>
parents: 154
diff changeset
232 workspace = workspace_name,
cd35e600ae34 [MarkDown Converter] Fixed few things and made a test
June Park <parkjune1995@gmail.com>
parents: 154
diff changeset
233 bun_bin = bun_path,
cd35e600ae34 [MarkDown Converter] Fixed few things and made a test
June Park <parkjune1995@gmail.com>
parents: 154
diff changeset
234 src_file = src_path
cd35e600ae34 [MarkDown Converter] Fixed few things and made a test
June Park <parkjune1995@gmail.com>
parents: 154
diff changeset
235 )
cd35e600ae34 [MarkDown Converter] Fixed few things and made a test
June Park <parkjune1995@gmail.com>
parents: 154
diff changeset
236
cd35e600ae34 [MarkDown Converter] Fixed few things and made a test
June Park <parkjune1995@gmail.com>
parents: 154
diff changeset
237 ctx.actions.write(
cd35e600ae34 [MarkDown Converter] Fixed few things and made a test
June Park <parkjune1995@gmail.com>
parents: 154
diff changeset
238 output = actual_exe,
cd35e600ae34 [MarkDown Converter] Fixed few things and made a test
June Park <parkjune1995@gmail.com>
parents: 154
diff changeset
239 content = script_content,
cd35e600ae34 [MarkDown Converter] Fixed few things and made a test
June Park <parkjune1995@gmail.com>
parents: 154
diff changeset
240 is_executable = True,
cd35e600ae34 [MarkDown Converter] Fixed few things and made a test
June Park <parkjune1995@gmail.com>
parents: 154
diff changeset
241 )
cd35e600ae34 [MarkDown Converter] Fixed few things and made a test
June Park <parkjune1995@gmail.com>
parents: 154
diff changeset
242
cd35e600ae34 [MarkDown Converter] Fixed few things and made a test
June Park <parkjune1995@gmail.com>
parents: 154
diff changeset
243 return [
cd35e600ae34 [MarkDown Converter] Fixed few things and made a test
June Park <parkjune1995@gmail.com>
parents: 154
diff changeset
244 DefaultInfo(
cd35e600ae34 [MarkDown Converter] Fixed few things and made a test
June Park <parkjune1995@gmail.com>
parents: 154
diff changeset
245 executable = actual_exe,
cd35e600ae34 [MarkDown Converter] Fixed few things and made a test
June Park <parkjune1995@gmail.com>
parents: 154
diff changeset
246 runfiles = ctx.runfiles(
cd35e600ae34 [MarkDown Converter] Fixed few things and made a test
June Park <parkjune1995@gmail.com>
parents: 154
diff changeset
247 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
248 ).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
249 ),
cd35e600ae34 [MarkDown Converter] Fixed few things and made a test
June Park <parkjune1995@gmail.com>
parents: 154
diff changeset
250 ]
cd35e600ae34 [MarkDown Converter] Fixed few things and made a test
June Park <parkjune1995@gmail.com>
parents: 154
diff changeset
251
cd35e600ae34 [MarkDown Converter] Fixed few things and made a test
June Park <parkjune1995@gmail.com>
parents: 154
diff changeset
252 # 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
253 bun_run = rule(
cd35e600ae34 [MarkDown Converter] Fixed few things and made a test
June Park <parkjune1995@gmail.com>
parents: 154
diff changeset
254 implementation = _bun_run_impl,
cd35e600ae34 [MarkDown Converter] Fixed few things and made a test
June Park <parkjune1995@gmail.com>
parents: 154
diff changeset
255 executable = True,
cd35e600ae34 [MarkDown Converter] Fixed few things and made a test
June Park <parkjune1995@gmail.com>
parents: 154
diff changeset
256 attrs = {
cd35e600ae34 [MarkDown Converter] Fixed few things and made a test
June Park <parkjune1995@gmail.com>
parents: 154
diff changeset
257 "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
258 "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
259 "_bun": attr.label(
cd35e600ae34 [MarkDown Converter] Fixed few things and made a test
June Park <parkjune1995@gmail.com>
parents: 154
diff changeset
260 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
261 executable = True,
cd35e600ae34 [MarkDown Converter] Fixed few things and made a test
June Park <parkjune1995@gmail.com>
parents: 154
diff changeset
262 cfg = "exec"
cd35e600ae34 [MarkDown Converter] Fixed few things and made a test
June Park <parkjune1995@gmail.com>
parents: 154
diff changeset
263 ),
cd35e600ae34 [MarkDown Converter] Fixed few things and made a test
June Park <parkjune1995@gmail.com>
parents: 154
diff changeset
264 "_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
265 },
cd35e600ae34 [MarkDown Converter] Fixed few things and made a test
June Park <parkjune1995@gmail.com>
parents: 154
diff changeset
266 )
cd35e600ae34 [MarkDown Converter] Fixed few things and made a test
June Park <parkjune1995@gmail.com>
parents: 154
diff changeset
267
cd35e600ae34 [MarkDown Converter] Fixed few things and made a test
June Park <parkjune1995@gmail.com>
parents: 154
diff changeset
268
12
de54585a40f1 Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents: 8
diff changeset
269 def _move_files_into_dir_impl(ctx):
de54585a40f1 Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents: 8
diff changeset
270 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
271 outs = []
12
de54585a40f1 Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents: 8
diff changeset
272 for src in srcs:
de54585a40f1 Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents: 8
diff changeset
273 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
274 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
275 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
276 outputs = [out],
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
277 command = "cp \"$1\" \"$2\"",
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
278 arguments = [src.path, out.path],
12
de54585a40f1 Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents: 8
diff changeset
279 )
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
280 outs.append(out)
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
281 return [DefaultInfo(files = depset(outs))]
12
de54585a40f1 Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents: 8
diff changeset
282
de54585a40f1 Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents: 8
diff changeset
283 move_files_into_dir = rule(
de54585a40f1 Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents: 8
diff changeset
284 implementation = _move_files_into_dir_impl,
de54585a40f1 Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents: 8
diff changeset
285 attrs = {
de54585a40f1 Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents: 8
diff changeset
286 "srcs": attr.label_list(allow_files=True),
de54585a40f1 Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents: 8
diff changeset
287 "dest": attr.string(),
de54585a40f1 Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents: 8
diff changeset
288 },
de54585a40f1 Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents: 8
diff changeset
289 )
de54585a40f1 Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents: 8
diff changeset
290
de54585a40f1 Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents: 8
diff changeset
291 def _move_to_directory_impl(ctx):
de54585a40f1 Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents: 8
diff changeset
292 srcs = ctx.files.data
de54585a40f1 Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents: 8
diff changeset
293 res = []
de54585a40f1 Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents: 8
diff changeset
294 for src in srcs:
de54585a40f1 Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents: 8
diff changeset
295 true = "/".join(src.path.split("/")[2:])
de54585a40f1 Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents: 8
diff changeset
296 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
297 out = ctx.actions.declare_file(
de54585a40f1 Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents: 8
diff changeset
298 path
de54585a40f1 Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents: 8
diff changeset
299 );
de54585a40f1 Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents: 8
diff changeset
300 ctx.actions.symlink(
de54585a40f1 Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents: 8
diff changeset
301 output = out,
de54585a40f1 Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents: 8
diff changeset
302 target_file = src,
de54585a40f1 Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents: 8
diff changeset
303 )
de54585a40f1 Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents: 8
diff changeset
304 res.append(out)
de54585a40f1 Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents: 8
diff changeset
305 return [DefaultInfo(files = depset(res))]
de54585a40f1 Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents: 8
diff changeset
306
de54585a40f1 Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents: 8
diff changeset
307 move_to_directory = rule(
de54585a40f1 Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents: 8
diff changeset
308 implementation = _move_to_directory_impl,
de54585a40f1 Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents: 8
diff changeset
309 attrs = {
de54585a40f1 Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents: 8
diff changeset
310 "data": attr.label_list(allow_files=True),
de54585a40f1 Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents: 8
diff changeset
311 "dest": attr.string(),
de54585a40f1 Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents: 8
diff changeset
312 },
de54585a40f1 Adding bun and node modules.
June Park <parkjune1995@gmail.com>
parents: 8
diff changeset
313 )
58
ccb42d5bf8fd [PostDog] Somewhat working copy. That would use for testing.
June Park <parkjune1995@gmail.com>
parents: 25
diff changeset
314
ccb42d5bf8fd [PostDog] Somewhat working copy. That would use for testing.
June Park <parkjune1995@gmail.com>
parents: 25
diff changeset
315
ccb42d5bf8fd [PostDog] Somewhat working copy. That would use for testing.
June Park <parkjune1995@gmail.com>
parents: 25
diff changeset
316 def _macos_app_impl(ctx):
ccb42d5bf8fd [PostDog] Somewhat working copy. That would use for testing.
June Park <parkjune1995@gmail.com>
parents: 25
diff changeset
317 """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
318 binary = ctx.file.binary
ccb42d5bf8fd [PostDog] Somewhat working copy. That would use for testing.
June Park <parkjune1995@gmail.com>
parents: 25
diff changeset
319 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
320 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
321
ccb42d5bf8fd [PostDog] Somewhat working copy. That would use for testing.
June Park <parkjune1995@gmail.com>
parents: 25
diff changeset
322 # 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
323 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
324
ccb42d5bf8fd [PostDog] Somewhat working copy. That would use for testing.
June Park <parkjune1995@gmail.com>
parents: 25
diff changeset
325 ctx.actions.run_shell(
ccb42d5bf8fd [PostDog] Somewhat working copy. That would use for testing.
June Park <parkjune1995@gmail.com>
parents: 25
diff changeset
326 inputs = [binary],
ccb42d5bf8fd [PostDog] Somewhat working copy. That would use for testing.
June Park <parkjune1995@gmail.com>
parents: 25
diff changeset
327 outputs = [app_dir],
ccb42d5bf8fd [PostDog] Somewhat working copy. That would use for testing.
June Park <parkjune1995@gmail.com>
parents: 25
diff changeset
328 command = """
ccb42d5bf8fd [PostDog] Somewhat working copy. That would use for testing.
June Park <parkjune1995@gmail.com>
parents: 25
diff changeset
329 set -e
ccb42d5bf8fd [PostDog] Somewhat working copy. That would use for testing.
June Park <parkjune1995@gmail.com>
parents: 25
diff changeset
330
ccb42d5bf8fd [PostDog] Somewhat working copy. That would use for testing.
June Park <parkjune1995@gmail.com>
parents: 25
diff changeset
331 APPDIR="{app_dir}"
ccb42d5bf8fd [PostDog] Somewhat working copy. That would use for testing.
June Park <parkjune1995@gmail.com>
parents: 25
diff changeset
332
ccb42d5bf8fd [PostDog] Somewhat working copy. That would use for testing.
June Park <parkjune1995@gmail.com>
parents: 25
diff changeset
333 rm -rf "$APPDIR"
ccb42d5bf8fd [PostDog] Somewhat working copy. That would use for testing.
June Park <parkjune1995@gmail.com>
parents: 25
diff changeset
334 mkdir -p "$APPDIR/Contents/MacOS"
ccb42d5bf8fd [PostDog] Somewhat working copy. That would use for testing.
June Park <parkjune1995@gmail.com>
parents: 25
diff changeset
335 mkdir -p "$APPDIR/Contents/Resources"
ccb42d5bf8fd [PostDog] Somewhat working copy. That would use for testing.
June Park <parkjune1995@gmail.com>
parents: 25
diff changeset
336
ccb42d5bf8fd [PostDog] Somewhat working copy. That would use for testing.
June Park <parkjune1995@gmail.com>
parents: 25
diff changeset
337 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
338 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
339
ccb42d5bf8fd [PostDog] Somewhat working copy. That would use for testing.
June Park <parkjune1995@gmail.com>
parents: 25
diff changeset
340 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
341 <?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
342 <!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
343 "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
344 <plist version="1.0">
ccb42d5bf8fd [PostDog] Somewhat working copy. That would use for testing.
June Park <parkjune1995@gmail.com>
parents: 25
diff changeset
345 <dict>
ccb42d5bf8fd [PostDog] Somewhat working copy. That would use for testing.
June Park <parkjune1995@gmail.com>
parents: 25
diff changeset
346 <key>CFBundleExecutable</key>
ccb42d5bf8fd [PostDog] Somewhat working copy. That would use for testing.
June Park <parkjune1995@gmail.com>
parents: 25
diff changeset
347 <string>{app_name}</string>
ccb42d5bf8fd [PostDog] Somewhat working copy. That would use for testing.
June Park <parkjune1995@gmail.com>
parents: 25
diff changeset
348 <key>CFBundleIdentifier</key>
ccb42d5bf8fd [PostDog] Somewhat working copy. That would use for testing.
June Park <parkjune1995@gmail.com>
parents: 25
diff changeset
349 <string>{bundle_id}</string>
ccb42d5bf8fd [PostDog] Somewhat working copy. That would use for testing.
June Park <parkjune1995@gmail.com>
parents: 25
diff changeset
350 <key>CFBundleName</key>
ccb42d5bf8fd [PostDog] Somewhat working copy. That would use for testing.
June Park <parkjune1995@gmail.com>
parents: 25
diff changeset
351 <string>{app_name}</string>
ccb42d5bf8fd [PostDog] Somewhat working copy. That would use for testing.
June Park <parkjune1995@gmail.com>
parents: 25
diff changeset
352 <key>CFBundleVersion</key>
ccb42d5bf8fd [PostDog] Somewhat working copy. That would use for testing.
June Park <parkjune1995@gmail.com>
parents: 25
diff changeset
353 <string>1.0</string>
ccb42d5bf8fd [PostDog] Somewhat working copy. That would use for testing.
June Park <parkjune1995@gmail.com>
parents: 25
diff changeset
354 </dict>
ccb42d5bf8fd [PostDog] Somewhat working copy. That would use for testing.
June Park <parkjune1995@gmail.com>
parents: 25
diff changeset
355 </plist>
ccb42d5bf8fd [PostDog] Somewhat working copy. That would use for testing.
June Park <parkjune1995@gmail.com>
parents: 25
diff changeset
356 EOF
ccb42d5bf8fd [PostDog] Somewhat working copy. That would use for testing.
June Park <parkjune1995@gmail.com>
parents: 25
diff changeset
357 """.format(
ccb42d5bf8fd [PostDog] Somewhat working copy. That would use for testing.
June Park <parkjune1995@gmail.com>
parents: 25
diff changeset
358 app_dir = app_dir.path,
ccb42d5bf8fd [PostDog] Somewhat working copy. That would use for testing.
June Park <parkjune1995@gmail.com>
parents: 25
diff changeset
359 binary = binary.path,
ccb42d5bf8fd [PostDog] Somewhat working copy. That would use for testing.
June Park <parkjune1995@gmail.com>
parents: 25
diff changeset
360 app_name = app_name,
ccb42d5bf8fd [PostDog] Somewhat working copy. That would use for testing.
June Park <parkjune1995@gmail.com>
parents: 25
diff changeset
361 bundle_id = bundle_id,
ccb42d5bf8fd [PostDog] Somewhat working copy. That would use for testing.
June Park <parkjune1995@gmail.com>
parents: 25
diff changeset
362 ),
ccb42d5bf8fd [PostDog] Somewhat working copy. That would use for testing.
June Park <parkjune1995@gmail.com>
parents: 25
diff changeset
363 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
364 )
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 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
367
ccb42d5bf8fd [PostDog] Somewhat working copy. That would use for testing.
June Park <parkjune1995@gmail.com>
parents: 25
diff changeset
368 _macos_app = rule(
ccb42d5bf8fd [PostDog] Somewhat working copy. That would use for testing.
June Park <parkjune1995@gmail.com>
parents: 25
diff changeset
369 implementation = _macos_app_impl,
ccb42d5bf8fd [PostDog] Somewhat working copy. That would use for testing.
June Park <parkjune1995@gmail.com>
parents: 25
diff changeset
370 attrs = {
ccb42d5bf8fd [PostDog] Somewhat working copy. That would use for testing.
June Park <parkjune1995@gmail.com>
parents: 25
diff changeset
371 "binary": attr.label(
ccb42d5bf8fd [PostDog] Somewhat working copy. That would use for testing.
June Park <parkjune1995@gmail.com>
parents: 25
diff changeset
372 allow_single_file = True,
ccb42d5bf8fd [PostDog] Somewhat working copy. That would use for testing.
June Park <parkjune1995@gmail.com>
parents: 25
diff changeset
373 mandatory = True,
ccb42d5bf8fd [PostDog] Somewhat working copy. That would use for testing.
June Park <parkjune1995@gmail.com>
parents: 25
diff changeset
374 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
375 ),
ccb42d5bf8fd [PostDog] Somewhat working copy. That would use for testing.
June Park <parkjune1995@gmail.com>
parents: 25
diff changeset
376 "app_name": attr.string(
ccb42d5bf8fd [PostDog] Somewhat working copy. That would use for testing.
June Park <parkjune1995@gmail.com>
parents: 25
diff changeset
377 mandatory = True,
ccb42d5bf8fd [PostDog] Somewhat working copy. That would use for testing.
June Park <parkjune1995@gmail.com>
parents: 25
diff changeset
378 doc = "Name of the application",
ccb42d5bf8fd [PostDog] Somewhat working copy. That would use for testing.
June Park <parkjune1995@gmail.com>
parents: 25
diff changeset
379 ),
ccb42d5bf8fd [PostDog] Somewhat working copy. That would use for testing.
June Park <parkjune1995@gmail.com>
parents: 25
diff changeset
380 "bundle_id": attr.string(
ccb42d5bf8fd [PostDog] Somewhat working copy. That would use for testing.
June Park <parkjune1995@gmail.com>
parents: 25
diff changeset
381 mandatory = True,
ccb42d5bf8fd [PostDog] Somewhat working copy. That would use for testing.
June Park <parkjune1995@gmail.com>
parents: 25
diff changeset
382 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
383 ),
ccb42d5bf8fd [PostDog] Somewhat working copy. That would use for testing.
June Park <parkjune1995@gmail.com>
parents: 25
diff changeset
384 },
ccb42d5bf8fd [PostDog] Somewhat working copy. That would use for testing.
June Park <parkjune1995@gmail.com>
parents: 25
diff changeset
385 )
ccb42d5bf8fd [PostDog] Somewhat working copy. That would use for testing.
June Park <parkjune1995@gmail.com>
parents: 25
diff changeset
386
ccb42d5bf8fd [PostDog] Somewhat working copy. That would use for testing.
June Park <parkjune1995@gmail.com>
parents: 25
diff changeset
387 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
388 """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
389 app_dir = ctx.file.app
ccb42d5bf8fd [PostDog] Somewhat working copy. That would use for testing.
June Park <parkjune1995@gmail.com>
parents: 25
diff changeset
390 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
391
ccb42d5bf8fd [PostDog] Somewhat working copy. That would use for testing.
June Park <parkjune1995@gmail.com>
parents: 25
diff changeset
392 # 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
393 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
394
ccb42d5bf8fd [PostDog] Somewhat working copy. That would use for testing.
June Park <parkjune1995@gmail.com>
parents: 25
diff changeset
395 ctx.actions.run_shell(
ccb42d5bf8fd [PostDog] Somewhat working copy. That would use for testing.
June Park <parkjune1995@gmail.com>
parents: 25
diff changeset
396 inputs = [app_dir],
ccb42d5bf8fd [PostDog] Somewhat working copy. That would use for testing.
June Park <parkjune1995@gmail.com>
parents: 25
diff changeset
397 outputs = [signed_app_dir],
ccb42d5bf8fd [PostDog] Somewhat working copy. That would use for testing.
June Park <parkjune1995@gmail.com>
parents: 25
diff changeset
398 command = """
ccb42d5bf8fd [PostDog] Somewhat working copy. That would use for testing.
June Park <parkjune1995@gmail.com>
parents: 25
diff changeset
399 set -e
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 APPDIR="{app_dir}"
ccb42d5bf8fd [PostDog] Somewhat working copy. That would use for testing.
June Park <parkjune1995@gmail.com>
parents: 25
diff changeset
402 SIGNEDDIR="{signed_dir}"
ccb42d5bf8fd [PostDog] Somewhat working copy. That would use for testing.
June Park <parkjune1995@gmail.com>
parents: 25
diff changeset
403
ccb42d5bf8fd [PostDog] Somewhat working copy. That would use for testing.
June Park <parkjune1995@gmail.com>
parents: 25
diff changeset
404 rm -rf "$SIGNEDDIR"
ccb42d5bf8fd [PostDog] Somewhat working copy. That would use for testing.
June Park <parkjune1995@gmail.com>
parents: 25
diff changeset
405 # 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
406 cp -RL "$APPDIR" "$SIGNEDDIR"
ccb42d5bf8fd [PostDog] Somewhat working copy. That would use for testing.
June Park <parkjune1995@gmail.com>
parents: 25
diff changeset
407
ccb42d5bf8fd [PostDog] Somewhat working copy. That would use for testing.
June Park <parkjune1995@gmail.com>
parents: 25
diff changeset
408 codesign --deep --force --sign - "$SIGNEDDIR"
ccb42d5bf8fd [PostDog] Somewhat working copy. That would use for testing.
June Park <parkjune1995@gmail.com>
parents: 25
diff changeset
409 """.format(
ccb42d5bf8fd [PostDog] Somewhat working copy. That would use for testing.
June Park <parkjune1995@gmail.com>
parents: 25
diff changeset
410 app_dir = app_dir.path,
ccb42d5bf8fd [PostDog] Somewhat working copy. That would use for testing.
June Park <parkjune1995@gmail.com>
parents: 25
diff changeset
411 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
412 ),
ccb42d5bf8fd [PostDog] Somewhat working copy. That would use for testing.
June Park <parkjune1995@gmail.com>
parents: 25
diff changeset
413 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
414 )
ccb42d5bf8fd [PostDog] Somewhat working copy. That would use for testing.
June Park <parkjune1995@gmail.com>
parents: 25
diff changeset
415
ccb42d5bf8fd [PostDog] Somewhat working copy. That would use for testing.
June Park <parkjune1995@gmail.com>
parents: 25
diff changeset
416 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
417
ccb42d5bf8fd [PostDog] Somewhat working copy. That would use for testing.
June Park <parkjune1995@gmail.com>
parents: 25
diff changeset
418 _macos_signed_app = rule(
ccb42d5bf8fd [PostDog] Somewhat working copy. That would use for testing.
June Park <parkjune1995@gmail.com>
parents: 25
diff changeset
419 implementation = _macos_signed_app_impl,
ccb42d5bf8fd [PostDog] Somewhat working copy. That would use for testing.
June Park <parkjune1995@gmail.com>
parents: 25
diff changeset
420 attrs = {
ccb42d5bf8fd [PostDog] Somewhat working copy. That would use for testing.
June Park <parkjune1995@gmail.com>
parents: 25
diff changeset
421 "app": attr.label(
ccb42d5bf8fd [PostDog] Somewhat working copy. That would use for testing.
June Park <parkjune1995@gmail.com>
parents: 25
diff changeset
422 allow_single_file = True,
ccb42d5bf8fd [PostDog] Somewhat working copy. That would use for testing.
June Park <parkjune1995@gmail.com>
parents: 25
diff changeset
423 mandatory = True,
ccb42d5bf8fd [PostDog] Somewhat working copy. That would use for testing.
June Park <parkjune1995@gmail.com>
parents: 25
diff changeset
424 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
425 ),
ccb42d5bf8fd [PostDog] Somewhat working copy. That would use for testing.
June Park <parkjune1995@gmail.com>
parents: 25
diff changeset
426 "app_name": attr.string(
ccb42d5bf8fd [PostDog] Somewhat working copy. That would use for testing.
June Park <parkjune1995@gmail.com>
parents: 25
diff changeset
427 mandatory = True,
ccb42d5bf8fd [PostDog] Somewhat working copy. That would use for testing.
June Park <parkjune1995@gmail.com>
parents: 25
diff changeset
428 doc = "Name of the application",
ccb42d5bf8fd [PostDog] Somewhat working copy. That would use for testing.
June Park <parkjune1995@gmail.com>
parents: 25
diff changeset
429 ),
ccb42d5bf8fd [PostDog] Somewhat working copy. That would use for testing.
June Park <parkjune1995@gmail.com>
parents: 25
diff changeset
430 },
ccb42d5bf8fd [PostDog] Somewhat working copy. That would use for testing.
June Park <parkjune1995@gmail.com>
parents: 25
diff changeset
431 )
ccb42d5bf8fd [PostDog] Somewhat working copy. That would use for testing.
June Park <parkjune1995@gmail.com>
parents: 25
diff changeset
432
ccb42d5bf8fd [PostDog] Somewhat working copy. That would use for testing.
June Park <parkjune1995@gmail.com>
parents: 25
diff changeset
433 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
434 """
ccb42d5bf8fd [PostDog] Somewhat working copy. That would use for testing.
June Park <parkjune1995@gmail.com>
parents: 25
diff changeset
435 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
436
ccb42d5bf8fd [PostDog] Somewhat working copy. That would use for testing.
June Park <parkjune1995@gmail.com>
parents: 25
diff changeset
437 Args:
ccb42d5bf8fd [PostDog] Somewhat working copy. That would use for testing.
June Park <parkjune1995@gmail.com>
parents: 25
diff changeset
438 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
439 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
440 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
441
ccb42d5bf8fd [PostDog] Somewhat working copy. That would use for testing.
June Park <parkjune1995@gmail.com>
parents: 25
diff changeset
442 Generates:
ccb42d5bf8fd [PostDog] Somewhat working copy. That would use for testing.
June Park <parkjune1995@gmail.com>
parents: 25
diff changeset
443 {name}_app: The .app bundle
ccb42d5bf8fd [PostDog] Somewhat working copy. That would use for testing.
June Park <parkjune1995@gmail.com>
parents: 25
diff changeset
444 {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
445 {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
446 """
ccb42d5bf8fd [PostDog] Somewhat working copy. That would use for testing.
June Park <parkjune1995@gmail.com>
parents: 25
diff changeset
447 # 1. Build the .app bundle
ccb42d5bf8fd [PostDog] Somewhat working copy. That would use for testing.
June Park <parkjune1995@gmail.com>
parents: 25
diff changeset
448 _macos_app(
ccb42d5bf8fd [PostDog] Somewhat working copy. That would use for testing.
June Park <parkjune1995@gmail.com>
parents: 25
diff changeset
449 name = name + "_app",
ccb42d5bf8fd [PostDog] Somewhat working copy. That would use for testing.
June Park <parkjune1995@gmail.com>
parents: 25
diff changeset
450 binary = binary,
ccb42d5bf8fd [PostDog] Somewhat working copy. That would use for testing.
June Park <parkjune1995@gmail.com>
parents: 25
diff changeset
451 app_name = name,
ccb42d5bf8fd [PostDog] Somewhat working copy. That would use for testing.
June Park <parkjune1995@gmail.com>
parents: 25
diff changeset
452 bundle_id = bundle_id,
ccb42d5bf8fd [PostDog] Somewhat working copy. That would use for testing.
June Park <parkjune1995@gmail.com>
parents: 25
diff changeset
453 )
ccb42d5bf8fd [PostDog] Somewhat working copy. That would use for testing.
June Park <parkjune1995@gmail.com>
parents: 25
diff changeset
454
ccb42d5bf8fd [PostDog] Somewhat working copy. That would use for testing.
June Park <parkjune1995@gmail.com>
parents: 25
diff changeset
455 # 2. Sign the .app
ccb42d5bf8fd [PostDog] Somewhat working copy. That would use for testing.
June Park <parkjune1995@gmail.com>
parents: 25
diff changeset
456 _macos_signed_app(
ccb42d5bf8fd [PostDog] Somewhat working copy. That would use for testing.
June Park <parkjune1995@gmail.com>
parents: 25
diff changeset
457 name = name + "_signed_app",
ccb42d5bf8fd [PostDog] Somewhat working copy. That would use for testing.
June Park <parkjune1995@gmail.com>
parents: 25
diff changeset
458 app = ":" + name + "_app",
ccb42d5bf8fd [PostDog] Somewhat working copy. That would use for testing.
June Park <parkjune1995@gmail.com>
parents: 25
diff changeset
459 app_name = name,
ccb42d5bf8fd [PostDog] Somewhat working copy. That would use for testing.
June Park <parkjune1995@gmail.com>
parents: 25
diff changeset
460 )
ccb42d5bf8fd [PostDog] Somewhat working copy. That would use for testing.
June Park <parkjune1995@gmail.com>
parents: 25
diff changeset
461
ccb42d5bf8fd [PostDog] Somewhat working copy. That would use for testing.
June Park <parkjune1995@gmail.com>
parents: 25
diff changeset
462 # 3. Create the DMG
ccb42d5bf8fd [PostDog] Somewhat working copy. That would use for testing.
June Park <parkjune1995@gmail.com>
parents: 25
diff changeset
463 native.genrule(
ccb42d5bf8fd [PostDog] Somewhat working copy. That would use for testing.
June Park <parkjune1995@gmail.com>
parents: 25
diff changeset
464 name = name + "_dmg",
ccb42d5bf8fd [PostDog] Somewhat working copy. That would use for testing.
June Park <parkjune1995@gmail.com>
parents: 25
diff changeset
465 srcs = [":" + name + "_signed_app"],
ccb42d5bf8fd [PostDog] Somewhat working copy. That would use for testing.
June Park <parkjune1995@gmail.com>
parents: 25
diff changeset
466 outs = [name + ".dmg"],
ccb42d5bf8fd [PostDog] Somewhat working copy. That would use for testing.
June Park <parkjune1995@gmail.com>
parents: 25
diff changeset
467 cmd = """
ccb42d5bf8fd [PostDog] Somewhat working copy. That would use for testing.
June Park <parkjune1995@gmail.com>
parents: 25
diff changeset
468 set -e
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 SIGNEDDIR="$(location :{name}_signed_app)"
ccb42d5bf8fd [PostDog] Somewhat working copy. That would use for testing.
June Park <parkjune1995@gmail.com>
parents: 25
diff changeset
471
ccb42d5bf8fd [PostDog] Somewhat working copy. That would use for testing.
June Park <parkjune1995@gmail.com>
parents: 25
diff changeset
472 hdiutil create \
ccb42d5bf8fd [PostDog] Somewhat working copy. That would use for testing.
June Park <parkjune1995@gmail.com>
parents: 25
diff changeset
473 -volname {name} \
ccb42d5bf8fd [PostDog] Somewhat working copy. That would use for testing.
June Park <parkjune1995@gmail.com>
parents: 25
diff changeset
474 -srcfolder "$$SIGNEDDIR" \
ccb42d5bf8fd [PostDog] Somewhat working copy. That would use for testing.
June Park <parkjune1995@gmail.com>
parents: 25
diff changeset
475 -ov -format UDZO "$@"
ccb42d5bf8fd [PostDog] Somewhat working copy. That would use for testing.
June Park <parkjune1995@gmail.com>
parents: 25
diff changeset
476 """.format(name = name),
ccb42d5bf8fd [PostDog] Somewhat working copy. That would use for testing.
June Park <parkjune1995@gmail.com>
parents: 25
diff changeset
477 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
478 tags = ["no-sandbox"],
ccb42d5bf8fd [PostDog] Somewhat working copy. That would use for testing.
June Park <parkjune1995@gmail.com>
parents: 25
diff changeset
479 )