Skip to content

Build PerfSpect from source and decouple it from the agent build - #84

Open
artursarlo wants to merge 5 commits into
masterfrom
perfspect-build-from-source
Open

artursarlo wants to merge 5 commits into
masterfrom
perfspect-build-from-source

Conversation

@artursarlo

Copy link
Copy Markdown

Summary

Build the PerfSpect profiling tool from source with gProfiler-specific patches, and decouple it from the per-architecture agent executable builds so it can be built once (on x86_64) and passed in as a prebuilt binary.

Motivation

PerfSpect's make dist only runs on x86_64 — it cross-compiles both the x86_64 and aarch64 binaries. Building it inline during the aarch64 executable build is therefore impossible. Decoupling lets CI build PerfSpect once on an x86_64 worker and hand the right artifact to each architecture's build.

Changes

scripts/build_perfspect.sh

  • Builds PerfSpect from a pinned upstream revision, applying guarded, idempotent gProfiler-specific patches to the freshly cloned source (kept here rather than upstreamed):
    • avx-turbo: clone with full history so the pinned commit is reachable (the shallow --depth 1 clone couldn't check it out).
    • lower make tools parallelism to avoid GitHub clone throttling.
    • drop check_vuln from the aggregate check target so the build isn't gated on newly-disclosed CVEs.
  • Delegates the actual build to builder/build.sh.
  • Dropped the --arch selector: make dist cross-compiles both arches, so the script now always emits both perfspect/perfspect-x86_64 and perfspect/perfspect-aarch64.
  • Reclaims ownership of the build tree after the container build (make dist runs as root and leaves root-owned artifacts).

scripts/build_x86_64_executable.sh / scripts/build_aarch64_executable.sh

  • Accept --perfspect <path> to bundle a prebuilt PerfSpect binary; if omitted, the agent is built without the resource (graceful, non-breaking).
  • Stage only the single resource file at perfspect/perfspect (collision-safe), without wiping perfspect/, so prebuilt binaries produced alongside are preserved.
  • Never mutate the tracked executable.Dockerfile: when PerfSpect is absent, build from a throwaway Dockerfile with the COPY stripped, keeping the tree clean and each run idempotent.

.dockerignore / .gitignore

  • Keep the large PerfSpect clone/dist out of the Docker build context (only perfspect/perfspect is shipped).
  • Ignore the /perfspect/ build clone directory.

Testing

x86_64 and aarch64 executable builds were validated manually end-to-end using the decoupled flow (build_perfspect.sh --strategy build producing both binaries, then each build_*_executable.sh --perfspect <binary>).

Made with Cursor

artursarlo and others added 5 commits September 29, 2026 23:12
Switch the executable build scripts to build PerfSpect from source
(--strategy=build) instead of downloading the prebuilt release, and patch
the freshly cloned PerfSpect source in build_perfspect.sh so it builds
cleanly against the pinned revision on restricted hosts:

- avx-turbo: full single-branch clone so the pinned commit is reachable
  (the shallow --depth 1 clone cannot check it out)
- tools build: lower parallelism to -j4 to avoid GitHub throttling the
  many parallel anonymous git clones
- make check: drop check_vuln so the build is not gated on CVEs disclosed
  after the pinned release

Replace the manual docker build steps with a call to builder/build.sh and
extract the arch-appropriate binary from the dist tarball into
perfspect/perfspect (handling the root-owned artifact from the container).

Co-authored-by: Cursor <cursoragent@cursor.com>
scripts/build_perfspect.sh clones PerfSpect into ./perfspect at build
time (130MB+, contains root-owned artifacts from the container build).
Ignore it so it can't be committed accidentally.

Co-authored-by: Cursor <cursoragent@cursor.com>
PerfSpect can only be built on x86_64 (it cross-compiles both arches), so
building it inline during the aarch64 executable build is not possible.

Decouple it: the x86_64 and aarch64 executable build scripts no longer call
build_perfspect.sh. Instead they accept a prebuilt PerfSpect binary via
--perfspect <path> and stage it into the build context at perfspect/perfspect.
If no binary is provided, the PerfSpect COPY is dropped and the agent is built
without the resource (non-breaking for existing callers).

This lets CI build PerfSpect once on an x86_64 worker and pass the per-arch
artifact to each executable build.

Co-authored-by: Cursor <cursoragent@cursor.com>
…erfile

build_perfspect.sh:
- Drop the --arch selector. 'make dist' cross-compiles both architectures, so
  always extract both binaries (perfspect/perfspect-x86_64 and
  perfspect/perfspect-aarch64) via a shared extract helper.
- Download strategy stays x86_64-only (Intel publishes no aarch64 release).

build_{x86_64,aarch64}_executable.sh:
- Stop wiping perfspect/. Stage only the single resource file perfspect/perfspect,
  collision-safe (skip self-copy) with a sudo fallback for a root-owned stale file,
  so prebuilt binaries left in perfspect/ by build_perfspect.sh are preserved.
- Never mutate the tracked executable.Dockerfile. When no --perfspect is given,
  build from a throwaway temp Dockerfile with the PerfSpect COPY stripped, so a
  missing perfspect/ can't break the build and runs are idempotent.

.dockerignore:
- Exclude perfspect/** except perfspect/perfspect, so the large clone/dist and the
  per-arch binaries stay out of the build context now that perfspect/ isn't wiped.

Co-authored-by: Cursor <cursoragent@cursor.com>
builder/build.sh runs 'make dist' in a container as root with the clone
bind-mounted, so dist/ and the in-container-built perfspect / perfspect-aarch64
binaries end up owned by root on the host. This made extracting perfspect-aarch64
fail (cp could not overwrite the root-owned file) and left root-owned artifacts
behind.

chown -R the tree back to the current user after the build, and make the extract
helper overwrite its destination (rm -f before cp) so it no longer collides with
the perfspect-aarch64 binary that make compiles at the clone root.

Co-authored-by: Cursor <cursoragent@cursor.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant