Skip to content

Commit

Permalink
CMake: Add a command for codesigning with the get-task-allow entitlement
Browse files Browse the repository at this point in the history
This allows developers on macOS to open Ladybird.app in Instruments.

Add some documentation for how to use the command as well. It is enabled
automatically in CMAKE_BUILD_TYPE=Debug.
  • Loading branch information
ADKaster committed Jun 30, 2024
1 parent b4fa11f commit f74fea5
Show file tree
Hide file tree
Showing 3 changed files with 34 additions and 1 deletion.
16 changes: 15 additions & 1 deletion Documentation/BuildInstructionsLadybird.md
Original file line number Diff line number Diff line change
Expand Up @@ -183,8 +183,22 @@ After running Ladybird as suggested above with `./Meta/ladybird.sh run ladybird`

Now breakpoints, stepping and variable inspection will work.

### Debugging with Xcode on macOS
### Debugging with Xcode or Instruments on macOS

If all you want to do is use Instruments, then an Xcode project is not required.

Simply run the `ladybird.sh` script as normal, and then make sure to codesign the Ladybird binary with the proper entitlements to allow Instruments to attach to it.

```
./Meta/ladybird.sh build
ninja -C build/ladybird apply-debug-entitlements
# or
codesign -s - -v -f --entitlements Meta/debug.plist Build/ladybird/bin/Ladybird.app
```

Now you can open the Instruments app and point it to the Ladybird app bundle.

If you want to use Xcode itself for debugging, you will need to generate an Xcode project.
The `ladybird.sh` build script does not know how to generate Xcode projects, so creating the project must be done manually.

```
Expand Down
11 changes: 11 additions & 0 deletions Ladybird/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,17 @@ function(create_ladybird_bundle target_name)
add_custom_command(TARGET ${target_name} POST_BUILD
COMMAND "${CMAKE_COMMAND}" -E create_symlink "${CMAKE_LIBRARY_OUTPUT_DIRECTORY}" "${bundle_dir}/Contents/lib"
)

if (CMAKE_BUILD_TYPE STREQUAL "Debug")
add_custom_command(TARGET ${target_name} POST_BUILD
COMMAND codesign -s - -v -f --entitlements "${LADYBIRD_SOURCE_DIR}/Meta/debug.plist" "${bundle_dir}"
)
else()
add_custom_target(apply-debug-entitlements
COMMAND codesign -s - -v -f --entitlements "${LADYBIRD_SOURCE_DIR}/Meta/debug.plist" "${bundle_dir}"
USES_TERMINAL
)
endif()
endif()

if (APPLE)
Expand Down
8 changes: 8 additions & 0 deletions Meta/debug.plist
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
<key>com.apple.security.get-task-allow</key>
<true/>
</dict>
</plist>

0 comments on commit f74fea5

Please sign in to comment.