Home
About
Blog
Products
Forum
Support
Contact
Sunbelt Computer Software
PL/B Language Development and Support
Home
About
Blog
Products
Forum
Support
Contact
bun/scripts/pack-codegen-for-zig-team.ts at main · wrongnull/bun · GitHub
Skip to content
Navigation Menu
Sign in
Appearance settings
Platform
AI CODE CREATION
GitHub Copilot
Write better code with AI
GitHub Copilot app
Direct agents from issue to merge
MCP Registry
Integrate external tools
DEVELOPER WORKFLOWS
Actions
Automate any workflow
Codespaces
Instant dev environments
Issues
Plan and track work
Code Review
Manage code changes
Code Quality
Enforce quality at merge
APPLICATION SECURITY
GitHub Advanced Security
Find and fix vulnerabilities
Code security
Secure your code as you build
Secret protection
Stop leaks before they start
EXPLORE
Why GitHub
Documentation
Blog
Changelog
Marketplace
View all features
Solutions
BY COMPANY SIZE
Enterprises
Small and medium teams
Startups
Nonprofits
BY USE CASE
App Modernization
DevSecOps
DevOps
CI/CD
View all use cases
BY INDUSTRY
Healthcare
Financial services
Manufacturing
Government
View all industries
View all solutions
Resources
EXPLORE BY TOPIC
AI
Software Development
DevOps
Security
View all topics
EXPLORE BY TYPE
Customer stories
Events & webinars
Ebooks & reports
Business insights
GitHub Skills
SUPPORT & SERVICES
Documentation
Customer support
Community forum
Trust center
Partners
View all resources
Open Source
COMMUNITY
GitHub Sponsors
Fund open source developers
PROGRAMS
Security Lab
Maintainer Community
GitHub Stars
Archive Program
REPOSITORIES
Topics
Trending
Collections
Enterprise
ENTERPRISE SOLUTIONS
Enterprise platform
AI-powered developer platform
AVAILABLE ADD-ONS
GitHub Advanced Security
Enterprise-grade security features
Copilot for Business
Enterprise-grade AI features
Premium Support
Enterprise-grade 24/7 support
Pricing
Search
/
Sign in
Sign up
Appearance settings
You signed in with another tab or window.
Reload
to refresh your session.
You signed out in another tab or window.
Reload
to refresh your session.
You switched accounts on another tab or window.
Reload
to refresh your session.
Dismiss alert
{{ message }}
wrongnull
/
bun
Public
forked from
oven-sh/bun
Notifications
You must be signed in to change notification settings
Fork
0
Star
0
Code
Pull requests
9
Actions
Projects
Security and quality
0
Insights
Additional navigation options
Code
Pull requests
Actions
Projects
Security and quality
Insights
Files
Expand file tree
main
Breadcrumbs
bun
/
scripts
/
pack-codegen-for-zig-team.ts
Copy path
Blame
More file actions
Blame
More file actions
Latest commit
History
History
History
167 lines (149 loc) · 4.49 KB
main
Breadcrumbs
bun
/
scripts
/
pack-codegen-for-zig-team.ts
Copy path
Top
File metadata and controls
Code
Blame
167 lines (149 loc) · 4.49 KB
Raw
Copy raw file
Download raw file
Open symbols panel
Edit and raw actions
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
import
{
$
}
from
"bun"
;
import
{
dirname
,
join
,
relative
}
from
"path"
;
// Check for local changes in git before proceeding
const
statusOutput
=
await
$
`git status --porcelain --untracked-files=normal`
.
text
(
)
;
if
(
statusOutput
.
trim
(
)
.
length
>
0
)
{
console
.
error
(
"There are local changes in git. Please commit or stash them before running this command."
)
;
console
.
error
(
"Git status:"
)
;
console
.
error
(
statusOutput
)
;
process
.
exit
(
1
)
;
}
async
function
revertUnstagedChanges
(
)
{
// Discard ONLY worktree changes; keep index (staged) intact.
// Prefer `git restore` (Git ≥2.23), fall back to `git checkout` for older Git.
try
{
const
restore
=
Bun
.
spawn
(
{
cmd
:
[
"git"
,
"restore"
,
"--worktree"
,
"--"
,
"."
]
,
stdio
:
[
"ignore"
,
"ignore"
,
"inherit"
]
,
}
)
;
await
restore
.
exited
;
if
(
restore
.
exitCode
!==
0
)
{
const
checkout
=
Bun
.
spawn
(
{
cmd
:
[
"git"
,
"checkout"
,
"--"
,
"."
]
,
stdio
:
[
"ignore"
,
"ignore"
,
"inherit"
]
,
}
)
;
await
checkout
.
exited
;
}
}
catch
{
// Best-effort; ignore restore errors so the main task can still complete.
}
}
let
skip
=
-
1
;
const
args
=
process
.
argv
.
slice
(
2
)
.
filter
(
(
arg
,
i
)
=>
{
if
(
arg
===
"--listen=-"
)
return
false
;
if
(
arg
===
"--zig-lib-dir"
)
{
skip
=
i
+
1
;
return
false
;
}
if
(
skip
===
i
)
return
false
;
return
true
;
}
)
;
if
(
args
.
length
===
0
)
{
console
.
error
(
`Usage: bun scripts/pack-codegen-for-zig-team <full crashing zig command>
The full command should be displayed in the build failure message. It should start with /path/to/zig build-obj ..... and end with --listen=-`
)
;
process
.
exit
(
1
)
;
}
if
(
!
args
[
0
]
.
includes
(
"zig"
)
)
{
console
.
error
(
"First argument must be a zig command: "
,
args
[
0
]
)
;
process
.
exit
(
1
)
;
}
if
(
args
[
1
]
===
"build"
)
{
console
.
error
(
"build not supported. Expected a `zig build-obj` command."
)
;
process
.
exit
(
1
)
;
}
args
.
shift
(
)
;
let
resolvedZigFiles
=
new
Set
<
string
>
(
)
;
const
backmap
=
new
Map
<
string
,
string
>
(
)
;
for
(
const
arg
of
args
)
{
const
[
_
,
file
]
=
arg
.
split
(
"="
)
;
if
(
!
file
)
continue
;
if
(
!
file
.
includes
(
"/"
)
)
continue
;
const
resolved
=
relative
(
"."
,
file
)
;
if
(
resolved
.
startsWith
(
".."
)
)
{
console
.
error
(
"File is outside of the current directory: "
,
file
)
;
process
.
exit
(
1
)
;
}
resolvedZigFiles
.
add
(
resolved
)
;
backmap
.
set
(
file
,
resolved
)
;
}
for
(
const
file
of
resolvedZigFiles
)
{
let
content
:
string
;
try
{
content
=
await
Bun
.
file
(
file
)
.
text
(
)
;
}
catch
(
e
)
{
console
.
error
(
"Failed to read file: "
,
file
)
;
resolvedZigFiles
.
delete
(
file
)
;
continue
;
}
if
(
!
file
.
endsWith
(
".zig"
)
)
continue
;
const
imports
=
content
.
matchAll
(
/
@
(?:
i
m
p
o
r
t
|
e
m
b
e
d
F
i
l
e
)
\(
"
(
[
^
"
]
+
)
"
\)
/
g
)
;
for
(
const
[
_
,
imported
]
of
imports
)
{
if
(
!
imported
.
includes
(
"/"
)
&&
!
imported
.
includes
(
"."
)
)
continue
;
const
resolved
=
join
(
dirname
(
file
)
,
imported
)
;
resolvedZigFiles
.
add
(
resolved
)
;
}
}
// now, create zip
const
out_args
=
"build/all.args"
;
const
out
=
"codegen-for-zig-team.tar.gz"
;
try
{
await
Bun
.
file
(
out
)
.
delete
(
)
;
}
catch
(
e
)
{
}
const
a0
=
args
.
shift
(
)
;
await
Bun
.
write
(
out_args
,
args
.
filter
(
arg
=>
{
if
(
arg
===
"-fsanitize-address"
)
return
false
;
// not available upstream
return
true
;
}
)
.
map
(
arg
=>
{
if
(
arg
.
includes
(
"="
)
)
{
const
[
flag
,
value
]
=
arg
.
split
(
"="
)
;
return
`
${
flag
}
=
${
backmap
.
get
(
value
)
??
value
}
`
;
}
return
arg
;
}
)
.
join
(
" "
)
,
)
;
// Prepare zig source for use with the upstream compiler
{
const
fmt
=
Bun
.
spawn
(
{
cmd
:
[
"./vendor/zig/zig"
,
"fmt"
,
"--upstream"
,
"src"
]
,
stdio
:
[
"inherit"
,
"inherit"
,
"inherit"
]
,
}
)
;
await
fmt
.
exited
;
if
(
fmt
.
exitCode
!==
0
)
{
await
revertUnstagedChanges
(
)
;
console
.
error
(
"`zig fmt` failed."
)
;
process
.
exit
(
fmt
.
exitCode
??
1
)
;
}
}
try
{
const
spawned
=
Bun
.
spawn
(
{
cmd
:
[
"tar"
,
"--no-xattrs"
,
"-zcf"
,
out
,
out_args
,
...
resolvedZigFiles
]
,
stdio
:
[
"inherit"
,
"inherit"
,
"inherit"
]
,
}
)
;
await
spawned
.
exited
;
if
(
spawned
.
exitCode
!==
0
)
{
console
.
error
(
"Failed to create zip: "
,
spawned
.
exitCode
)
;
process
.
exit
(
1
)
;
}
console
.
log
(
`
pack-codegen-for-zig-team
Reminder: Test that the reproduction steps work with the official Zig binary before submitting the issue.
Output file:
${
out
}
Reproduction steps:
Download codegen-for-zig-team.tar.gz
\`\`\`sh
cd /empty/folder
wget ....
tar -xvzf codegen-for-zig-team.tar.gz
zig
${
a0
}
@
${
out_args
}
\`\`\`
`
)
;
console
.
log
(
"->"
,
out
)
;
}
finally
{
// Always clean up any fmt-induced worktree changes (preserve index)
await
revertUnstagedChanges
(
)
;
}
You can’t perform that action at this time.