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

generate individual checksum file for each target #84

Merged
merged 4 commits into from
Mar 24, 2024

Conversation

cocoa-xu
Copy link
Contributor

Hi this PR improves user experience by generating a checksum file for each target and assembling the final checksum.exs file using the generated checksum files over the actual binary files.

This can be useful because if the binaries need to be compiled in different CI runners, for example, separate runners for Linux, macOS and Windows, where we cannot produce the final checksum.exs right away on CI -- currently we have to download all precompiled binaries just to build the final checksum.exs file, and it costs disk space and time to do so especially when the binaries are huge.

This feature is on by default but it requires users to include the generated .sha256 files in the GitHub release. If the .sha256 file cannot be downloaded (no matter it's because of a network error or it's missing in the GitHub release), the precompiled binaries will be downloaded to calculate the checksum (as what we're currently doing on the master branch).

In addition to that, this PR opens a chance for us to (maybe optionally) ditch away the checksum.exs file (somewhat a double edged sword), because it cannot be changed after it's released to hex.pm (IIRC it's 30 minutes or 1 hour-ish); so if the library author missed anything, they have to release a new version which means to go through the whole process again.

Of course, one of the pros of using a checksum.exs file is that it prevents situations like network error or supply chain attacks (e.g., attackers re-upload these binaries with malicious code).

@josevalim
Copy link
Member

@cocoa-xu the main purpose of checksum.exs in my opinion is to avoid supply chain attacks, so I don't think we should avoid it. If we want to improve this, I think we should send pull requests to Hex.pm to allow metadata to be attached to packages. I will add a TODO list for the Dashbit team to tackle it (but most likely only Q3-Q4).

However, to address your CI issues, we can download the .sha256 files when building the checksum.exs itself, but that's it. WDYT?

@cocoa-xu
Copy link
Contributor Author

However, to address your CI issues, we can download the .sha256 files when building the checksum.exs itself, but that's it. WDYT?

Yeah, that's what this PR is doing/adding to elixir_make.

the main purpose of checksum.exs in my opinion is to avoid supply chain attacks, so I don't think we should avoid it.

True, I also kinda hesitated when suggesting the idea of ditching away checksum.exs.

if we want to improve this, I think we should send pull requests to Hex.pm to allow metadata to be attached to packages. I will add a TODO list for the Dashbit team to tackle it (but most likely only Q3-Q4).

No problem! Let's discuss this later/

@josevalim
Copy link
Member

Perfect then, I dropped some suggestions and you can merge whenever. :) Once it has tested a bit, please let me know and I can do a new release :)

@cocoa-xu
Copy link
Contributor Author

Thank you Jose! I don't have write access to this repository but I can do some tests first and let you know if this PR is ready. ;)

@cocoa-xu
Copy link
Contributor Author

Hi Jose I fixed a minor issue and tested this PR here using the following script:

mix deps.get
mix elixir_make.checksum --all

targets=(
  aarch64-apple-darwin
  aarch64-linux-gnu
  armv7l-linux-gnueabihf
  i686-linux-gnu
  powerpc64le-linux-gnu
  riscv64-linux-gnu
  s390x-linux-gnu
  x86_64-apple-darwin
  x86_64-linux-gnu
  x86_64-windows-msvc
)
echo "%{" > manual-checksum.exs
for target in "${targets[@]}"; do
  export FILENAME=stb_image-nif-2.16-${target}-0.6.9.tar.gz
  curl -fSsL https://github.com/cocoa-xu/stb_image/releases/download/v0.6.9/${FILENAME}.sha256 -o ${FILENAME}.sha256
  curl -fSsL https://github.com/cocoa-xu/stb_image/releases/download/v0.6.9/${FILENAME} -o ${FILENAME}
  sha256sum -c ${FILENAME}.sha256 && echo "  \"${FILENAME}\" => \"sha256:$(sha256sum ${FILENAME} | cut -d' ' -f1)\"," >> manual-checksum.exs
done
echo "}" >> manual-checksum.exs

cat checksum.exs
cat manual-checksum.exs
diff checksum.exs manual-checksum.exs

And the result looks okay to me. :)

==> stb_image
NIF checksum file with checksum 99487fac89d8be9b74a112bd357c163e572ef192a96b0d330987942116e2b478 (sha256)
NIF checksum file with checksum fc40a4b7f383f221fb51f48daf4589f30c893948a433bed4a271f78151a0f153 (sha256)
NIF checksum file with checksum 88d3a580be0e2a1de085ad60e45d3fd3bd7b15625f94f17380e68b3a371d9acf (sha256)
NIF checksum file with checksum 1ed4dc04dc9f234e8ca37163a85d12f49ad3b97ce2d6a6498d2e6b6e365df728 (sha256)
NIF checksum file with checksum a6545de2ff8c53563bf259b13f6e279ffe66cae1806e5ead200d458050f1048c (sha256)
NIF checksum file with checksum c6800a803f19a880c7e26cc9c7a4822c74155db3795de5768f36d6c7bb2bc716 (sha256)
NIF checksum file with checksum 28edc687011e6709b8406d0b0ce44e463dd26d73fc711d908a03c32e3f947507 (sha256)
NIF checksum file with checksum 1a098f200975502f42f6b82f88c389366d8ec67e26e7a5a22391f678492aee22 (sha256)
NIF checksum file with checksum 5da8b1fd6dce52c4f01dc48f4137fb8e95a14fc5d9e1078e7d28aed80afa7f79 (sha256)
NIF checksum file with checksum 0d8792f4f10be319be96d5d845c80d4c099e2f60e79ac6ab33c4bbafa8c3869f (sha256)
stb_image-nif-2.16-aarch64-apple-darwin-0.6.9.tar.gz: OK
stb_image-nif-2.16-aarch64-linux-gnu-0.6.9.tar.gz: OK
stb_image-nif-2.16-armv7l-linux-gnueabihf-0.6.9.tar.gz: OK
stb_image-nif-2.16-i686-linux-gnu-0.6.9.tar.gz: OK
stb_image-nif-2.16-powerpc64le-linux-gnu-0.6.9.tar.gz: OK
stb_image-nif-2.16-riscv64-linux-gnu-0.6.9.tar.gz: OK
stb_image-nif-2.16-s390x-linux-gnu-0.6.9.tar.gz: OK
stb_image-nif-2.16-x86_64-apple-darwin-0.6.9.tar.gz: OK
stb_image-nif-2.16-x86_64-linux-gnu-0.6.9.tar.gz: OK
stb_image-nif-2.16-x86_64-windows-msvc-0.6.9.tar.gz: OK
%{
  "stb_image-nif-2.16-aarch64-apple-darwin-0.6.9.tar.gz" => "sha256:0d8792f4f10be319be96d5d845c80d4c099e2f60e79ac6ab33c4bbafa8c3869f",
  "stb_image-nif-2.16-aarch64-linux-gnu-0.6.9.tar.gz" => "sha256:28edc687011e6709b8406d0b0ce44e463dd26d73fc711d908a03c32e3f947507",
  "stb_image-nif-2.16-armv7l-linux-gnueabihf-0.6.9.tar.gz" => "sha256:a6545de2ff8c53563bf259b13f6e279ffe66cae1806e5ead200d458050f1048c",
  "stb_image-nif-2.16-i686-linux-gnu-0.6.9.tar.gz" => "sha256:1a098f200975502f42f6b82f88c389366d8ec67e26e7a5a22391f678492aee22",
  "stb_image-nif-2.16-powerpc64le-linux-gnu-0.6.9.tar.gz" => "sha256:c6800a803f19a880c7e26cc9c7a4822c74155db3795de5768f36d6c7bb2bc716",
  "stb_image-nif-2.16-riscv64-linux-gnu-0.6.9.tar.gz" => "sha256:fc40a4b7f383f221fb51f48daf4589f30c893948a433bed4a271f78151a0f153",
  "stb_image-nif-2.16-s390x-linux-gnu-0.6.9.tar.gz" => "sha256:1ed4dc04dc9f234e8ca37163a85d12f49ad3b97ce2d6a6498d2e6b6e365df728",
  "stb_image-nif-2.16-x86_64-apple-darwin-0.6.9.tar.gz" => "sha256:5da8b1fd6dce52c4f01dc48f4137fb8e95a14fc5d9e1078e7d28aed80afa7f79",
  "stb_image-nif-2.16-x86_64-linux-gnu-0.6.9.tar.gz" => "sha256:99487fac89d8be9b74a112bd357c163e572ef192a96b0d3[309](https://github.com/cocoa-xu/stb_image/actions/runs/8409130184/job/23026147469#step:4:310)87942116e2b478",
  "stb_image-nif-2.16-x86_64-windows-msvc-0.6.9.tar.gz" => "sha256:88d3a580be0e2a1de085ad60e45d3fd3bd7b15625f94f17380e68b3a371d9acf",
}
%{
  "stb_image-nif-2.16-aarch64-apple-darwin-0.6.9.tar.gz" => "sha256:0d8792f4f10be319be96d5d845c80d4c099e2f60e79ac6ab33c4bbafa8c3869f",
  "stb_image-nif-2.16-aarch64-linux-gnu-0.6.9.tar.gz" => "sha256:28edc687011e6709b8406d0b0ce44e463dd26d73fc711d908a03c32e3f947507",
  "stb_image-nif-2.16-armv7l-linux-gnueabihf-0.6.9.tar.gz" => "sha256:a6545de2ff8c53563bf259b13f6e279ffe66cae1806e5ead200d458050f1048c",
  "stb_image-nif-2.16-i686-linux-gnu-0.6.9.tar.gz" => "sha256:1a098f200975502f42f6b82f88c389366d8ec67e26e7a5a22391f678492aee22",
  "stb_image-nif-2.16-powerpc64le-linux-gnu-0.6.9.tar.gz" => "sha256:c6800a803f19a880c7e26cc9c7a4822c74155db3795de5768f36d6c7bb2bc716",
  "stb_image-nif-2.16-riscv64-linux-gnu-0.6.9.tar.gz" => "sha256:fc40a4b7f383f221fb51f48daf4589f30c893948a433bed4a271f78151a0f153",
  "stb_image-nif-2.16-s390x-linux-gnu-0.6.9.tar.gz" => "sha256:1ed4dc04dc9f234e8ca37163a85d12f49ad3b97ce2d6a6498d2e6b6e365df728",
  "stb_image-nif-2.16-x86_64-apple-darwin-0.6.9.tar.gz" => "sha256:5da8b1fd6dce52c4f01dc48f4137fb8e95a14fc5d9e1078e7d28aed80afa7f79",
  "stb_image-nif-2.16-x86_64-linux-gnu-0.6.9.tar.gz" => "sha256:99487fac89d8be9b74a112bd357c163e572ef192a96b0d330987942116e2b478",
  "stb_image-nif-2.16-x86_64-windows-msvc-0.6.9.tar.gz" => "sha256:88d3a580be0e2a1de085ad60e45d3fd3bd7b15625f94f17380e68b3a371d9acf",
}

@josevalim josevalim merged commit 22a5511 into elixir-lang:master Mar 24, 2024
2 checks passed
@josevalim
Copy link
Member

💚 💙 💜 💛 ❤️

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Development

Successfully merging this pull request may close these issues.

2 participants