diff --git a/.github/dotslash-provisioned-config.json b/.github/dotslash-provisioned-config.json new file mode 100644 index 0000000000..2f7363ed06 --- /dev/null +++ b/.github/dotslash-provisioned-config.json @@ -0,0 +1,16 @@ +{ + "outputs": { + "codex-provisioned": { + "platforms": { + "macos-aarch64": { + "regex": "^codex-provisioned-package-aarch64-apple-darwin\\.tar\\.gz$", + "path": "bin/codex" + }, + "macos-x86_64": { + "regex": "^codex-provisioned-package-x86_64-apple-darwin\\.tar\\.gz$", + "path": "bin/codex" + } + } + } + } +} diff --git a/.github/scripts/build-codex-package-archive.sh b/.github/scripts/build-codex-package-archive.sh index 7b5ac74865..1ac54c0cce 100644 --- a/.github/scripts/build-codex-package-archive.sh +++ b/.github/scripts/build-codex-package-archive.sh @@ -15,7 +15,7 @@ Usage: build-codex-package-archive.sh \ [--zsh-manifest ] \ [--codex-command-runner-bin ] \ [--codex-windows-sandbox-setup-bin ] \ - [--voice-signed-dir --release-version ] \ + [--voice-release-dir --release-version ] \ [--target-suffixed-entrypoint] EOF } @@ -30,7 +30,7 @@ bwrap_bin_provided="false" code_mode_host_bin_provided="false" command_runner_bin_provided="false" sandbox_setup_bin_provided="false" -voice_signed_dir="" +voice_release_dir="" release_version="" while [[ $# -gt 0 ]]; do @@ -93,8 +93,8 @@ while [[ $# -gt 0 ]]; do target_suffixed_entrypoint="true" shift ;; - --voice-signed-dir) - voice_signed_dir="${2:?--voice-signed-dir requires a value}" + --voice-release-dir) + voice_release_dir="${2:?--voice-release-dir requires a value}" shift 2 ;; --release-version) @@ -117,8 +117,8 @@ if [[ -z "$target" || -z "$bundle" || -z "$entrypoint_dir" || -z "$archive_dir" usage >&2 exit 1 fi -if [[ ( -n "$voice_signed_dir" || -n "$release_version" ) && ( -z "$voice_signed_dir" || -z "$release_version" || "$bundle" != "primary" || "$target" != *-apple-darwin ) ]]; then - echo "Signed voice resources require a primary macOS release package version" >&2 +if [[ ( -n "$voice_release_dir" || -n "$release_version" ) && ( -z "$voice_release_dir" || -z "$release_version" || "$bundle" != "primary" || ( "$target" != *-apple-darwin && "$target" != *-unknown-linux-musl ) ) ]]; then + echo "Voice resources require a primary macOS or Linux release package version" >&2 exit 1 fi @@ -204,7 +204,7 @@ python_args=( --cargo-profile release --package-dir "$package_dir" ) -if [[ -z "$voice_signed_dir" ]]; then +if [[ -z "$voice_release_dir" ]]; then python_args+=(--archive-output "$gzip_archive_path" --archive-output "$zstd_archive_path") fi if ((${#resource_args[@]} > 0)); then @@ -214,14 +214,18 @@ python_args+=(--force) "$python_bin" "${python_args[@]}" -if [[ -n "$voice_signed_dir" ]]; then +if [[ -n "$voice_release_dir" ]]; then + voice_target="$target" + if [[ "$target" == *-unknown-linux-musl ]]; then + voice_target="${target%-musl}-gnu" + fi voice_package="${RUNNER_TEMP:-/tmp}/${archive_stem}-voice-${target}" rm -rf "$voice_package" "$python_bin" "${repo_root}/third_party/voice/assemble_package.py" \ --package "$package_dir" \ - --helper "${voice_signed_dir%/}/codex-voice-host" \ - --runtime "${voice_signed_dir%/}/runtime" \ - --voice-target "$target" \ + --helper "${voice_release_dir%/}/codex-voice-host" \ + --runtime "${voice_release_dir%/}/runtime" \ + --voice-target "$voice_target" \ --build-commit "$(git -C "$repo_root" rev-parse HEAD)" \ --release-version "$release_version" \ --output "$voice_package" diff --git a/.github/workflows/rust-release-provisioned-macos.yml b/.github/workflows/rust-release-provisioned-macos.yml index d131835618..6d1b24591f 100644 --- a/.github/workflows/rust-release-provisioned-macos.yml +++ b/.github/workflows/rust-release-provisioned-macos.yml @@ -1,4 +1,5 @@ -# Optional side artifacts only; no release, npm, installer, or DMG publication. +# Verified side packages, published by rust-release.yml when enabled. +# The legacy CLI, npm, installer and DMG packages are unchanged. # Required secrets in the codesigning environment: # - CODEX_CLI_PROVISIONING_PROFILE_BASE64: profile approved for public distribution. # - CODEX_CLI_PROVISIONING_PROFILE_SHA256: reviewed lowercase SHA-256 of that profile. diff --git a/.github/workflows/rust-release.yml b/.github/workflows/rust-release.yml index d351371dfa..b3863a0e4c 100644 --- a/.github/workflows/rust-release.yml +++ b/.github/workflows/rust-release.yml @@ -61,9 +61,8 @@ jobs: needs: tag-check name: Build - ${{ matrix.runner }} - ${{ matrix.target }} - ${{ matrix.bundle }} runs-on: ${{ matrix.runs_on || matrix.runner }} - # Release builds can take a long time, so leave some headroom to avoid - # having to restart the full workflow due to a timeout. - timeout-minutes: 90 + # Linux releases also build the native voice runtime in this job. + timeout-minutes: 120 permissions: contents: read id-token: write @@ -292,6 +291,37 @@ jobs: path: codex-rs/symbols-dist/${{ matrix.artifact_name }}/* if-no-files-found: error + - name: Set up Bazel for Linux voice + if: ${{ matrix.bundle == 'primary' && contains(matrix.target, 'linux') }} + uses: bazel-contrib/setup-bazel@c5acdfb288317d0b5c0bbd7a396a3dc868bb0f86 # 0.19.0 + with: + bazelisk-version: 1.28.1 + + - name: Build Linux voice runtime + if: ${{ matrix.bundle == 'primary' && contains(matrix.target, 'linux') }} + shell: bash + env: + APP_TARGET: ${{ matrix.target }} + run: | + set -euo pipefail + cd "$GITHUB_WORKSPACE" + voice_target="${APP_TARGET%-musl}-gnu" + case "$voice_target" in + aarch64-unknown-linux-gnu) prefix=linux_aarch64 ;; + x86_64-unknown-linux-gnu) prefix=linux_x86_64 ;; + *) exit 1 ;; + esac + bazel build -c opt //codex-rs/voice-host:codex-voice-host //third_party/voice:native_runtime + source="bazel-bin/third_party/voice/native_runtime_${prefix}" + output="${RUNNER_TEMP}/signed-voice/${APP_TARGET}" + mkdir -p "$output" + python3 third_party/voice/release_runtime.py stage \ + --target "$voice_target" --source "$source" --output "$output/runtime" + cp bazel-bin/codex-rs/voice-host/codex-voice-host "$output/codex-voice-host" + chmod 0755 "$output/codex-voice-host" + python3 third_party/voice/release_runtime.py seal \ + --target "$voice_target" --output "$output/runtime" + - if: ${{ runner.os == 'macOS' }} name: Stage unsigned macOS artifacts shell: bash @@ -376,12 +406,26 @@ jobs: BUNDLE: ${{ matrix.bundle }} run: | set -euo pipefail + voice_args=() + if [[ "$BUNDLE" == "primary" && "$TARGET" == *-unknown-linux-musl ]]; then + voice_args+=(--voice-release-dir "${RUNNER_TEMP}/signed-voice/${TARGET}") + voice_args+=(--release-version "${GITHUB_REF_NAME#rust-v}") + fi bash "${GITHUB_WORKSPACE}/.github/scripts/build-codex-package-archive.sh" \ --target "$TARGET" \ --bundle "$BUNDLE" \ --entrypoint-dir "target/${TARGET}/release" \ --archive-dir "dist/${TARGET}" \ - --zsh-manifest "${RUNNER_TEMP}/codex-zsh" + --zsh-manifest "${RUNNER_TEMP}/codex-zsh" \ + "${voice_args[@]}" + + - name: Cosign Linux voice package archives + if: ${{ matrix.bundle == 'primary' && contains(matrix.target, 'linux') }} + uses: ./.github/actions/linux-code-sign + with: + target: ${{ matrix.target }} + artifacts-dir: ${{ github.workspace }}/codex-rs/dist/${{ matrix.target }} + binaries: codex-package-${{ matrix.target }}.tar.gz codex-package-${{ matrix.target }}.tar.zst - name: Build Python runtime wheel if: ${{ matrix.bundle == 'primary' && runner.os != 'macOS' }} @@ -413,13 +457,31 @@ jobs: # the Homebrew Python as externally managed under PEP 668. "${RUNNER_TEMP}/python-runtime-build-venv/bin/python" -m pip install build + # Keep the existing manylinux_2_17 wheel compatible with older glibc. + # GNU voice libraries belong in the signed release package archives, + # but their minimum glibc version is not covered by this wheel tag. + wheel_archives="${RUNNER_TEMP}/voice-free-wheel/${{ matrix.target }}" + bash "${GITHUB_WORKSPACE}/.github/scripts/build-codex-package-archive.sh" \ + --target "${{ matrix.target }}" \ + --bundle primary \ + --entrypoint-dir "target/${{ matrix.target }}/release" \ + --archive-dir "$wheel_archives" \ + --zsh-manifest "${RUNNER_TEMP}/codex-zsh" + wheel_archive="${wheel_archives}/codex-package-${{ matrix.target }}.tar.gz" + python3 - "$wheel_archive" <<'PY' + import sys + import tarfile + with tarfile.open(sys.argv[1]) as archive: + assert not any("codex-resources/voice/" in item.name for item in archive) + PY + stage_dir="${RUNNER_TEMP}/openai-codex-cli-bin-${{ matrix.target }}" wheel_dir="${GITHUB_WORKSPACE}/python-runtime-dist/${{ matrix.target }}" stage_runtime_args=( "${GITHUB_WORKSPACE}/sdk/python/scripts/update_sdk_artifacts.py" stage-runtime "$stage_dir" - "dist/${{ matrix.target }}/codex-package-${{ matrix.target }}.tar.gz" + "$wheel_archive" --codex-version "${GITHUB_REF_NAME}" --platform-tag "$platform_tag" ) @@ -915,7 +977,7 @@ jobs: set -euo pipefail voice_args=() if [[ "$BUNDLE" == "primary" ]]; then - voice_args+=(--voice-signed-dir "${RUNNER_TEMP}/signed-voice/${TARGET}") + voice_args+=(--voice-release-dir "${RUNNER_TEMP}/signed-voice/${TARGET}") voice_args+=(--release-version "${GITHUB_REF_NAME#rust-v}") fi bash "${GITHUB_WORKSPACE}/.github/scripts/build-codex-package-archive.sh" \ @@ -1394,7 +1456,8 @@ jobs: path: codex-rs/dist/${{ matrix.target }}/* if-no-files-found: error - # Separate opt-in candidates never enter the normal release download patterns. + # Keep provisioned packages separate from the legacy CLI/npm/installer layout. + # Desktop consumes the versioned codex-provisioned manifest from this release. provisioned-macos-candidate: needs: finalize-macos if: github.event_name == 'push' && startsWith(github.ref, 'refs/tags/rust-v') && vars.CODEX_PROVISIONED_MACOS_CANDIDATE == 'true' @@ -1476,6 +1539,7 @@ jobs: - build-windows - argument-comment-lint-release-assets - stage-npm-packages + - provisioned-macos-candidate if: >- ${{ always() && @@ -1484,7 +1548,10 @@ jobs: needs.finalize-macos.result == 'success' && needs.build-windows.result == 'success' && needs.argument-comment-lint-release-assets.result == 'success' && - needs.stage-npm-packages.result == 'success' + needs.stage-npm-packages.result == 'success' && + (needs.provisioned-macos-candidate.result == 'success' || + (vars.CODEX_PROVISIONED_MACOS_CANDIDATE != 'true' && + needs.provisioned-macos-candidate.result == 'skipped')) }} name: release runs-on: ubuntu-latest @@ -1536,6 +1603,17 @@ jobs: path: dist pattern: "{*-symbols,argument-comment-lint-*,python-runtime-wheel-*}" + - name: Download verified provisioned macOS packages + if: vars.CODEX_PROVISIONED_MACOS_CANDIDATE == 'true' + uses: actions/download-artifact@3e5f45b2cfb9172054b4087a40e8e0b5a5461e7c # v8.0.1 + with: + path: dist + pattern: "provisioned-macos-verified-candidate-*" + + - name: Remove per-architecture checksum filenames before release upload + if: vars.CODEX_PROVISIONED_MACOS_CANDIDATE == 'true' + run: rm dist/provisioned-macos-verified-candidate-*/SHA256SUMS + - name: List run: ls -R dist/ @@ -1546,7 +1624,7 @@ jobs: manifest="dist/codex-package_SHA256SUMS" tmp_manifest="$(mktemp)" find dist -type f \ - \( -name 'codex-package-*.tar.gz' -o -name 'codex-app-server-package-*.tar.gz' \) \ + \( -name 'codex-package-*.tar.gz' -o -name 'codex-app-server-package-*.tar.gz' -o -name 'codex-provisioned-package-*.tar.gz' \) \ -print | sort | while IFS= read -r archive; do @@ -1676,6 +1754,15 @@ jobs: tag: ${{ github.ref_name }} config: .github/dotslash-argument-comment-lint-config.json + - name: Publish the provisioned macOS package manifest + if: vars.CODEX_PROVISIONED_MACOS_CANDIDATE == 'true' + uses: facebook/dotslash-publish-release@9c9ec027515c34db9282a09a25a9cab5880b2c52 # v2 + env: + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} + with: + tag: ${{ github.ref_name }} + config: .github/dotslash-provisioned-config.json + # Publish to npm using OIDC authentication. # July 31, 2025: https://github.blog/changelog/2025-07-31-npm-trusted-publishing-with-oidc-is-generally-available/ # npm docs: https://docs.npmjs.com/trusted-publishers diff --git a/MODULE.bazel b/MODULE.bazel index 6f74ef307b..e014c6d32c 100644 --- a/MODULE.bazel +++ b/MODULE.bazel @@ -142,6 +142,11 @@ use_repo(osx, "macos_sdk") # Needed to disable xcode... bazel_dep(name = "apple_support", version = "2.1.0") bazel_dep(name = "rules_cc", version = "0.2.18") + +# Windows voice jobs explicitly select the installed MSVC C toolchains. +cc_configure = use_extension("@rules_cc//cc:extensions.bzl", "cc_configure_extension") +use_repo(cc_configure, "local_config_cc") + single_version_override( module_name = "rules_cc", patch_strip = 1, diff --git a/codex-rs/windows-sandbox-rs/src/bin/setup_main/win.rs b/codex-rs/windows-sandbox-rs/src/bin/setup_main/win.rs index f80efe4d12..95ca3fe473 100644 --- a/codex-rs/windows-sandbox-rs/src/bin/setup_main/win.rs +++ b/codex-rs/windows-sandbox-rs/src/bin/setup_main/win.rs @@ -344,28 +344,42 @@ fn lock_sandbox_dir( let system_sid = resolve_sid("SYSTEM")?; let admins_sid = resolve_sid("Administrators")?; let real_sid = resolve_sid(real_user)?; - let entries = [ + let inherited = OBJECT_INHERIT_ACE | CONTAINER_INHERIT_ACE; + let mut entries = vec![ ( sandbox_group_sid.to_vec(), sandbox_group_mask, sandbox_group_access_mode, + inherited, ), ( system_sid, FILE_GENERIC_READ | FILE_GENERIC_WRITE | FILE_GENERIC_EXECUTE | DELETE, GRANT_ACCESS, + inherited, ), ( admins_sid, FILE_GENERIC_READ | FILE_GENERIC_WRITE | FILE_GENERIC_EXECUTE | DELETE, GRANT_ACCESS, + inherited, + ), + ( + real_sid.clone(), + real_user_mask & !WRITE_DAC, + GRANT_ACCESS, + inherited, ), - (real_sid, real_user_mask, GRANT_ACCESS), ]; + // Permission maintenance belongs to the trusted caller on this directory, + // not to the helper files and directories that inherit its content access. + if real_user_mask & WRITE_DAC != 0 { + entries.push((real_sid, WRITE_DAC, GRANT_ACCESS, 0)); + } unsafe { let mut eas: Vec = Vec::new(); let mut sids: Vec<*mut c_void> = Vec::new(); - for (sid_bytes, mask, access_mode) in entries.iter().map(|(s, m, a)| (s, *m, *a)) { + for (sid_bytes, mask, access_mode, inheritance) in &entries { let sid_str = string_from_sid_bytes(sid_bytes).map_err(anyhow::Error::msg)?; let sid_w = to_wide(OsStr::new(&sid_str)); let mut psid: *mut c_void = std::ptr::null_mut(); @@ -377,9 +391,9 @@ fn lock_sandbox_dir( } sids.push(psid); eas.push(EXPLICIT_ACCESS_W { - grfAccessPermissions: mask, - grfAccessMode: access_mode, - grfInheritance: OBJECT_INHERIT_ACE | CONTAINER_INHERIT_ACE, + grfAccessPermissions: *mask, + grfAccessMode: *access_mode, + grfInheritance: *inheritance, Trustee: TRUSTEE_W { pMultipleTrustee: std::ptr::null_mut(), MultipleTrusteeOperation: 0, @@ -816,7 +830,9 @@ fn lock_sandbox_bin_dir(payload: &Payload, sandbox_group_sid: &[u8]) -> Result<( sandbox_group_sid, GRANT_ACCESS, FILE_GENERIC_READ | FILE_GENERIC_EXECUTE, - FILE_GENERIC_READ | FILE_GENERIC_WRITE | FILE_GENERIC_EXECUTE | DELETE, + // Elevated provisioning may own this directory as Administrators. + // The following ordinary refresh must be able to retain its protected ACL. + FILE_GENERIC_READ | FILE_GENERIC_WRITE | FILE_GENERIC_EXECUTE | DELETE | WRITE_DAC, DaclInheritance::Protected, payload.mode, ) diff --git a/codex-rs/windows-sandbox-rs/src/bin/setup_main/win_acl_tests.rs b/codex-rs/windows-sandbox-rs/src/bin/setup_main/win_acl_tests.rs index df39cfdd18..0edce4aab6 100644 --- a/codex-rs/windows-sandbox-rs/src/bin/setup_main/win_acl_tests.rs +++ b/codex-rs/windows-sandbox-rs/src/bin/setup_main/win_acl_tests.rs @@ -7,6 +7,7 @@ use super::GRANT_ACCESS; use super::Payload; use super::SETUP_VERSION; use super::SetupMode; +use super::WRITE_DAC; use super::convert_string_sid_to_sid; use super::lock_sandbox_bin_dir; use super::lock_sandbox_dir; @@ -43,7 +44,11 @@ fn provision_only_locks_plain_directory_via_handle() { #[test] fn lock_sandbox_dir_blocks_inherited_write_for_runner_files() { - for setup_mode in [SetupMode::Full, SetupMode::ProvisionOnly] { + for setup_mode in [ + SetupMode::Full, + SetupMode::InteractiveProvision, + SetupMode::ProvisionOnly, + ] { let temp = tempfile::tempdir().expect("tempdir"); let workspace = temp.path().join("workspace"); let sandbox_bin = workspace.join(".sandbox-bin"); @@ -74,6 +79,8 @@ fn lock_sandbox_dir_blocks_inherited_write_for_runner_files() { ); let real_user = std::env::var("USERNAME").unwrap_or_else(|_| "Administrators".to_string()); + let real_sid = resolve_sid(&real_user).expect("resolve real user SID"); + let real_psid = sid_bytes_to_psid(&real_sid).expect("convert real user SID"); let payload = Payload { version: SETUP_VERSION, offline_username: String::new(), @@ -95,16 +102,52 @@ fn lock_sandbox_dir_blocks_inherited_write_for_runner_files() { let new_runner = sandbox_bin.join("new-runner.exe"); fs::write(&new_runner, b"new").expect("create new runner"); - for path in [&sandbox_bin, &existing_runner, &new_runner] { + let child_dir = sandbox_bin.join("child"); + fs::create_dir(&child_dir).expect("create child directory"); + + // Repeated refresh must retain the right seeded by privileged setup. + lock_sandbox_bin_dir(&payload, &sandbox_group_sid).expect("refresh sandbox bin"); + lock_sandbox_bin_dir(&payload, &sandbox_group_sid).expect("repeat refresh sandbox bin"); + assert!( + path_mask_allows( + &sandbox_bin, + &[real_psid], + WRITE_DAC, + /*require_all_bits*/ true + ) + .expect("check caller can maintain directory permissions") + ); + for path in [&existing_runner, &new_runner, &child_dir] { + assert!( + !path_mask_allows( + path, + &[real_psid], + WRITE_DAC, + /*require_all_bits*/ false + ) + .expect("check permission maintenance does not inherit to helpers") + ); + } + + for path in [&sandbox_bin, &existing_runner, &new_runner, &child_dir] { assert!( !path_mask_allows( path, &[workspace_psid], - FILE_GENERIC_WRITE | DELETE, + FILE_GENERIC_WRITE | DELETE | WRITE_DAC, /*require_all_bits*/ false, ) .expect("check protected path write and delete access") ); + assert!( + !path_mask_allows( + path, + &[sandbox_group_psid], + WRITE_DAC, + /*require_all_bits*/ false + ) + .expect("check sandbox cannot maintain permissions") + ); assert!( path_mask_allows( path, @@ -117,6 +160,7 @@ fn lock_sandbox_dir_blocks_inherited_write_for_runner_files() { } unsafe { + LocalFree(real_psid as HLOCAL); LocalFree(workspace_psid as HLOCAL); LocalFree(sandbox_group_psid as HLOCAL); } diff --git a/third_party/voice/BUILD.bazel b/third_party/voice/BUILD.bazel index 3cf29ebde6..b3c5f0930e 100644 --- a/third_party/voice/BUILD.bazel +++ b/third_party/voice/BUILD.bazel @@ -133,6 +133,30 @@ alias( visibility = ["//visibility:public"], ) +# Explicitly select the installed pkgconf and pinned CMake in Windows voice CI. +native_tool_toolchain( + name = "windows_pkg_config_tool", + env = {"PKG_CONFIG": "$(execpath :pkg_config)"}, + path = "$(execpath :pkg_config)", + target = ":pkg_config", +) + +toolchain( + name = "windows_pkg_config_toolchain", + exec_compatible_with = ["@platforms//os:windows"], + toolchain = ":windows_pkg_config_tool", + toolchain_type = "@rules_foreign_cc//toolchains:pkgconfig_toolchain", + visibility = ["//visibility:public"], +) + +toolchain( + name = "windows_cmake_toolchain", + exec_compatible_with = ["@platforms//os:windows"], + toolchain = "@cmake-3.31.8-windows-x86_64//:cmake_tool", + toolchain_type = "@rules_foreign_cc//toolchains:cmake_toolchain", + visibility = ["//visibility:public"], +) + filegroup( name = "archives", srcs = [ diff --git a/third_party/voice/NOTICE.md b/third_party/voice/NOTICE.md index b6557717f7..c5b79744a8 100644 --- a/third_party/voice/NOTICE.md +++ b/third_party/voice/NOTICE.md @@ -1,6 +1,6 @@ # Native voice libraries in Codex releases -The macOS Codex release package includes dynamically linked GStreamer and GLib +Codex release packages with voice include dynamically linked GStreamer and GLib libraries and selected plugins, plus their native library dependencies. These components have their own copyrights and licenses. Their notices accompany this file in `licenses/`: `LGPL-2.1.txt` for GStreamer and GLib, @@ -12,6 +12,6 @@ The exact upstream versions, source archive URLs and SHA-256 digests are in projection and package scripts are in the public Codex source tree under `third_party/voice/`. The source commit for this package is recorded in `manifest.json`. The native libraries remain separate dynamic libraries in -`lib/` and `plugins/`; replacing them requires compatible binaries and valid -macOS code signatures. Build tools listed in `sources.json` are build inputs, -not bundled runtime libraries. +platform-specific runtime directories. Replacements must be compatible with +the package and, on macOS, have valid code signatures. Build tools listed in +`sources.json` are build inputs, not bundled runtime libraries. diff --git a/third_party/voice/README.md b/third_party/voice/README.md index d79e3de68d..48ea1fa46c 100644 --- a/third_party/voice/README.md +++ b/third_party/voice/README.md @@ -258,11 +258,14 @@ The module does not download that installed tree or accept compiler licenses. After provisioning, a native PowerShell invocation is: ```powershell +$hostArch = $env:PROCESSOR_ARCHITEW6432 +if (-not $hostArch) { $hostArch = $env:PROCESSOR_ARCHITECTURE } bazel build //third_party/voice:native_link_windows_x86_64 ` --platforms=//:local_windows_msvc ` --inject_repository="voice_windows_tools=$env:VOICE_WINDOWS_BAZEL_REPOSITORY" ` --//third_party/voice:windows_installed_tools=@voice_windows_tools//:tools ` - --action_env="SystemRoot=$env:SystemRoot" --host_action_env="SystemRoot=$env:SystemRoot" + --action_env="SystemRoot=$env:SystemRoot" --host_action_env="SystemRoot=$env:SystemRoot" ` + --action_env="PROCESSOR_ARCHITECTURE=$hostArch" --host_action_env="PROCESSOR_ARCHITECTURE=$hostArch" ``` Use `native_link_windows_aarch64` on native ARM64 Windows. Existing MSVC license diff --git a/third_party/voice/bazel_windows.py b/third_party/voice/bazel_windows.py index f14941d041..5cd172fb5a 100644 --- a/third_party/voice/bazel_windows.py +++ b/third_party/voice/bazel_windows.py @@ -64,9 +64,13 @@ def main(): environment, _ = build_environment( document, inputs["target"], {"python": Path(sys.executable)} ) - # Keep executor scratch directories, never its developer tool search path. + # Keep host identity and scratch directories, never developer tool search paths. environment.update( - {name: os.environ[name] for name in ("TMP", "TEMP") if name in os.environ} + { + name: os.environ[name] + for name in ("TMP", "TEMP", "PROCESSOR_ARCHITECTURE") + if name in os.environ + } ) home = temporary / "home" home.mkdir() diff --git a/third_party/voice/release_runtime.py b/third_party/voice/release_runtime.py index 6cb0f74efc..6b705ca314 100644 --- a/third_party/voice/release_runtime.py +++ b/third_party/voice/release_runtime.py @@ -1,4 +1,4 @@ -"""Stage verified macOS voice libraries and seal their post-signing release receipt.""" +"""Stage verified voice libraries and seal their public-release receipt.""" import argparse import json @@ -10,8 +10,13 @@ from runtime import digest def stage(source: Path, destination: Path, target: str) -> None: - if target not in {"aarch64-apple-darwin", "x86_64-apple-darwin"}: - raise ValueError("public voice runtime requires a macOS target") + if target not in { + "aarch64-apple-darwin", + "x86_64-apple-darwin", + "aarch64-unknown-linux-gnu", + "x86_64-unknown-linux-gnu", + }: + raise ValueError("unsupported public release voice runtime target") source = source.resolve(strict=True) files = runtime_files(source, target) destination.mkdir() diff --git a/third_party/voice/test_assemble_package.py b/third_party/voice/test_assemble_package.py index 2eb4999671..7758bd4b12 100644 --- a/third_party/voice/test_assemble_package.py +++ b/third_party/voice/test_assemble_package.py @@ -276,6 +276,38 @@ class AssembleTests(unittest.TestCase): ) self.assertEqual(manifest["appVersion"], version) + def test_linux_release_pairs_musl_app_with_gnu_voice_runtime(self): + self.commit = "b" * 40 + target = "aarch64-unknown-linux-gnu" + runtime, _ = self.make_runtime(target) + staged = self.root / "staged" + stage(runtime, staged, target) + seal(staged, target) + for version in ("0.154.0-alpha.8", "0.154.0-beta.2", "0.154.0"): + with self.subTest(version=version): + self.metadata["version"] = version + (self.package / "codex-package.json").write_text( + json.dumps(self.metadata) + ) + output = self.root / f"linux-{version}" + assemble( + self.package, + self.helper, + target, + self.commit, + output, + runtime=staged, + release_version=version, + ) + voice = output / "codex-resources/voice" + manifest = json.loads((voice / "manifest.json").read_text()) + self.assertEqual(manifest["appTarget"], "aarch64-unknown-linux-musl") + self.assertEqual(manifest["voiceTarget"], target) + self.assertEqual( + manifest["sha256"]["codex-resources/voice/runtime.json"], + digest(staged / "runtime.json"), + ) + def test_rejects_invalid_runtime_receipts_before_creating_package(self): runtime, original = self.make_runtime() changes = [ diff --git a/third_party/voice/test_bazel_windows.py b/third_party/voice/test_bazel_windows.py index 945c7e270c..1bb4296e62 100644 --- a/third_party/voice/test_bazel_windows.py +++ b/third_party/voice/test_bazel_windows.py @@ -5,13 +5,56 @@ import errno import json from pathlib import Path import tempfile +from types import SimpleNamespace import unittest +from unittest.mock import patch + +import bazel_windows from bazel_copy import copy_payloads from bazel_windows import selected_inputs class WindowsInputsTests(unittest.TestCase): + def test_adapter_preserves_host_architecture_without_developer_path(self): + with tempfile.TemporaryDirectory() as directory: + config = Path(directory) / "action.json" + config.write_text("{}") + for architecture in ("AMD64", "ARM64"): + environment = {"PROCESSOR_ARCHITECTURE": architecture, "PATH": "unsafe"} + with ( + self.subTest(architecture=architecture), + patch.object( + bazel_windows, "os", SimpleNamespace(environ=environment) + ), + patch.object( + bazel_windows.sys, "argv", ["driver", "unknown", str(config)] + ), + patch.object( + bazel_windows, + "selected_inputs", + return_value={"target": "unused"}, + ), + patch.object( + bazel_windows, + "build_environment", + return_value=({"PATH": "declared"}, {}), + ), + ): + with self.assertRaisesRegex( + ValueError, "unknown Windows native action" + ): + bazel_windows.main() + self.assertEqual( + environment, + { + "PROCESSOR_ARCHITECTURE": architecture, + "PATH": "declared", + "HOME": environment["HOME"], + "USERPROFILE": environment["HOME"], + }, + ) + def setUp(self): temporary = tempfile.TemporaryDirectory() self.addCleanup(temporary.cleanup) diff --git a/third_party/voice/windows_native.bzl b/third_party/voice/windows_native.bzl index e1a135319e..51c9968dd5 100644 --- a/third_party/voice/windows_native.bzl +++ b/third_party/voice/windows_native.bzl @@ -25,6 +25,9 @@ def _windows_tools_impl(ctx): system_root = ctx.configuration.default_shell_env.get("SystemRoot") if not system_root: fail("Pass --action_env=SystemRoot= as a fixed value") + host_architecture = ctx.configuration.default_shell_env.get("PROCESSOR_ARCHITECTURE") + if not host_architecture: + fail("Pass --action_env=PROCESSOR_ARCHITECTURE= as a fixed value") msvc = ctx.attr.msvc[DirectoryInfo] sdk = ctx.attr.sdk[DirectoryInfo] tools = { @@ -68,7 +71,11 @@ def _windows_tools_impl(ctx): python = python, manifest = manifests[0], installed_files = installed, - environment = {"SystemRoot": system_root, "SYSTEMROOT": system_root}, + environment = { + "SystemRoot": system_root, + "SYSTEMROOT": system_root, + "PROCESSOR_ARCHITECTURE": host_architecture, + }, inputs = { "schemaVersion": 1, "target": ctx.attr.target,