{"record":{"id":"d93768afa618e6f9","repo":"PyO3/pyo3","slug":"your-rust-target-architecture-bit-does-not-ma","errorCode":null,"errorMessage":"your Rust target architecture ({}-bit) does not match your python interpreter ({}-bit)","messagePattern":"your Rust target architecture \\((.+?)-bit\\) does not match your python interpreter \\((.+?)-bit\\)","errorType":"console","errorClass":null,"httpStatus":null,"severity":"error","filePath":"pyo3-ffi/build.rs","lineNumber":184,"sourceCode":"        }\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!(\n        lib_name,\n        \"python3\" | \"python3_d\" | \"python3t\" | \"python3t_d\"\n    ) {","sourceCodeStart":166,"sourceCodeEnd":202,"githubUrl":"https://github.com/PyO3/pyo3/blob/ac9b6899d348be4d54614d060dea53a645a12e36/pyo3-ffi/build.rs#L166-L202","documentation":"The build script compares the Rust target's pointer width with the pointer width reported by the Python interpreter configuration and aborts on mismatch, since a pyo3 extension module must be compiled for the same word size as the interpreter.","triggerScenarios":"Cross-compiling with a Rust target whose pointer width differs from the configured Python (e.g. building for i686/aarch32 Rust target against 64-bit Python, or vice versa), inside ensure_target_pointer_width.","commonSituations":"Cross-compiling wheels for 32-bit platforms using the host's 64-bit Python; mixed 32/64-bit Python installs on Windows; wrong CC/PYTHON targets in CI cross jobs.","solutions":["Use a Python interpreter matching the Rust target's pointer width (e.g. 32-bit Python for a 32-bit target)","Set PYO3_CROSS / PYO3_CROSS_PYTHON_VERSION and PYO3_CROSS_PYTHON_IMPLEMENTATION for cross builds instead of pointing at host Python","Change the Rust target (rustup target) to match the Python bitness","Verify with python -c \"import struct; print(struct.calcsize('P')*8)\" and rustc --print target-pointer-width"],"exampleFix":"// before\ncargo build --target i686-unknown-linux-gnu   # using 64-bit python3\n// after\nPYO3_CROSS_PYTHON_VERSION=3.12 cargo build --target i686-unknown-linux-gnu\n# or use a 32-bit python interpreter","handlingStrategy":"validation","validationCode":"import struct, os, subprocess\ndef python_bits(): return struct.calcsize(\"P\") * 8\ndef rust_target_bits(target):\n    return 64 if \"64\" in target or \"aarch64\" in target or \"x86_64\" in target else 32\n# assert python_bits() == rust_target_bits(os.environ.get(\"CARGO_BUILD_TARGET\", \"x86_64\"))","typeGuard":null,"tryCatchPattern":null,"preventionTips":["In cross-compilation, always set PYO3_CROSS_PYTHON_VERSION / PYO3_CROSS_PYTHON_IMPLEMENTATION instead of relying on host Python","Use maturin/cibuildwheel which manage matching interpreters per target","Verify pointer widths before starting cross builds","Keep separate 32-bit Python installs for 32-bit targets"],"tags":["rust","cross-compilation","pointer-width","build"],"backgroundTag":"pointer-width-mismatch","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"}