Skip to content

Commit 41add82

Browse files
committed
WIP test for new build system design
1 parent e776700 commit 41add82

13 files changed

Lines changed: 153 additions & 61 deletions

File tree

Cargo.lock

Lines changed: 15 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
[workspace]
22
resolver = "3"
33
members = [
4-
"Modules/_base64",
4+
"Modules/_base64", "Modules/cpython-build-helper", "Modules/cpython-rust-staticlib",
55
"Modules/cpython-sys"
66
]

Makefile.pre.in

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -178,7 +178,8 @@ CONFINCLUDEPY= $(CONFINCLUDEDIR)/python$(LDVERSION)
178178
SHLIB_SUFFIX= @SHLIB_SUFFIX@
179179
EXT_SUFFIX= @EXT_SUFFIX@
180180
LDSHARED= @LDSHARED@ $(PY_LDFLAGS)
181-
BLDSHARED= @BLDSHARED@ $(PY_CORE_LDFLAGS)
181+
BLDSHARED_EXE= @BLDSHARED_EXE@
182+
BLDSHARED_ARGS= @BLDSHARED_ARGS@ $(PY_CORE_LDFLAGS)
182183
LDCXXSHARED= @LDCXXSHARED@ $(PY_LDFLAGS)
183184
DESTSHARED= $(BINLIBDEST)/lib-dynload
184185

Modules/_base64/Cargo.toml

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,10 @@ edition = "2024"
66
[dependencies]
77
cpython-sys ={ path = "../cpython-sys" }
88

9+
[build-dependencies]
10+
cpython-build-helper = { path = "../cpython-build-helper" }
11+
912
[lib]
1013
name = "_base64"
11-
crate-type = ["staticlib"]
14+
# For shared builds, we generate a c dynamic library. Static builds use the rlib
15+
crate-type = ["cdylib", "rlib"]

Modules/_base64/build.rs

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
use cpython_build_helper::print_linker_args;
2+
3+
fn main() {
4+
print_linker_args();
5+
}
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
[package]
2+
name = "cpython-build-helper"
3+
version = "0.1.0"
4+
edition = "2024"
5+
6+
[dependencies]
7+
shlex = "1.3"
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
# cpython-build-helper
2+
3+
This crate is used in Rust modules `build.rs` files to help do common tasks such
4+
as passing necessary link arguments.
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
use std::env;
2+
3+
/// Print necessary link arguments for the library depending on the build
4+
/// configuration (static or shared)
5+
pub fn print_linker_args() {
6+
let shared_build = env::var("RUST_SHARED_BUILD").expect("RUST_SHARED_BUILD not set in Makefile?");
7+
if shared_build == "1" {
8+
let build_shared_args =
9+
env::var("BLDSHARED_ARGS").expect("BLDSHARED_ARGS not set in Makefile?");
10+
// TODO(emmatyping): Ideally, we would not need to split the args here and take shlex
11+
// as a dependency.
12+
for arg in shlex::split(&build_shared_args).expect("Invalid BUILDSHARED_ARGS") {
13+
println!("cargo:rustc-link-arg={}", arg);
14+
}
15+
}
16+
// Static linker configuration is in cpython-rust-staticlib
17+
}
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
[package]
2+
name = "cpython-rust-staticlib"
3+
version = "0.1.0"
4+
edition = "2024"
5+
6+
[dependencies]
7+
_base64 ={ path = "../_base64" }
8+
9+
[lib]
10+
name = "cpython_rust_staticlib"
11+
crate-type = ["staticlib"]
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
pub use _base64::PyInit__base64;

0 commit comments

Comments
 (0)