{"record":{"id":"72d2eaf0c90b2f7c","repo":"PyO3/pyo3","slug":"unexpected-rust-target-pointer-width","errorCode":null,"errorMessage":"unexpected Rust target pointer width: {}","messagePattern":"unexpected Rust target pointer width: (.+?)","errorType":"validation","errorClass":null,"httpStatus":null,"severity":"error","filePath":"pyo3-ffi/build.rs","lineNumber":181,"sourceCode":"                \"GraalPy does not support {abi} so the build artifacts will be version-specific.\"\n            ),\n            PythonImplementation::RustPython => {}\n        }\n    }\n\n    Ok(())\n}\n\nfn ensure_target_pointer_width(interpreter_config: &InterpreterConfig) -> Result<()> {\n    if let Some(pointer_width) = interpreter_config.pointer_width() {\n        // Try to check whether the target architecture matches the python library\n        let rust_target = match cargo_env_var(\"CARGO_CFG_TARGET_POINTER_WIDTH\")\n            .unwrap()\n            .as_str()\n        {\n            \"64\" => 64,\n            \"32\" => 32,\n            x => bail!(\"unexpected Rust target pointer width: {}\", x),\n        };\n\n        ensure!(\n            rust_target == pointer_width,\n            \"your Rust target architecture ({}-bit) does not match your python interpreter ({}-bit)\",\n            rust_target,\n            pointer_width\n        );\n    }\n    Ok(())\n}\n\n/// `raw-dylib` currently does not support arbitrary names\n/// (see https://internals.rust-lang.org/t/support-renames-with-link-name-kind-raw-dylib/24415)\n/// so if the lib name is not one of the known subset, we must fall back to full linking.\nfn lib_name_is_known_for_raw_dylib(lib_name: &str) -> bool {\n    // pyo3_dll cfg for raw-dylib linking on Windows\n    if matches!(","sourceCodeStart":163,"sourceCodeEnd":199,"githubUrl":"https://github.com/PyO3/pyo3/blob/ac9b6899d348be4d54614d060dea53a645a12e36/pyo3-ffi/build.rs#L163-L199","documentation":"During configuration pyo3-ffi compares the Rust target's pointer width (from CARGO_CFG_TARGET_POINTER_WIDTH) against the Python interpreter's pointer width. If cargo reports a pointer width other than 64 or 32, the value is unrecognized and the build bails, since pyo3 only supports 32- and 64-bit targets.","triggerScenarios":"ensure_target_pointer_width (called from configure_pyo3_ffi) reads CARGO_CFG_TARGET_POINTER_WIDTH and hits an unexpected value like '16' — i.e. compiling for a niche 16-bit target, or a toolchain/custom target spec reports a nonstandard pointer width.","commonSituations":"Cross-compiling for embedded/16-bit Rust targets (e.g. some AVR-style custom targets); using a nightly custom target JSON with an unusual pointer width; misconfigured build environments where the env var is clobbered.","solutions":["Switch to a supported 32- or 64-bit target triple for the pyo3 dependency","Exclude pyo3/Python extension code from embedded targets (feature-gate it out of the workspace build for that target)","If using a custom target JSON, change its pointer width to 32 or 64 as appropriate"],"exampleFix":"// before\ncargo build --target msp430-none-elf   # 16-bit\n// after\ncargo build --target x86_64-unknown-linux-gnu","handlingStrategy":"validation","validationCode":"// shell\nRUSTC_TARGET=<your-triple>; PW=$(rustc --print target-spec-json -Z unstable-options --target $RUSTC_TARGET 2>/dev/null | grep -o '\"data-layout\"' >/dev/null && echo check || echo check); rustc --print cfg --target $RUSTC_TARGET | grep target_pointer_width","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Only compile pyo3 crates for 32- or 64-bit targets","Feature-gate Python extension code out of embedded builds","Validate custom target JSONs declare standard pointer widths"],"tags":["rust","pyo3","cross-compilation","pointer-width","build-time"],"backgroundTag":"unsupported-target-architecture","analyzedSha":"ac9b6899d348be4d54614d060dea53a645a12e36","analyzedAt":"2026-09-05T09:20:35.319Z","contentChangedAt":"2026-09-05T09:20:35.319Z","schemaVersion":2},"datasetVersion":"2026-09-12T12:17:11.808Z"}