Repository navigation
feat(unicode): migrate grapheme breaking to uucode with GB9c support #26376
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change | ||||||||||||||||||||||||||||||||||||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
| @@ -0,0 +1,82 @@ | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| #!/bin/bash | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| # Updates the vendored uucode library and regenerates grapheme tables. | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| # | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| # Usage: | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| # ./scripts/update-uucode.sh # update from default URL | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| # ./scripts/update-uucode.sh /path/to/uucode # update from local directory | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| # ./scripts/update-uucode.sh https://url.tar.gz # update from URL | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| # | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| # After running, verify with: | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| # bun bd test test/js/bun/util/stringWidth.test.ts | ||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||
| set -euo pipefail | ||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||
| SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)" | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| BUN_ROOT="$(cd "$SCRIPT_DIR/.." && pwd)" | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| UUCODE_DIR="$BUN_ROOT/src/deps/uucode" | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| ZIG="$BUN_ROOT/vendor/zig/zig" | ||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||
| if [ ! -x "$ZIG" ]; then | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| echo "error: zig not found at $ZIG" | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| echo " run scripts/bootstrap.sh first" | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| exit 1 | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| fi | ||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||
| update_from_dir() { | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| local src="$1" | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| echo "Updating uucode from: $src" | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| rm -rf "$UUCODE_DIR" | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| mkdir -p "$UUCODE_DIR" | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| cp -r "$src"/* "$UUCODE_DIR/" | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||
| update_from_url() { | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| local url="$1" | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| local tmp | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| tmp=$(mktemp -d) | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| trap "rm -rf $tmp" EXIT | ||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||
| echo "Downloading uucode from: $url" | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| curl -fsSL "$url" | tar -xz -C "$tmp" --strip-components=1 | ||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||
| update_from_dir "$tmp" | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||
| # Handle source argument | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| if [ $# -ge 1 ]; then | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| SOURCE="$1" | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| if [ -d "$SOURCE" ]; then | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| update_from_dir "$SOURCE" | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| elif [[ "$SOURCE" == http* ]]; then | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| update_from_url "$SOURCE" | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| else | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| echo "error: argument must be a directory or URL" | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| exit 1 | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| fi | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| else | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| # Default: use the zig global cache if available | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| CACHED=$(find "$HOME/.cache/zig/p" -maxdepth 1 -name "uucode-*" -type d 2>/dev/null | sort -V | tail -1) | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| if [ -n "$CACHED" ]; then | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| update_from_dir "$CACHED" | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| else | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| echo "error: no uucode source specified and none found in zig cache" | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| echo "" | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| echo "usage: $0 <path-to-uucode-dir-or-url>" | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| exit 1 | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| fi | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| fi | ||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Comment on lines
+56
to
+67
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 🧹 Nitpick | 🔵 Trivial Consider cross-platform Zig cache location. The default cache path ♻️ Suggested fix for cross-platform support else
# Default: use the zig global cache if available
- CACHED=$(find "$HOME/.cache/zig/p" -maxdepth 1 -name "uucode-*" -type d 2>/dev/null | sort -V | tail -1)
+ # Try Linux cache first, then macOS
+ CACHED=$(find "$HOME/.cache/zig/p" "$HOME/Library/Caches/zig/p" -maxdepth 1 -name "uucode-*" -type d 2>/dev/null | sort -V | tail -1)
if [ -n "$CACHED" ]; then
update_from_dir "$CACHED"
else📝 Committable suggestion
Suggested change
🤖 Prompt for AI Agents |
||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||
| echo "" | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| echo "Regenerating grapheme tables..." | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| cd "$BUN_ROOT" | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| "$ZIG" build generate-grapheme-tables | ||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||
| echo "" | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| echo "Done. Updated files:" | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| echo " src/deps/uucode/ (vendored library)" | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| echo " src/string/immutable/grapheme_tables.zig (regenerated)" | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| echo "" | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| echo "Next steps:" | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| echo " 1. bun bd test test/js/bun/util/stringWidth.test.ts" | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| echo " 2. git add src/deps/uucode src/string/immutable/grapheme_tables.zig" | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| echo " 3. git commit -m 'Update uucode to <version>'" | ||||||||||||||||||||||||||||||||||||||||||||||||||||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,30 @@ | ||
| # uucode license | ||
|
|
||
| MIT License | ||
|
|
||
| Copyright (c) 2025 Jacob Sandlund | ||
|
|
||
| Permission is hereby granted, free of charge, to any person obtaining a copy of | ||
| this software and associated documentation files (the "Software"), to deal in | ||
| the Software without restriction, including without limitation the rights to | ||
| use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies | ||
| of the Software, and to permit persons to whom the Software is furnished to do | ||
| so, subject to the following conditions: | ||
|
|
||
| The above copyright notice and this permission notice shall be included in all | ||
| copies or substantial portions of the Software. | ||
|
|
||
| THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR | ||
| IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, | ||
| FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE | ||
| AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER | ||
| LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, | ||
| OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE | ||
| SOFTWARE. | ||
|
|
||
| ## Other licenses | ||
|
|
||
| See [./licenses](./licenses) for licenses of code being used in the repo: | ||
|
|
||
| - [LICENSE_Bjoern_Hoehrmann](./licenses/LICENSE_Bjoern_Hoehrmann) | ||
| - [LICENSE_unicode](./licenses/LICENSE_unicode) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
🧹 Nitpick | 🔵 Trivial
Fix trap to use single quotes per shellcheck recommendation.
The trap on line 37 expands
$tmpimmediately. While this works correctly here since$tmpis set just before, using single quotes is the recommended practice to avoid subtle bugs if the code is refactored.♻️ Suggested fix
update_from_url() { local url="$1" local tmp tmp=$(mktemp -d) - trap "rm -rf $tmp" EXIT + trap 'rm -rf "$tmp"' EXIT echo "Downloading uucode from: $url" curl -fsSL "$url" | tar -xz -C "$tmp" --strip-components=1📝 Committable suggestion
🧰 Tools
🪛 Shellcheck (0.11.0)
[warning] 37-37: Use single quotes, otherwise this expands now rather than when signalled.
(SC2064)
🤖 Prompt for AI Agents