@@ -25,10 +25,8 @@ func init() {
2525 mainCommand .AddCommand (commandBuild )
2626}
2727
28- // formatTargetLog returns a human-readable log string for a target
2928func formatTargetLog (t Target ) string {
3029 if t .Platform != "" {
31- // Apple platform with Platform/Environment
3230 platformName := "iOS"
3331 if t .Platform == "tvos" {
3432 platformName = "tvOS"
@@ -44,10 +42,8 @@ func formatTargetLog(t Target) string {
4442 return fmt .Sprintf ("%s/%s" , t .GOOS , t .ARCH )
4543}
4644
47- // getOutputDirectory returns the GN output directory for a target
4845func getOutputDirectory (t Target ) string {
4946 if t .Platform != "" {
50- // Apple platform: out/cronet-{platform}-{cpu}[-simulator]
5147 directory := fmt .Sprintf ("out/cronet-%s-%s" , t .Platform , t .CPU )
5248 if t .Environment == "simulator" {
5349 directory += "-simulator"
@@ -68,7 +64,6 @@ func build(targets []Target) {
6864 log .Print ("Build complete!" )
6965}
7066
71- // getExtraFlags returns the EXTRA_FLAGS for a target
7267func getExtraFlags (t Target ) string {
7368 flags := []string {
7469 fmt .Sprintf (`target_os="%s"` , t .OS ),
@@ -77,7 +72,6 @@ func getExtraFlags(t Target) string {
7772 return strings .Join (flags , " " )
7873}
7974
80- // OpenWrt SDK configuration for each architecture
8175type openwrtConfig struct {
8276 target string // OpenWrt target (e.g., "x86", "armsr")
8377 subtarget string // OpenWrt subtarget (e.g., "64", "generic")
@@ -86,10 +80,8 @@ type openwrtConfig struct {
8680 gccVer string // GCC version in SDK
8781}
8882
89- // getOpenwrtConfig returns the OpenWrt SDK configuration for a target
9083func getOpenwrtConfig (t Target ) openwrtConfig {
9184 // Use OpenWrt 23.05.5 as it's stable and widely available
92- // GCC version varies by release
9385 switch t .CPU {
9486 case "x64" :
9587 return openwrtConfig {
@@ -129,7 +121,6 @@ func getOpenwrtConfig(t Target) openwrtConfig {
129121 }
130122}
131123
132- // getOpenwrtFlags returns the OPENWRT_FLAGS environment variable value
133124func getOpenwrtFlags (t Target ) string {
134125 config := getOpenwrtConfig (t )
135126 return fmt .Sprintf (
@@ -138,7 +129,6 @@ func getOpenwrtFlags(t Target) string {
138129 )
139130}
140131
141- // runGetClang runs naiveproxy's get-clang.sh with appropriate EXTRA_FLAGS
142132func runGetClang (t Target ) {
143133 // For cross-compilation on Linux, we need to also build host sysroot first
144134 // because GN needs host sysroot in addition to target sysroot.
@@ -147,7 +137,6 @@ func runGetClang(t Target) {
147137 hostCPU := hostToCPU (runtime .GOARCH )
148138 needsHostSysroot := hostOS == "linux" && (t .OS == "linux" || t .OS == "android" || t .OS == "openwrt" )
149139 if needsHostSysroot {
150- // Run get-clang.sh with host target to ensure host sysroot is downloaded
151140 hostFlags := fmt .Sprintf (`target_os="linux" target_cpu="%s"` , hostCPU )
152141 log .Printf ("Running get-clang.sh for host sysroot with EXTRA_FLAGS=%s" , hostFlags )
153142 command := exec .Command ("bash" , "./get-clang.sh" )
@@ -160,7 +149,6 @@ func runGetClang(t Target) {
160149 log .Fatalf ("get-clang.sh (host) failed: %v" , err )
161150 }
162151
163- // Create symlink for host sysroot so GN can find it at the default location
164152 hostSysrootSource := filepath .Join (srcRoot , "out/sysroot-build/bullseye/bullseye_amd64_staging" )
165153 hostSysrootDestination := filepath .Join (srcRoot , "build/linux/debian_bullseye_amd64-sysroot" )
166154 if _ , err := os .Stat (hostSysrootDestination ); os .IsNotExist (err ) {
@@ -175,7 +163,6 @@ func runGetClang(t Target) {
175163 extraFlags := getExtraFlags (t )
176164 env := []string {"EXTRA_FLAGS=" + extraFlags }
177165
178- // For openwrt (musl), also set OPENWRT_FLAGS
179166 if t .OS == "openwrt" {
180167 openwrtFlags := getOpenwrtFlags (t )
181168 env = append (env , "OPENWRT_FLAGS=" + openwrtFlags )
@@ -196,12 +183,10 @@ func runGetClang(t Target) {
196183}
197184
198185func buildTarget (t Target ) {
199- // Run get-clang.sh to ensure toolchain is available
200186 runGetClang (t )
201187
202188 outputDirectory := getOutputDirectory (t )
203189
204- // Prepare GN args
205190 args := []string {
206191 "is_official_build=true" ,
207192 "is_debug=false" ,
@@ -239,7 +224,6 @@ func buildTarget(t Target) {
239224 fmt .Sprintf ("target_cpu=\" %s\" " , t .CPU ),
240225 }
241226
242- // Platform-specific args
243227 switch t .OS {
244228 case "mac" :
245229 args = append (args , "use_sysroot=false" )
@@ -257,7 +241,6 @@ func buildTarget(t Target) {
257241 args = append (args , "use_cfi_icall=false" , "is_cfi=false" )
258242 }
259243 case "openwrt" :
260- // OpenWrt uses musl libc
261244 config := getOpenwrtConfig (t )
262245 sysrootDirectory := fmt .Sprintf ("out/sysroot-build/openwrt/%s/%s" , config .release , config .arch )
263246 args = append (args ,
@@ -295,7 +278,6 @@ func buildTarget(t Target) {
295278 )
296279 }
297280
298- // Detect and use ccache/sccache
299281 if runtime .GOOS == "windows" {
300282 sccachePath , _ := exec .LookPath ("sccache" )
301283 if sccachePath != "" {
@@ -310,13 +292,11 @@ func buildTarget(t Target) {
310292
311293 gnArgs := strings .Join (args , " " )
312294
313- // Determine GN path
314295 gnPath := filepath .Join (srcRoot , "gn" , "out" , "gn" )
315296 if runtime .GOOS == "windows" {
316297 gnPath += ".exe"
317298 }
318299
319- // Run gn gen
320300 log .Printf ("Running: gn gen %s" , outputDirectory )
321301 gnCommand := exec .Command (gnPath , "gen" , outputDirectory , "--args=" + gnArgs )
322302 gnCommand .Dir = srcRoot
@@ -331,7 +311,6 @@ func buildTarget(t Target) {
331311 log .Fatalf ("gn gen failed: %v" , err )
332312 }
333313
334- // Run ninja
335314 if t .GOOS == "windows" {
336315 // Windows: only build DLL (static linking not supported - Chromium uses MSVC, Go CGO only supports MinGW)
337316 log .Printf ("Running: ninja -C %s cronet" , outputDirectory )
0 commit comments