@@ -142,36 +142,44 @@ impl CrossCompileConfig {
142
142
}
143
143
144
144
fn cross_compiling ( ) -> Result < Option < CrossCompileConfig > > {
145
- let target = env:: var ( "TARGET" ) ?;
146
- let host = env:: var ( "HOST" ) ?;
147
- if target == host {
148
- // Not cross-compiling
149
- return Ok ( None ) ;
150
- }
145
+ if env:: var_os ( "PYO3_CROSS" ) . is_none ( )
146
+ && env:: var_os ( "PYO3_CROSS_LIB_DIR" ) . is_none ( )
147
+ && env:: var_os ( "PYO3_CROSS_INCLUDE_DIR" ) . is_none ( )
148
+ && env:: var_os ( "PYO3_CROSS_VERSION" ) . is_none ( )
149
+ && env:: var_os ( "PYO3_CROSS_PYTHON_VERSION" ) . is_none ( )
150
+ {
151
+ let target = env:: var ( "TARGET" ) ?;
152
+ let host = env:: var ( "HOST" ) ?;
153
+ if target == host {
154
+ // Not cross-compiling
155
+ return Ok ( None ) ;
156
+ }
151
157
152
- if target == "i686-pc-windows-msvc" && host == "x86_64-pc-windows-msvc" {
153
- // Not cross-compiling to compile for 32-bit Python from windows 64-bit
154
- return Ok ( None ) ;
155
- }
158
+ if target == "i686-pc-windows-msvc" && host == "x86_64-pc-windows-msvc" {
159
+ // Not cross-compiling to compile for 32-bit Python from windows 64-bit
160
+ return Ok ( None ) ;
161
+ }
156
162
157
- if target == "x86_64-apple-darwin" && host == "aarch64-apple-darwin" {
158
- // Not cross-compiling to compile for x86-64 Python from macOS arm64
159
- return Ok ( None ) ;
160
- }
161
- if target == "aarch64-apple-darwin" && host == "x86_64-apple-darwin" {
162
- // Not cross-compiling to compile for arm64 Python from macOS x86_64
163
- return Ok ( None ) ;
164
- }
163
+ if target == "x86_64-apple-darwin" && host == "aarch64-apple-darwin" {
164
+ // Not cross-compiling to compile for x86-64 Python from macOS arm64
165
+ return Ok ( None ) ;
166
+ }
165
167
166
- if host. starts_with ( & format ! (
167
- "{}-{}-{}" ,
168
- env:: var( "CARGO_CFG_TARGET_ARCH" ) ?,
169
- env:: var( "CARGO_CFG_TARGET_VENDOR" ) ?,
170
- env:: var( "CARGO_CFG_TARGET_OS" ) ?
171
- ) ) {
172
- // Not cross-compiling if arch-vendor-os is all the same
173
- // e.g. x86_64-unknown-linux-musl on x86_64-unknown-linux-gnu host
174
- return Ok ( None ) ;
168
+ if target == "aarch64-apple-darwin" && host == "x86_64-apple-darwin" {
169
+ // Not cross-compiling to compile for arm64 Python from macOS x86_64
170
+ return Ok ( None ) ;
171
+ }
172
+
173
+ if host. starts_with ( & format ! (
174
+ "{}-{}-{}" ,
175
+ env:: var( "CARGO_CFG_TARGET_ARCH" ) ?,
176
+ env:: var( "CARGO_CFG_TARGET_VENDOR" ) ?,
177
+ env:: var( "CARGO_CFG_TARGET_OS" ) ?
178
+ ) ) {
179
+ // Not cross-compiling if arch-vendor-os is all the same
180
+ // e.g. x86_64-unknown-linux-musl on x86_64-unknown-linux-gnu host
181
+ return Ok ( None ) ;
182
+ }
175
183
}
176
184
177
185
// Cross-compiling on any other platform
0 commit comments