Skip to content

Commit 87fa065

Browse files
committed
Add build for linux shared library
1 parent 491f68e commit 87fa065

File tree

6 files changed

+120
-2
lines changed

6 files changed

+120
-2
lines changed

.github/workflows/naive-build.yml

Lines changed: 72 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,10 @@ on:
77
description: 'Publish to go-release branch'
88
type: boolean
99
default: false
10+
version:
11+
description: 'Release version (e.g., v1.0.0). Creates GitHub Release draft when provided.'
12+
type: string
13+
required: false
1014
push:
1115
branches: [main]
1216

@@ -112,6 +116,20 @@ jobs:
112116
export QEMU_LD_PREFIX=$PWD/naiveproxy/src/out/sysroot-build/bullseye/bullseye_${{ matrix.sysroot_arch }}_staging
113117
fi
114118
./cronet.test -test.v -test.run=TestEngineVersion
119+
- name: Build purego test binary
120+
run: |
121+
cp lib/linux_${{ matrix.arch }}/libcronet.so .
122+
CGO_ENABLED=0 \
123+
GOOS=linux \
124+
GOARCH=${{ matrix.arch }} \
125+
go test -tags with_purego -c -o cronet.purego.test .
126+
- name: Run purego test binary
127+
run: |
128+
if [ "${{ matrix.arch }}" != "amd64" ] && [ "${{ matrix.arch }}" != "386" ]; then
129+
export QEMU_LD_PREFIX=$PWD/naiveproxy/src/out/sysroot-build/bullseye/bullseye_${{ matrix.sysroot_arch }}_staging
130+
fi
131+
export LD_LIBRARY_PATH=$PWD
132+
./cronet.purego.test -test.v -test.run=TestEngineVersion
115133
- uses: actions/upload-artifact@v4
116134
with:
117135
name: cronet-linux-${{ matrix.arch }}
@@ -488,3 +506,57 @@ jobs:
488506
else
489507
go run ./cmd/build-naive publish --branch go
490508
fi
509+
510+
release:
511+
needs: [linux, publish]
512+
if: github.event_name == 'workflow_dispatch' && github.event.inputs.version != ''
513+
runs-on: ubuntu-22.04
514+
steps:
515+
- uses: actions/checkout@v4
516+
517+
- name: Download Linux artifacts
518+
uses: actions/download-artifact@v4
519+
with:
520+
pattern: cronet-linux-*
521+
path: artifacts/
522+
merge-multiple: false
523+
524+
- name: Get Chromium version
525+
id: chromium
526+
run: |
527+
VERSION=$(grep -h 'const Version' artifacts/cronet-linux-amd64/lib/linux_amd64/libcronet_cgo.go | sed 's/.*"\(.*\)".*/\1/')
528+
echo "version=$VERSION" >> $GITHUB_OUTPUT
529+
530+
- name: Prepare release assets
531+
run: |
532+
mkdir -p release
533+
for dir in artifacts/cronet-linux-*/lib/linux_*; do
534+
if [[ "$dir" != *_musl ]]; then
535+
ARCH=$(basename "$dir" | sed 's/linux_//')
536+
if [ -f "$dir/libcronet.so" ]; then
537+
cp "$dir/libcronet.so" "release/libcronet-linux-${ARCH}.so"
538+
fi
539+
fi
540+
done
541+
ls -la release/
542+
543+
- name: Create or update release draft
544+
env:
545+
GH_TOKEN: ${{ github.token }}
546+
run: |
547+
VERSION="${{ github.event.inputs.version }}"
548+
CHROMIUM_VERSION="${{ steps.chromium.outputs.version }}"
549+
550+
# Check if release exists
551+
if gh release view "$VERSION" &>/dev/null; then
552+
echo "Release $VERSION exists, uploading assets..."
553+
else
554+
echo "Creating release draft $VERSION..."
555+
gh release create "$VERSION" \
556+
--draft \
557+
--title "$VERSION" \
558+
--notes "Cronet Go binding release based on Chromium $CHROMIUM_VERSION"
559+
fi
560+
561+
# Upload assets
562+
gh release upload "$VERSION" release/*.so --clobber

cmd/build-naive/cmd.go

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -231,6 +231,35 @@ func copyDirectory(source, destination string) {
231231
}
232232
}
233233

234+
func copyDirectoryExclude(source, destination string, excludePatterns []string) {
235+
os.MkdirAll(destination, 0o755)
236+
entries, err := os.ReadDir(source)
237+
if err != nil {
238+
return
239+
}
240+
for _, entry := range entries {
241+
sourcePath := filepath.Join(source, entry.Name())
242+
destinationPath := filepath.Join(destination, entry.Name())
243+
244+
shouldExclude := false
245+
for _, pattern := range excludePatterns {
246+
if matched, _ := filepath.Match(pattern, entry.Name()); matched {
247+
shouldExclude = true
248+
break
249+
}
250+
}
251+
if shouldExclude {
252+
continue
253+
}
254+
255+
if entry.IsDir() {
256+
copyDirectoryExclude(sourcePath, destinationPath, excludePatterns)
257+
} else {
258+
copyFile(sourcePath, destinationPath)
259+
}
260+
}
261+
}
262+
234263
func copyGlob(sourceDirectory, destinationDirectory, pattern string) {
235264
matches, _ := filepath.Glob(filepath.Join(sourceDirectory, pattern))
236265
for _, source := range matches {

cmd/build-naive/cmd_build.go

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -302,5 +302,11 @@ func buildTarget(t Target) {
302302
} else {
303303
log.Printf("Running: ninja -C %s cronet_static", outputDirectory)
304304
runCommand(srcRoot, "ninja", "-C", outputDirectory, "cronet_static")
305+
306+
// For Linux glibc, also build shared library for purego mode and release distribution
307+
if t.GOOS == "linux" && t.Libc != "musl" {
308+
log.Printf("Running: ninja -C %s cronet", outputDirectory)
309+
runCommand(srcRoot, "ninja", "-C", outputDirectory, "cronet")
310+
}
305311
}
306312
}

cmd/build-naive/cmd_package.go

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -83,6 +83,16 @@ func packageTargets(targets []Target) {
8383
log.Printf("Copied static library for %s/%s", t.GOOS, t.ARCH)
8484
}
8585
}
86+
87+
// For Linux glibc, also copy shared library (for testing and release, not for go module)
88+
if t.GOOS == "linux" && t.Libc != "musl" {
89+
sourceShared := filepath.Join(srcRoot, outputDirectory, "libcronet.so")
90+
destinationShared := filepath.Join(targetDirectory, "libcronet.so")
91+
if _, err := os.Stat(sourceShared); err == nil {
92+
copyFile(sourceShared, destinationShared)
93+
log.Printf("Copied shared library for %s/%s", t.GOOS, t.ARCH)
94+
}
95+
}
8696
}
8797
}
8898

cmd/build-naive/cmd_publish.go

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,8 @@ func publish() {
5050
log.Print("Step 1: Publishing main module and lib submodules...")
5151

5252
// Copy lib, include directories and include_cgo.go
53-
copyDirectory(filepath.Join(projectRoot, "lib"), filepath.Join(temporaryDirectory, "lib"))
53+
// Exclude shared libraries (.so) - they are for testing/release only, not for go module
54+
copyDirectoryExclude(filepath.Join(projectRoot, "lib"), filepath.Join(temporaryDirectory, "lib"), []string{"*.so"})
5455
copyDirectory(filepath.Join(projectRoot, "include"), filepath.Join(temporaryDirectory, "include"))
5556
copyFile(filepath.Join(projectRoot, "include_cgo.go"), filepath.Join(temporaryDirectory, "include_cgo.go"))
5657

naiveproxy

0 commit comments

Comments
 (0)