Mercurial
comparison gui_ze/gui_ze.bzl @ 60:d64a8c189a77
Merged
| author | June Park <me@mrjunejune.com> |
|---|---|
| date | Sat, 20 Dec 2025 13:56:01 -0500 |
| parents | ccb42d5bf8fd |
| children | a30944e5719e |
comparison
equal
deleted
inserted
replaced
| 50:983769fba767 | 60:d64a8c189a77 |
|---|---|
| 7 return [DefaultInfo(files = depset([out]))] | 7 return [DefaultInfo(files = depset([out]))] |
| 8 | 8 |
| 9 foo_binary = rule( | 9 foo_binary = rule( |
| 10 implementation = _foo_impl, | 10 implementation = _foo_impl, |
| 11 ) | 11 ) |
| 12 | |
| 13 | 12 |
| 14 def _bundle_impl(ctx): | 13 def _bundle_impl(ctx): |
| 15 """ | 14 """ |
| 16 bundle binary target into a folder which can later be used to make a post to github easily. | 15 bundle binary target into a folder which can later be used to make a post to github easily. |
| 17 """ | 16 """ |
| 181 attrs = { | 180 attrs = { |
| 182 "data": attr.label_list(allow_files=True), | 181 "data": attr.label_list(allow_files=True), |
| 183 "dest": attr.string(), | 182 "dest": attr.string(), |
| 184 }, | 183 }, |
| 185 ) | 184 ) |
| 185 | |
| 186 | |
| 187 def _macos_app_impl(ctx): | |
| 188 """Implementation for creating a macOS .app bundle from a binary.""" | |
| 189 binary = ctx.file.binary | |
| 190 app_name = ctx.attr.app_name | |
| 191 bundle_id = ctx.attr.bundle_id | |
| 192 | |
| 193 # Declare the .app directory as output | |
| 194 app_dir = ctx.actions.declare_directory(app_name + ".app") | |
| 195 | |
| 196 ctx.actions.run_shell( | |
| 197 inputs = [binary], | |
| 198 outputs = [app_dir], | |
| 199 command = """ | |
| 200 set -e | |
| 201 | |
| 202 APPDIR="{app_dir}" | |
| 203 | |
| 204 rm -rf "$APPDIR" | |
| 205 mkdir -p "$APPDIR/Contents/MacOS" | |
| 206 mkdir -p "$APPDIR/Contents/Resources" | |
| 207 | |
| 208 cp {binary} "$APPDIR/Contents/MacOS/{app_name}" | |
| 209 chmod +x "$APPDIR/Contents/MacOS/{app_name}" | |
| 210 | |
| 211 cat > "$APPDIR/Contents/Info.plist" <<EOF | |
| 212 <?xml version="1.0" encoding="UTF-8"?> | |
| 213 <!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" | |
| 214 "http://www.apple.com/DTDs/PropertyList-1.0.dtd"> | |
| 215 <plist version="1.0"> | |
| 216 <dict> | |
| 217 <key>CFBundleExecutable</key> | |
| 218 <string>{app_name}</string> | |
| 219 <key>CFBundleIdentifier</key> | |
| 220 <string>{bundle_id}</string> | |
| 221 <key>CFBundleName</key> | |
| 222 <string>{app_name}</string> | |
| 223 <key>CFBundleVersion</key> | |
| 224 <string>1.0</string> | |
| 225 </dict> | |
| 226 </plist> | |
| 227 EOF | |
| 228 """.format( | |
| 229 app_dir = app_dir.path, | |
| 230 binary = binary.path, | |
| 231 app_name = app_name, | |
| 232 bundle_id = bundle_id, | |
| 233 ), | |
| 234 progress_message = "Creating macOS app bundle for {}".format(app_name), | |
| 235 ) | |
| 236 | |
| 237 return [DefaultInfo(files = depset([app_dir]))] | |
| 238 | |
| 239 _macos_app = rule( | |
| 240 implementation = _macos_app_impl, | |
| 241 attrs = { | |
| 242 "binary": attr.label( | |
| 243 allow_single_file = True, | |
| 244 mandatory = True, | |
| 245 doc = "The binary to bundle into a .app", | |
| 246 ), | |
| 247 "app_name": attr.string( | |
| 248 mandatory = True, | |
| 249 doc = "Name of the application", | |
| 250 ), | |
| 251 "bundle_id": attr.string( | |
| 252 mandatory = True, | |
| 253 doc = "Bundle identifier (e.g., com.example.app)", | |
| 254 ), | |
| 255 }, | |
| 256 ) | |
| 257 | |
| 258 def _macos_signed_app_impl(ctx): | |
| 259 """Implementation for signing a macOS .app bundle.""" | |
| 260 app_dir = ctx.file.app | |
| 261 app_name = ctx.attr.app_name | |
| 262 | |
| 263 # Declare the signed .app directory as output | |
| 264 signed_app_dir = ctx.actions.declare_directory(app_name + "_signed.app") | |
| 265 | |
| 266 ctx.actions.run_shell( | |
| 267 inputs = [app_dir], | |
| 268 outputs = [signed_app_dir], | |
| 269 command = """ | |
| 270 set -e | |
| 271 | |
| 272 APPDIR="{app_dir}" | |
| 273 SIGNEDDIR="{signed_dir}" | |
| 274 | |
| 275 rm -rf "$SIGNEDDIR" | |
| 276 # Use -L to dereference symlinks, as codesign doesn't work with symlinks | |
| 277 cp -RL "$APPDIR" "$SIGNEDDIR" | |
| 278 | |
| 279 codesign --deep --force --sign - "$SIGNEDDIR" | |
| 280 """.format( | |
| 281 app_dir = app_dir.path, | |
| 282 signed_dir = signed_app_dir.path, | |
| 283 ), | |
| 284 progress_message = "Signing macOS app bundle {}".format(app_name), | |
| 285 ) | |
| 286 | |
| 287 return [DefaultInfo(files = depset([signed_app_dir]))] | |
| 288 | |
| 289 _macos_signed_app = rule( | |
| 290 implementation = _macos_signed_app_impl, | |
| 291 attrs = { | |
| 292 "app": attr.label( | |
| 293 allow_single_file = True, | |
| 294 mandatory = True, | |
| 295 doc = "The .app directory to sign", | |
| 296 ), | |
| 297 "app_name": attr.string( | |
| 298 mandatory = True, | |
| 299 doc = "Name of the application", | |
| 300 ), | |
| 301 }, | |
| 302 ) | |
| 303 | |
| 304 def macos_app_and_dmg(name, binary, bundle_id = "com.example.app"): | |
| 305 """ | |
| 306 Creates a macOS .app bundle, signs it, and packages it into a DMG. | |
| 307 | |
| 308 Args: | |
| 309 name: Base name for the generated targets | |
| 310 binary: Label of the binary target to bundle | |
| 311 bundle_id: Bundle identifier for the app (default: com.example.app) | |
| 312 | |
| 313 Generates: | |
| 314 {name}_app: The .app bundle | |
| 315 {name}_signed_app: The signed .app bundle | |
| 316 {name}_dmg: The final DMG file | |
| 317 """ | |
| 318 # 1. Build the .app bundle | |
| 319 _macos_app( | |
| 320 name = name + "_app", | |
| 321 binary = binary, | |
| 322 app_name = name, | |
| 323 bundle_id = bundle_id, | |
| 324 ) | |
| 325 | |
| 326 # 2. Sign the .app | |
| 327 _macos_signed_app( | |
| 328 name = name + "_signed_app", | |
| 329 app = ":" + name + "_app", | |
| 330 app_name = name, | |
| 331 ) | |
| 332 | |
| 333 # 3. Create the DMG | |
| 334 native.genrule( | |
| 335 name = name + "_dmg", | |
| 336 srcs = [":" + name + "_signed_app"], | |
| 337 outs = [name + ".dmg"], | |
| 338 cmd = """ | |
| 339 set -e | |
| 340 | |
| 341 SIGNEDDIR="$(location :{name}_signed_app)" | |
| 342 | |
| 343 hdiutil create \ | |
| 344 -volname {name} \ | |
| 345 -srcfolder "$$SIGNEDDIR" \ | |
| 346 -ov -format UDZO "$@" | |
| 347 """.format(name = name), | |
| 348 local = 1, # Disable sandboxing for hdiutil | |
| 349 tags = ["no-sandbox"], | |
| 350 ) |