|
| 1 | +# Implement Java `darwin-arm64` in-process runtime support |
| 2 | + |
| 3 | +Work autonomously in the current `copilot-sdk` repository. Implement the change completely, validate it, and leave the worktree ready for review. Do not stop at a plan, do not ask routine implementation questions, and do not commit or push unless explicitly requested. |
| 4 | + |
| 5 | +## Required context |
| 6 | + |
| 7 | +Read `java/docs/adr/adr-007-native-bundling-strategy.md` and deeply understand it. |
| 8 | + |
| 9 | +This work extends two merged pull requests. Before editing anything, use `gh` to fetch and thoroughly understand them in this order: |
| 10 | + |
| 11 | +1. PR [#2301](https://github.com/github/copilot-sdk/pull/2301), which introduced the Java in-process FFI runtime and `linux-x64` classifier. |
| 12 | +1. PR [#2393](https://github.com/github/copilot-sdk/pull/2393), which added `win32-x64`, host-specific packaging, multi-runner testing, artifact handoff, and coordinated Maven Central release/snapshot publication. |
| 13 | + |
| 14 | +Read their descriptions, changed-file lists, commits, diffs, and relevant review context. Then inspect the current versions of all affected files; current `main` is authoritative where it differs from a merged PR diff. |
| 15 | + |
| 16 | +Also read and follow all repository instructions that apply to Java, Maven, workflows, and documentation. Run every Maven command from `java/`, with the required Java environment and tee-to-`*job-logs*` convention from the repository instructions. |
| 17 | + |
| 18 | +The current local runtime is native `darwin-arm64`, so use it for real host-matched packaging and in-process validation rather than relying only on mocked tests. |
| 19 | + |
| 20 | +## Goal |
| 21 | + |
| 22 | +Add `darwin-arm64` as the third implemented and published Java native runtime classifier, alongside: |
| 23 | + |
| 24 | +* `linux-x64` from PR #2301. |
| 25 | +* `win32-x64` from PR #2393. |
| 26 | + |
| 27 | +The result must support Java in-process mode on Apple Silicon macOS, build the macOS classifier only on a matching macOS ARM64 host, test it in CI, and publish all three classifiers under one coordinated Maven deployment for releases and snapshots. |
| 28 | + |
| 29 | +Preserve existing default subprocess behavior. In-process mode remains experimental and opt-in. |
| 30 | + |
| 31 | +## Non-negotiable invariants |
| 32 | + |
| 33 | +Preserve and extend the safety model established by PR #2393: |
| 34 | + |
| 35 | +* Build each classifier on its matching native host: |
| 36 | + * `linux-x64` on Ubuntu x64 glibc. |
| 37 | + * `win32-x64` on Windows x64. |
| 38 | + * `darwin-arm64` on Apple Silicon macOS. |
| 39 | +* Validate the exact OS and architecture before download or packaging. Unsupported or mismatched hosts must fail rather than emit a mislabeled classifier. |
| 40 | +* Fetch `@github/copilot-darwin-arm64` at the exact version and SHA-512 integrity pinned in `nodejs/package-lock.json`. |
| 41 | +* Package these nonempty resources in the Darwin classifier: |
| 42 | + * `native/darwin-arm64/runtime.node` |
| 43 | + * `native/darwin-arm64/copilot` |
| 44 | + * `native/darwin-arm64/platform.properties` |
| 45 | +* Keep the bundled `copilot` executable during the active Rust migration. Do not interpret issue #2399's title as permission to remove the transitional embedded-host executable or broadly remove Node.js requirements. |
| 46 | +* Keep the primary runtime JAR OS-neutral and free of every platform-native resource. |
| 47 | +* Reject cross-classifier contamination in classifier JARs. |
| 48 | +* Build all classifiers from the same immutable source and Maven version. |
| 49 | +* Perform exactly one Maven deployment from Ubuntu after validating and attaching the Windows and Darwin handoffs. This preserves one snapshot timestamp/build number and one signed release artifact set. |
| 50 | +* Publish checksums and report all three classifier artifacts only after Maven deployment succeeds. |
| 51 | +* Do not weaken release rollback safeguards, source identity checks, checksum checks, artifact-name checks, pinned-native-version checks, signing checks, or local publication validation. |
| 52 | +* Do not hand-edit generated sources. |
| 53 | +* Do not modify unrelated languages or workflows. |
| 54 | + |
| 55 | +The Java runtime loader and `PlatformDetector` already recognize `darwin-arm64`. Do not rewrite them merely to show activity. Change Java production code only if investigation or native validation exposes a real Darwin-specific defect. |
| 56 | + |
| 57 | +## Implementation requirements |
| 58 | + |
| 59 | +Investigate all hard-coded one-platform and two-platform assumptions, not only the obvious workflow matrices. At minimum, address the following surfaces. |
| 60 | + |
| 61 | +### Native Maven packaging |
| 62 | + |
| 63 | +Update `java/copilot-native/pom.xml` following the existing Linux and Windows profiles: |
| 64 | + |
| 65 | +* Add a host-activated `native-darwin-arm64` profile for Apple Silicon macOS. |
| 66 | +* Set the classifier to `darwin-arm64` and the CLI filename to `copilot`. |
| 67 | +* Bind the shared host validation, fetch, script-test, classifier-JAR, and structural-verification executions exactly as the implemented host profiles do. |
| 68 | +* Ensure `-Pinprocess` selects `darwin-arm64` on this host instead of retaining its Linux default. |
| 69 | +* Add a validated external Darwin-classifier attachment profile for the Ubuntu publication aggregator, analogous to the external Windows attachment profile. |
| 70 | +* Keep attachment validation before artifact attachment and use the exact expected Maven filename. |
| 71 | +* Preserve skip-download behavior. |
| 72 | + |
| 73 | +Update `java/sdk/pom.xml` so its `inprocess` test dependency resolves the `darwin-arm64` classifier on Apple Silicon macOS, analogous to the Windows override. |
| 74 | + |
| 75 | +Use Maven's actual normalized OS/architecture values for the configured JDK. Confirm profile activation locally; do not guess at `arm64` versus `aarch64`. |
| 76 | + |
| 77 | +### Native scripts and tests |
| 78 | + |
| 79 | +Extend the reusable native tooling rather than adding Darwin-only copies: |
| 80 | + |
| 81 | +* `validate-native-host.mjs`: accept only `platform=darwin`, `arch=arm64` for `darwin-arm64`, with no Linux libc requirement. |
| 82 | +* `validate-native-host.test.mjs`: cover Darwin acceptance and wrong-OS/wrong-architecture rejection while retaining Linux and Windows coverage. |
| 83 | +* `fetch-native.test.mjs`: include `darwin-arm64` in the platform table and preserve correct non-Windows CLI naming and executable behavior. |
| 84 | +* `validate-native-artifact.mjs`: ensure Darwin classifier contents and metadata are validated and ensure placeholder validation rejects Darwin native resources too. Prefer a maintainable all-native-resource invariant over another fragile two-platform regex. |
| 85 | +* `create-native-classifier-test-fixture.mjs`, `validate-native-artifact.test.mjs`, and `validate-local-publication.mjs`: extend fixtures, pinned package data, contamination tests, exact expected JAR sets, and signed local-publication validation to all three implemented classifiers. |
| 86 | + |
| 87 | +Keep the fetch implementation generic if it already handles Darwin correctly. Add or change production logic only where required. |
| 88 | + |
| 89 | +### Java and native CI |
| 90 | + |
| 91 | +Update `.github/workflows/java-sdk-tests.yml`: |
| 92 | + |
| 93 | +* Add `darwin-arm64` on an Apple Silicon GitHub-hosted macOS runner to the in-process test matrix. |
| 94 | +* Run the same host validation and `mvn clean verify -Pinprocess` behavior as Linux and Windows. |
| 95 | +* Add a Darwin native-publication input job parallel to the Windows input job. It must validate source identity, build only the Darwin classifier, validate the classifier and neutral placeholder, generate and validate a SHA-256 manifest, and upload only the Darwin JAR and checksum with a unique run/attempt-scoped artifact name. |
| 96 | +* Make the Ubuntu publication-assembly job depend on both native input jobs. |
| 97 | +* Verify that Linux, Windows, and Darwin inputs all have the same immutable source SHA and Maven version before local deployment. |
| 98 | +* Download, checksum-validate, classifier-validate, and attach both external classifiers; build Linux locally; then validate one complete signed local publication containing exactly the neutral artifacts and all three classifier JARs. |
| 99 | + |
| 100 | +Do not assume `macos-latest` is ARM64 without confirming the current GitHub-hosted runner label. Use the repository's existing pinned-action conventions. |
| 101 | + |
| 102 | +### Maven Central release workflow |
| 103 | + |
| 104 | +Update `.github/workflows/java-publish-maven.yml` by extending the PR #2393 coordinated model: |
| 105 | + |
| 106 | +* Add a Darwin classifier build job after release preparation, parallel to the Windows job, on an Apple Silicon macOS runner. |
| 107 | +* Check out the prepared release tag and verify its commit equals the recorded immutable tag commit. |
| 108 | +* Validate the host, build and validate `darwin-arm64`, validate the neutral placeholder, create and validate its SHA-256 manifest, and upload only the classifier and checksum. |
| 109 | +* Make the single Ubuntu deploy job require and download both Windows and Darwin handoffs. |
| 110 | +* Validate exact filenames, checksums, pinned native metadata, source identity, and version before attaching either handoff. |
| 111 | +* Pass both external classifier paths to Maven, build Linux locally, and deploy the neutral artifacts plus all three classifiers once. |
| 112 | +* Include `darwin-arm64`, its macOS runner, artifact filename, and SHA-256 in the one post-success summary. |
| 113 | +* Update rollback job dependencies so failures in either native build or deployment trigger the existing guarded rollback behavior. Do not otherwise loosen or redesign rollback safety. |
| 114 | + |
| 115 | +### Maven Central snapshot workflow |
| 116 | + |
| 117 | +Update `.github/workflows/java-publish-snapshot.yml` with the same three-host publication topology: |
| 118 | + |
| 119 | +* Resolve one immutable snapshot source. |
| 120 | +* Build Windows and Darwin classifiers independently on matching runners. |
| 121 | +* Verify each checkout matches the resolved source and both Maven versions match the deploy checkout. |
| 122 | +* Upload run/attempt-scoped JAR/checksum handoffs. |
| 123 | +* In the sole Ubuntu deploy job, validate and attach both external classifiers, build Linux, and deploy all three classifiers once. |
| 124 | +* Emit one post-success summary listing Linux, Windows, and Darwin with runner, filename, and SHA-256. |
| 125 | +* Preserve scheduled/default-branch and manual-dispatch behavior from PR #2393. |
| 126 | + |
| 127 | +Avoid copy/paste drift where a small, clear matrix or shared script is safer, but do not force a matrix when GitHub Actions output or artifact semantics become less reliable. Correct source/version handoff is more important than reducing YAML lines. |
| 128 | + |
| 129 | +### Documentation |
| 130 | + |
| 131 | +Update `java/README.md` and `java/docs/adr/adr-007-native-bundling-strategy.md` to describe the implemented state accurately: |
| 132 | + |
| 133 | +* Supported in-process classifiers are now `linux-x64` glibc, `win32-x64`, and `darwin-arm64`. |
| 134 | +* Show how consumers choose the Darwin classifier. |
| 135 | +* Document native Apple Silicon Maven activation and `mvn -Pinprocess clean verify`. |
| 136 | +* Document Darwin classifier contents. |
| 137 | +* Describe the three-runner, one-deployment release and snapshot model. |
| 138 | +* Change statements that currently describe macOS as unsupported or say only two classifiers are published. |
| 139 | +* Preserve the distinction between all eight classifiers recognized by runtime detection and the three classifiers actually packaged/published. |
| 140 | +* Keep the transitional bundled CLI explanation. |
| 141 | + |
| 142 | +Keep documentation factual and avoid claiming `darwin-x64` or any ARM/ musl target other than `darwin-arm64` is implemented. |
| 143 | + |
| 144 | +## Validation |
| 145 | + |
| 146 | +Use the smallest focused checks while iterating, then run the complete host-matched validation. At minimum: |
| 147 | + |
| 148 | +1. Run the Node native script test suite used by the Maven module. |
| 149 | +1. Confirm Maven activates both native Darwin profiles on this `darwin-arm64` host and resolves the SDK test classifier as `darwin-arm64`. |
| 150 | +1. From `java/`, run the full native in-process reactor validation: |
| 151 | + |
| 152 | + ```text |
| 153 | + mvn clean verify -Pinprocess |
| 154 | + ``` |
| 155 | + |
| 156 | +1. Inspect the produced Darwin classifier JAR and prove it contains exactly the expected Darwin native resource tree with nonempty `runtime.node`, `copilot`, and correct `platform.properties`. |
| 157 | +1. Prove the primary runtime JAR has no platform-native resources. |
| 158 | +1. Exercise local publication validation for exactly three classifiers, including signatures where the existing workflow requires them. |
| 159 | +1. Run Spotless/checkstyle or the smallest existing formatting/lint checks covering changed Java/Maven files. |
| 160 | +1. Validate edited workflow YAML with an existing repository mechanism if one exists; do not add a new lint dependency. |
| 161 | +1. Review the final diff for stale two-platform wording and hard-coded classifier lists. |
| 162 | + |
| 163 | +All Maven invocations and Maven log inspection must follow the repository's Java command/bootstrap and `*job-logs*` requirements. Do not use `-q` for `mvn verify`, do not pipe Maven output through `grep`, and do not claim success from an uninspected exit status/log. |
| 164 | + |
| 165 | +If real in-process execution reveals a Darwin-specific loader, JNA, executable-permission, quarantine, atomic-publication, or library-locking issue, diagnose and fix the root cause with focused tests. Do not add broad catches, silent fallbacks, or platform skips to make CI green. |
| 166 | + |
| 167 | +## Completion criteria |
| 168 | + |
| 169 | +Finish only when: |
| 170 | + |
| 171 | +* `darwin-arm64` packages and runs in-process successfully on the current host. |
| 172 | +* Linux and Windows behavior remains intact. |
| 173 | +* CI covers in-process execution on all three hosts. |
| 174 | +* release, snapshot, and local publication assembly include exactly all three classifiers under one Maven deployment. |
| 175 | +* checksums, source/version identity, classifier contents, placeholder purity, and signing validation remain enforced. |
| 176 | +* README and ADR match the implemented behavior. |
| 177 | +* the final worktree contains only intentional source changes and any pre-existing user files; temporary build artifacts and logs are not staged. |
| 178 | + |
| 179 | +In the final response, lead with the implemented outcome, identify the meaningful packaging/workflow changes, and state any validation that could not be completed. Do not provide a plan or a list of optional follow-up work. |
0 commit comments