Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add install_only_stripped binaries to release #279

Merged
merged 4 commits into from
Jul 21, 2024
Merged

Conversation

charliermarsh
Copy link
Member

@charliermarsh charliermarsh commented Jul 14, 2024

Summary

This PR adds an install_only_stripped variant, which is generated by taking the install_only variant and removing debug symbols.

Closes #277.
Closes #174.
Related to #275.

Test Plan

On macOS:

  • Downloaded cpython-3.10.14+20240713-aarch64-apple-darwin-install_only.tar.gz locally.
  • Ran: cargo run convert-install-only-stripped cpython-3.10.14+20240713-aarch64-apple-darwin-install_only.tar.gz.
  • Relocated cpython-3.10.14+20240713-aarch64-apple-darwin-install_only_stripped.tar.gz to another directory.
  • Unzipped cpython-3.10.14+20240713-aarch64-apple-darwin-install_only.tar.gz.
  • Ran ./python in python/python/bin.

Performed the same procedure on Windows.

src/release.rs Outdated Show resolved Hide resolved
src/release.rs Outdated Show resolved Hide resolved
src/release.rs Outdated Show resolved Hide resolved
src/release.rs Outdated Show resolved Hide resolved
src/release.rs Outdated Show resolved Hide resolved
src/release.rs Outdated Show resolved Hide resolved
src/release.rs Outdated Show resolved Hide resolved
@charliermarsh
Copy link
Member Author

Thanks for the review, will revise.

@charliermarsh
Copy link
Member Author

@indygreg - Did you have a specific approach in mind for getting llvm-strip onto the host machine? My current plan was to add a bootstrap-llvm.py script that downloads and untars LLVM (based on the URLs in downloads.py) to a local directory, then assume a specific location (e.g., ./llvm/bin/llvm-strip) in the release script. I could also make it all temporary within the release script.

@charliermarsh
Copy link
Member Author

Actually, I'll just do the bootstrapping in Rust as part of the release script.

@charliermarsh charliermarsh force-pushed the charlie/strip branch 2 times, most recently from e97e68c to 68c26fd Compare July 14, 2024 23:22

let llvm_dir = PathBuf::from("llvm");

// If `llvm` is already available with the target version, return it.
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We can also just store this in a temporary directory for the duration of the command. It's a little tedious when iterating locally, since LLVM is large and you then have to re-download every time, but I don't feel strongly about keeping this.

@charliermarsh charliermarsh requested a review from indygreg July 14, 2024 23:23
@charliermarsh charliermarsh marked this pull request as ready for review July 14, 2024 23:23
@indygreg
Copy link
Collaborator

I would install the LLVM distributions this project already uses: those are known to work.

But if you want to take a shortcut, since the release automation is done in GitHub Actions now, I believe the LLVM packages on Ubuntu should be able to strip Mach-O binaries as well. If it works, that's path of least resistance.

@charliermarsh
Copy link
Member Author

👍 That’s what I opted for here — reusing the existing LLVM builds.

Copy link
Collaborator

@indygreg indygreg left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This looks great!

Don't forget to update the docs with information on the new artifacts.

fn llvm_strip(data: &[u8], llvm_dir: &Path) -> Result<Vec<u8>> {
let mut command = Command::new(llvm_dir.join("bin/llvm-strip"))
.arg("--strip-debug")
.arg("-")
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Oh, I didn't realize you could feed input via stdin. That's a nifty feature!

Comment on lines +453 to +463
if cfg!(target_os = "macos") {
if std::env::consts::ARCH == "aarch64" {
Url::parse("https://github.com/indygreg/toolchain-tools/releases/download/toolchain-bootstrap%2F20240713/llvm-18.0.8+20240713-aarch64-apple-darwin.tar.zst").unwrap()
} else if std::env::consts::ARCH == "x86_64" {
Url::parse("https://github.com/indygreg/toolchain-tools/releases/download/toolchain-bootstrap%2F20240713/llvm-18.0.8+20240713-x86_64-apple-darwin.tar.zst").unwrap()
} else {
panic!("unsupported macOS architecture");
}
} else if cfg!(target_os = "linux") {
Url::parse("https://github.com/indygreg/toolchain-tools/releases/download/toolchain-bootstrap%2F20240713/llvm-18.0.8+20240713-gnu_only-x86_64-unknown-linux-gnu.tar.zst").unwrap()
} else {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I've long thought about moving the download URLs / digests into a YAML file so we're not editing Python sources to upgrade dependencies. That would open the door to automatically detecting and applying available updates. Now this code is a potential new consumer of that YAML file.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I like that idea -- I'll do it separately.

src/release.rs Outdated Show resolved Hide resolved
Comment on lines +497 to +505
while let Some(chunk) = bytes_stream.next().await {
tokio::io::copy(&mut chunk?.as_ref(), &mut tarball_file).await?;
}

// Decompress the tarball.
let tarball = std::fs::File::open(&tarball_path)?;
let tar = zstd::stream::Decoder::new(std::io::BufReader::new(tarball))?;
let mut archive = tar::Archive::new(tar);
archive.unpack(temp_dir.path())?;
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There might be a way to do this without having to buffer the entire file first. But it's probably not worth the optimization.

@charliermarsh
Copy link
Member Author

Thanks for the great review!

Regarding the docs: I didn't go as far as to recommend them over the install_only archives, but let me know if you feel we should.

Copy link
Collaborator

@indygreg indygreg left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Changes look great!

Please squash commits when merging since the intermediate commits don't add much value to the commit history. (I try to keep the commit history in the main branch pretty clean and easy to reason about.)

@charliermarsh
Copy link
Member Author

👍 I do the same in all of my own projects :)

@charliermarsh charliermarsh merged commit 4a95986 into main Jul 21, 2024
239 checks passed
@charliermarsh charliermarsh deleted the charlie/strip branch July 21, 2024 11:34
@charliermarsh
Copy link
Member Author

Before and after sizes:

  • cpython-3.10.14+20240713-aarch64-apple-darwin: 17299450 -> 17174780
  • cpython-3.10.14+20240713-aarch64-unknown-linux-gnu: 24906983 -> 19527183
  • cpython-3.10.14+20240713-armv7-unknown-linux-gnueabi: 24707416 -> 19652900
  • cpython-3.10.14+20240713-armv7-unknown-linux-gnueabihf: 24152010 -> 19104999
  • cpython-3.10.14+20240713-i686-pc-windows-msvc: 35381174 -> 21363964
  • cpython-3.10.14+20240713-i686-pc-windows-msvc-shared: 35381174 -> 21363964
  • cpython-3.10.14+20240713-ppc64le-unknown-linux-gnu: 25748321 -> 20235181
  • cpython-3.10.14+20240713-s390x-unknown-linux-gnu: 26341932 -> 20657976
  • cpython-3.10.14+20240713-x86_64-apple-darwin: 17645695 -> 17533155
  • cpython-3.10.14+20240713-x86_64-pc-windows-msvc: 36224603 -> 22352832
  • cpython-3.10.14+20240713-x86_64-pc-windows-msvc-shared: 36224603 -> 22352832
  • cpython-3.10.14+20240713-x86_64-unknown-linux-gnu: 27404483 -> 20599597
  • cpython-3.10.14+20240713-x86_64-unknown-linux-musl: 25688602 -> 19900914
  • cpython-3.10.14+20240713-x86_64_v2-unknown-linux-gnu: 27297552 -> 20513601
  • cpython-3.10.14+20240713-x86_64_v2-unknown-linux-musl: 25667025 -> 19898580
  • cpython-3.10.14+20240713-x86_64_v3-unknown-linux-gnu: 27336616 -> 20548359
  • cpython-3.10.14+20240713-x86_64_v3-unknown-linux-musl: 25757753 -> 19973510
  • cpython-3.10.14+20240713-x86_64_v4-unknown-linux-gnu: 26649878 -> 20357072
  • cpython-3.10.14+20240713-x86_64_v4-unknown-linux-musl: 25760648 -> 19975807
  • cpython-3.11.9+20240713-aarch64-apple-darwin: 17909691 -> 17740367
  • cpython-3.11.9+20240713-aarch64-unknown-linux-gnu: 26061137 -> 20098652
  • cpython-3.11.9+20240713-armv7-unknown-linux-gnueabi: 25830776 -> 20180680
  • cpython-3.11.9+20240713-armv7-unknown-linux-gnueabihf: 25265909 -> 19627899
  • cpython-3.11.9+20240713-i686-pc-windows-msvc: 40305103 -> 24355887
  • cpython-3.11.9+20240713-i686-pc-windows-msvc-shared: 40305103 -> 24355887
  • cpython-3.11.9+20240713-ppc64le-unknown-linux-gnu: 26914444 -> 20805736
  • cpython-3.11.9+20240713-s390x-unknown-linux-gnu: 27607428 -> 21265402
  • cpython-3.11.9+20240713-x86_64-apple-darwin: 18295672 -> 18142840
  • cpython-3.11.9+20240713-x86_64-pc-windows-msvc: 41271034 -> 25455255
  • cpython-3.11.9+20240713-x86_64-pc-windows-msvc-shared: 41271034 -> 25455255
  • cpython-3.11.9+20240713-x86_64-unknown-linux-gnu: 29814546 -> 21321201
  • cpython-3.11.9+20240713-x86_64-unknown-linux-musl: 28061381 -> 20627197
  • cpython-3.11.9+20240713-x86_64_v2-unknown-linux-gnu: 29592431 -> 21242246
  • cpython-3.11.9+20240713-x86_64_v2-unknown-linux-musl: 28035086 -> 20622818
  • cpython-3.11.9+20240713-x86_64_v3-unknown-linux-gnu: 29592311 -> 21282165
  • cpython-3.11.9+20240713-x86_64_v3-unknown-linux-musl: 28151530 -> 20711354
  • cpython-3.11.9+20240713-x86_64_v4-unknown-linux-gnu: 28831326 -> 21080799
  • cpython-3.11.9+20240713-x86_64_v4-unknown-linux-musl: 28154690 -> 20712214
  • cpython-3.12.4+20240713-aarch64-apple-darwin: 16793087 -> 16602293
  • cpython-3.12.4+20240713-aarch64-unknown-linux-gnu: 25622381 -> 19090942
  • cpython-3.12.4+20240713-armv7-unknown-linux-gnueabi: 25341952 -> 19188929
  • cpython-3.12.4+20240713-armv7-unknown-linux-gnueabihf: 24814756 -> 18640252
  • cpython-3.12.4+20240713-i686-pc-windows-msvc: 40024080 -> 23123258
  • cpython-3.12.4+20240713-i686-pc-windows-msvc-shared: 40024080 -> 23123258
  • cpython-3.12.4+20240713-ppc64le-unknown-linux-gnu: 26520586 -> 19826965
  • cpython-3.12.4+20240713-s390x-unknown-linux-gnu: 27296463 -> 20290628
  • cpython-3.12.4+20240713-x86_64-apple-darwin: 17125560 -> 16955240
  • cpython-3.12.4+20240713-x86_64-pc-windows-msvc: 41012060 -> 24244457
  • cpython-3.12.4+20240713-x86_64-pc-windows-msvc-shared: 41012060 -> 24244457
  • cpython-3.12.4+20240713-x86_64-unknown-linux-gnu: 63306192 -> 22349158
  • cpython-3.12.4+20240713-x86_64-unknown-linux-musl: 50956810 -> 19620466
  • cpython-3.12.4+20240713-x86_64_v2-unknown-linux-gnu: 66818248 -> 22310884
  • cpython-3.12.4+20240713-x86_64_v2-unknown-linux-musl: 50937311 -> 19618341
  • cpython-3.12.4+20240713-x86_64_v3-unknown-linux-gnu: 66872174 -> 22359326
  • cpython-3.12.4+20240713-x86_64_v3-unknown-linux-musl: 51064520 -> 19714374
  • cpython-3.12.4+20240713-x86_64_v4-unknown-linux-gnu: 57366448 -> 20152019
  • cpython-3.12.4+20240713-x86_64_v4-unknown-linux-musl: 51070488 -> 19723916
  • cpython-3.8.19+20240713-aarch64-apple-darwin: 17652273 -> 17536906
  • cpython-3.8.19+20240713-aarch64-unknown-linux-gnu: 24743115 -> 19902524
  • cpython-3.8.19+20240713-i686-pc-windows-msvc: 35932287 -> 20788438
  • cpython-3.8.19+20240713-i686-pc-windows-msvc-shared: 35932287 -> 20788438
  • cpython-3.8.19+20240713-x86_64-apple-darwin: 17970036 -> 17866487
  • cpython-3.8.19+20240713-x86_64-pc-windows-msvc: 36977773 -> 21864341
  • cpython-3.8.19+20240713-x86_64-pc-windows-msvc-shared: 36977773 -> 21864341
  • cpython-3.8.19+20240713-x86_64-unknown-linux-gnu: 26606908 -> 20952060
  • cpython-3.8.19+20240713-x86_64-unknown-linux-musl: 24864061 -> 20234166
  • cpython-3.9.19+20240713-aarch64-apple-darwin: 16802018 -> 16676228
  • cpython-3.9.19+20240713-aarch64-unknown-linux-gnu: 24184610 -> 19039375
  • cpython-3.9.19+20240713-armv7-unknown-linux-gnueabi: 23993669 -> 19168583
  • cpython-3.9.19+20240713-armv7-unknown-linux-gnueabihf: 23435860 -> 18620498
  • cpython-3.9.19+20240713-i686-pc-windows-msvc: 37055015 -> 21054914
  • cpython-3.9.19+20240713-i686-pc-windows-msvc-shared: 37055015 -> 21054914
  • cpython-3.9.19+20240713-ppc64le-unknown-linux-gnu: 25010881 -> 19740177
  • cpython-3.9.19+20240713-s390x-unknown-linux-gnu: 25584391 -> 20152690
  • cpython-3.9.19+20240713-x86_64-apple-darwin: 17131429 -> 17019871
  • cpython-3.9.19+20240713-x86_64-pc-windows-msvc: 38099841 -> 22146904
  • cpython-3.9.19+20240713-x86_64-pc-windows-msvc-shared: 38099841 -> 22146904
  • cpython-3.9.19+20240713-x86_64-unknown-linux-gnu: 26339346 -> 20084265
  • cpython-3.9.19+20240713-x86_64-unknown-linux-musl: 24896726 -> 19450953
  • cpython-3.9.19+20240713-x86_64_v2-unknown-linux-gnu: 26202076 -> 20007446
  • cpython-3.9.19+20240713-x86_64_v2-unknown-linux-musl: 24862465 -> 19452593
  • cpython-3.9.19+20240713-x86_64_v3-unknown-linux-gnu: 26238116 -> 20042990
  • cpython-3.9.19+20240713-x86_64_v3-unknown-linux-musl: 24966229 -> 19523167
  • cpython-3.9.19+20240713-x86_64_v4-unknown-linux-gnu: 25802101 -> 19910804
  • cpython-3.9.19+20240713-x86_64_v4-unknown-linux-musl: 24965941 -> 19527721

Very impactful for Linux and Windows builds (nearly 50% for Windows), almost no impact on macOS interestingly.

@jfcherng
Copy link

Hi @charliermarsh , thanks for this PR but I didn't see an obvious size change between

  • cpython-3.12.4+20240713-x86_64-unknown-linux-gnu-install_only
  • cpython-3.12.4+20240725-x86_64-unknown-linux-gnu-install_only_stripped

image

I guess something goes wrong?

@charliermarsh
Copy link
Member Author

Apologies, I think I messed up the release and uploaded the non-stripped binaries under install_only_stripped.

@charliermarsh
Copy link
Member Author

Fixing and cutting another release when builds complete: #291

zanieb pushed a commit to zanieb/python-build-standalone that referenced this pull request Sep 4, 2024
This PR adds an `install_only_stripped` variant, which is generated by taking the `install_only` variant and removing debug symbols.

Closes astral-sh#277.
Closes astral-sh#174.
Related to astral-sh#275.

On macOS:

- Downloaded [cpython-3.10.14+20240713-aarch64-apple-darwin-install_only.tar.gz](https://github.com/indygreg/python-build-standalone/releases/download/20240713/cpython-3.10.14+20240713-aarch64-apple-darwin-install_only.tar.gz) locally.
- Ran: `cargo run convert-install-only-stripped cpython-3.10.14+20240713-aarch64-apple-darwin-install_only.tar.gz`.
- Relocated `cpython-3.10.14+20240713-aarch64-apple-darwin-install_only_stripped.tar.gz` to another directory.
- Unzipped `cpython-3.10.14+20240713-aarch64-apple-darwin-install_only.tar.gz`.
- Ran `./python` in `python/python/bin`.

Performed the same procedure on Windows.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

install_only builds should be stripped? FR: remove debug symbols from Windows install_only builds
3 participants