#!/usr/bin/env python3 """cargo-ndk 4.1.2 subprocess contract with locked, offline dependency resolution. Do not replace with a shell shim: some shells discard cargo-ndk's hyphenated CC/CXX environment keys, causing cc-rs to lose the actual NDK compiler path. """ import os from pathlib import Path import sys def refuse(): sys.stderr.write('cargo-locked-offline: refused unsupported invocation or missing input\n') raise SystemExit(64) def main(): real = os.environ.get('ANDROID_REAL_CARGO', '') if not real or not Path(real).is_absolute() or not os.access(real, os.X_OK): refuse() if Path(real).resolve() == Path(__file__).resolve(): refuse() if not Path('Cargo.lock').is_file() or Path('Cargo.lock').stat().st_size == 0 or not Path('Cargo.toml').is_file(): refuse() args = sys.argv[1:] if args == ['metadata', '--format-version', '1', '--no-deps']: args += ['--locked', '--offline'] else: base = ['build', '--release', '--locked', '--offline'] suffix = ['--manifest-path', str(Path.cwd() / 'Cargo.toml'), '--target', 'aarch64-linux-android', '--message-format', 'json-render-diagnostics'] preview = ['--no-default-features', '--features', 'experimental-usb'] if args not in (base + suffix, base + preview + suffix): refuse() # Preserve every NDK toolchain key verbatim, including hyphenated names. env = dict(os.environ, CARGO_NET_OFFLINE='true', CARGO=real) os.execve(real, [real, *args], env) if __name__ == '__main__': main()