libpng 1.6.58.1-x64-mingw-ucrt
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +7 -0
- data/.github/workflows/build.yml +190 -0
- data/.github/workflows/release.yml +281 -0
- data/.gitignore +17 -0
- data/.rspec +3 -0
- data/.rubocop.yml +39 -0
- data/Gemfile +12 -0
- data/LICENSE.txt +27 -0
- data/README.adoc +108 -0
- data/Rakefile +73 -0
- data/bin/console +5 -0
- data/bin/setup +5 -0
- data/ext/extconf.rb +12 -0
- data/lib/libpng/libpng16.dll +0 -0
- data/lib/libpng/recipe.rb +239 -0
- data/lib/libpng/version.rb +16 -0
- data/lib/libpng.rb +297 -0
- data/libpng.gemspec +38 -0
- metadata +80 -0
checksums.yaml
ADDED
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
---
|
|
2
|
+
SHA256:
|
|
3
|
+
metadata.gz: ad76d158a0e6ff53dd1d1e13cf2b6163bf73cf091c841c5fb00a726c415b1f1e
|
|
4
|
+
data.tar.gz: 04611330dd45ef2e54a8b142d6a0725dce063feba50d65e0c3ac6b18fabc0d0a
|
|
5
|
+
SHA512:
|
|
6
|
+
metadata.gz: d2e89781eae193ea655d05b09245cf46dd11e1ab16272c3b42c11ee69d555b7dd731fe7a9f9f7c9c7375e4b02f687e8d5b1892dba1d9a4bf0559639ce15de0d0
|
|
7
|
+
data.tar.gz: b0ba1acbf38dd84802c3690813513f0c98551cde1173d06cd5f23c480550d5b883b0f176c69e71c5244022ae20e1780eceac43db08fd012687f678d4c09533b6
|
|
@@ -0,0 +1,190 @@
|
|
|
1
|
+
name: build
|
|
2
|
+
|
|
3
|
+
on:
|
|
4
|
+
push:
|
|
5
|
+
branches: [ main ]
|
|
6
|
+
paths-ignore:
|
|
7
|
+
- '*.adoc'
|
|
8
|
+
pull_request:
|
|
9
|
+
workflow_dispatch:
|
|
10
|
+
|
|
11
|
+
concurrency:
|
|
12
|
+
group: '${{ github.workflow }}-${{ github.job }}-${{ github.head_ref || github.ref_name }}'
|
|
13
|
+
cancel-in-progress: true
|
|
14
|
+
|
|
15
|
+
jobs:
|
|
16
|
+
prepare:
|
|
17
|
+
uses: metanorma/ci/.github/workflows/prepare-rake.yml@main
|
|
18
|
+
|
|
19
|
+
test:
|
|
20
|
+
name: Test on Ruby ${{ matrix.ruby.version }} ${{ matrix.os }}
|
|
21
|
+
runs-on: ${{ matrix.os }}
|
|
22
|
+
|
|
23
|
+
needs: prepare
|
|
24
|
+
if: needs.prepare.outputs.push-for-tag != 'true'
|
|
25
|
+
|
|
26
|
+
continue-on-error: ${{ matrix.ruby.experimental }}
|
|
27
|
+
strategy:
|
|
28
|
+
fail-fast: false
|
|
29
|
+
max-parallel: 5
|
|
30
|
+
matrix: ${{ fromJson(needs.prepare.outputs.matrix) }}
|
|
31
|
+
|
|
32
|
+
steps:
|
|
33
|
+
- uses: actions/checkout@v4
|
|
34
|
+
|
|
35
|
+
- uses: ruby/setup-ruby@master
|
|
36
|
+
with:
|
|
37
|
+
bundler-cache: true
|
|
38
|
+
ruby-version: ${{ matrix.ruby.version }}
|
|
39
|
+
rubygems: ${{ matrix.ruby.rubygems }}
|
|
40
|
+
|
|
41
|
+
# libpng's CMake needs cmake >= 3.10 and a working zlib. Both are
|
|
42
|
+
# pre-installed on GitHub Actions runners; this is just a sanity check.
|
|
43
|
+
- name: Install build tools
|
|
44
|
+
if: startsWith(matrix.os, 'ubuntu')
|
|
45
|
+
run: |
|
|
46
|
+
sudo apt-get update
|
|
47
|
+
sudo apt-get install -y cmake ninja-build zlib1g-dev
|
|
48
|
+
|
|
49
|
+
- name: Install build tools (macOS)
|
|
50
|
+
if: startsWith(matrix.os, 'macos')
|
|
51
|
+
run: |
|
|
52
|
+
brew install cmake ninja
|
|
53
|
+
|
|
54
|
+
- name: Install build tools (Windows)
|
|
55
|
+
if: startsWith(matrix.os, 'windows')
|
|
56
|
+
uses: step-security/msvc-dev-cmd@v1
|
|
57
|
+
|
|
58
|
+
- run: bundle exec rake
|
|
59
|
+
|
|
60
|
+
build:
|
|
61
|
+
name: build ${{ matrix.os }}, ${{ matrix.ruby-version }}, ${{ matrix.platform }}
|
|
62
|
+
runs-on: ${{ matrix.os }}
|
|
63
|
+
needs: prepare
|
|
64
|
+
strategy:
|
|
65
|
+
fail-fast: false
|
|
66
|
+
matrix:
|
|
67
|
+
include:
|
|
68
|
+
- os: ubuntu-latest
|
|
69
|
+
platform: any
|
|
70
|
+
ruby-version: ${{ needs.prepare.outputs.default-ruby-version }}
|
|
71
|
+
- os: ubuntu-latest
|
|
72
|
+
platform: x86_64-linux
|
|
73
|
+
ruby-version: ${{ needs.prepare.outputs.default-ruby-version }}
|
|
74
|
+
- os: ubuntu-24.04-arm
|
|
75
|
+
platform: aarch64-linux
|
|
76
|
+
ruby-version: ${{ needs.prepare.outputs.default-ruby-version }}
|
|
77
|
+
- os: windows-latest
|
|
78
|
+
platform: x64-mingw32
|
|
79
|
+
ruby-version: ${{ needs.prepare.outputs.default-ruby-version }}
|
|
80
|
+
- os: windows-latest
|
|
81
|
+
platform: x64-mingw-ucrt
|
|
82
|
+
ruby-version: ${{ needs.prepare.outputs.default-ruby-version }}
|
|
83
|
+
- os: windows-11-arm
|
|
84
|
+
platform: aarch64-mingw-ucrt
|
|
85
|
+
ruby-version: '3.4'
|
|
86
|
+
- os: macos-15-intel
|
|
87
|
+
platform: x86_64-darwin
|
|
88
|
+
ruby-version: ${{ needs.prepare.outputs.default-ruby-version }}
|
|
89
|
+
- os: macos-latest
|
|
90
|
+
platform: arm64-darwin
|
|
91
|
+
ruby-version: ${{ needs.prepare.outputs.default-ruby-version }}
|
|
92
|
+
|
|
93
|
+
steps:
|
|
94
|
+
- uses: actions/checkout@v4
|
|
95
|
+
|
|
96
|
+
- name: Setup Ruby
|
|
97
|
+
uses: ruby/setup-ruby@master
|
|
98
|
+
with:
|
|
99
|
+
ruby-version: ${{ matrix.ruby-version }}
|
|
100
|
+
bundler-cache: true
|
|
101
|
+
|
|
102
|
+
- name: Install build tools (Linux)
|
|
103
|
+
if: startsWith(matrix.os, 'ubuntu')
|
|
104
|
+
run: |
|
|
105
|
+
sudo apt-get update
|
|
106
|
+
sudo apt-get install -y cmake ninja-build zlib1g-dev
|
|
107
|
+
|
|
108
|
+
- name: Install build tools (macOS)
|
|
109
|
+
if: startsWith(matrix.os, 'macos')
|
|
110
|
+
run: |
|
|
111
|
+
brew install cmake ninja
|
|
112
|
+
|
|
113
|
+
- name: Install build tools (Windows)
|
|
114
|
+
if: startsWith(matrix.os, 'windows')
|
|
115
|
+
uses: step-security/msvc-dev-cmd@v1
|
|
116
|
+
with:
|
|
117
|
+
arch: ${{ matrix.platform == 'aarch64-mingw-ucrt' && 'arm64' || 'x64' }}
|
|
118
|
+
|
|
119
|
+
- run: bundle exec rake gem:native:${{ matrix.platform }}
|
|
120
|
+
|
|
121
|
+
- uses: actions/upload-artifact@v4
|
|
122
|
+
with:
|
|
123
|
+
name: pkg-${{ matrix.platform }}
|
|
124
|
+
path: pkg/*.gem
|
|
125
|
+
|
|
126
|
+
- name: Install gem
|
|
127
|
+
run: gem install -b pkg/libpng-*.gem
|
|
128
|
+
|
|
129
|
+
- name: Test conversion
|
|
130
|
+
shell: bash
|
|
131
|
+
run: |
|
|
132
|
+
ruby -rlibpng -e 'png = Libpng.encode(2, 2, "\xff" * 16, pixel_format: "RGBA"); File.binwrite("test.png", png); puts Libpng.decode(png, pixel_format: "RGBA").inspect'
|
|
133
|
+
|
|
134
|
+
build_musl:
|
|
135
|
+
name: build ${{ matrix.platform }} (Alpine)
|
|
136
|
+
runs-on: ${{ matrix.os }}
|
|
137
|
+
needs: prepare
|
|
138
|
+
strategy:
|
|
139
|
+
fail-fast: false
|
|
140
|
+
matrix:
|
|
141
|
+
include:
|
|
142
|
+
- os: ubuntu-latest
|
|
143
|
+
platform: x86_64-linux-musl
|
|
144
|
+
- os: ubuntu-24.04-arm
|
|
145
|
+
platform: aarch64-linux-musl
|
|
146
|
+
|
|
147
|
+
steps:
|
|
148
|
+
- uses: actions/checkout@v4
|
|
149
|
+
|
|
150
|
+
# Run the entire build inside an Alpine container via `docker run` rather
|
|
151
|
+
# than the workflow `container:` field. The latter only works on x64
|
|
152
|
+
# runners (Actions' JS runtime has no arm64-musl build), but arm64 Ubuntu
|
|
153
|
+
# runners can run arm64 Alpine images natively via Docker.
|
|
154
|
+
- name: Build in Alpine container
|
|
155
|
+
shell: bash
|
|
156
|
+
env:
|
|
157
|
+
PLATFORM: ${{ matrix.platform }}
|
|
158
|
+
RUBY_VERSION: ${{ needs.prepare.outputs.default-ruby-version }}
|
|
159
|
+
run: |
|
|
160
|
+
cat > /tmp/alpine-build.sh <<'BUILD_EOF'
|
|
161
|
+
#!/bin/sh
|
|
162
|
+
set -e
|
|
163
|
+
apk add --no-cache build-base cmake ninja git file zlib-dev
|
|
164
|
+
# The mounted /work volume is owned by the host runner user; git in
|
|
165
|
+
# the container (running as root) refuses to operate on it without
|
|
166
|
+
# this. Without it, `git ls-files` in the gemspec returns empty and
|
|
167
|
+
# the built gem is missing lib/libpng.rb.
|
|
168
|
+
git config --global --add safe.directory /work
|
|
169
|
+
bundle install --jobs 4
|
|
170
|
+
bundle exec rake "gem:native:${PLATFORM}"
|
|
171
|
+
gem install -b pkg/libpng-*.gem
|
|
172
|
+
# Smoke test from /tmp so bundler's source-tree LOAD_PATH doesn't
|
|
173
|
+
# shadow the installed gem. Activate via `gem` so RubyGems resolves
|
|
174
|
+
# the platform-specific binary gem (Alpine Ruby's platform string
|
|
175
|
+
# is *-linux-musl, which must match the gem's platform suffix).
|
|
176
|
+
(cd /tmp && ruby -e 'gem "libpng"; require "libpng"; png = Libpng.encode(2, 2, "\xff" * 16, pixel_format: "RGBA"); File.binwrite("test.png", png); puts Libpng.decode(png, pixel_format: "RGBA").inspect')
|
|
177
|
+
BUILD_EOF
|
|
178
|
+
chmod +x /tmp/alpine-build.sh
|
|
179
|
+
docker run --rm \
|
|
180
|
+
-v "$PWD:/work" \
|
|
181
|
+
-v /tmp/alpine-build.sh:/alpine-build.sh \
|
|
182
|
+
-w /work \
|
|
183
|
+
-e PLATFORM \
|
|
184
|
+
ruby:${RUBY_VERSION}-alpine \
|
|
185
|
+
/alpine-build.sh
|
|
186
|
+
|
|
187
|
+
- uses: actions/upload-artifact@v4
|
|
188
|
+
with:
|
|
189
|
+
name: pkg-${{ matrix.platform }}
|
|
190
|
+
path: pkg/*.gem
|
|
@@ -0,0 +1,281 @@
|
|
|
1
|
+
name: release
|
|
2
|
+
|
|
3
|
+
on:
|
|
4
|
+
push:
|
|
5
|
+
tags:
|
|
6
|
+
- 'v*'
|
|
7
|
+
workflow_dispatch:
|
|
8
|
+
inputs:
|
|
9
|
+
bump-type:
|
|
10
|
+
description: 'What to bump before tagging'
|
|
11
|
+
type: choice
|
|
12
|
+
options:
|
|
13
|
+
- current
|
|
14
|
+
- iteration
|
|
15
|
+
- libpng
|
|
16
|
+
default: iteration
|
|
17
|
+
libpng-version:
|
|
18
|
+
description: 'New libpng version (required when bump-type=libpng, e.g. 1.6.49)'
|
|
19
|
+
type: string
|
|
20
|
+
required: false
|
|
21
|
+
|
|
22
|
+
# contents: write is needed for workflow_dispatch to push the bump commit + tag.
|
|
23
|
+
# id-token: write is required for RubyGems.org Trusted Publishing (OIDC).
|
|
24
|
+
permissions:
|
|
25
|
+
contents: write
|
|
26
|
+
id-token: write
|
|
27
|
+
|
|
28
|
+
jobs:
|
|
29
|
+
bump:
|
|
30
|
+
if: github.event_name == 'workflow_dispatch'
|
|
31
|
+
runs-on: ubuntu-latest
|
|
32
|
+
outputs:
|
|
33
|
+
sha: ${{ steps.sha.outputs.sha }}
|
|
34
|
+
new-version: ${{ steps.bump.outputs.new-version }}
|
|
35
|
+
steps:
|
|
36
|
+
- uses: actions/checkout@v4
|
|
37
|
+
|
|
38
|
+
- uses: ruby/setup-ruby@master
|
|
39
|
+
with:
|
|
40
|
+
ruby-version: '3.3'
|
|
41
|
+
|
|
42
|
+
- name: Bump version.rb
|
|
43
|
+
id: bump
|
|
44
|
+
shell: bash
|
|
45
|
+
env:
|
|
46
|
+
BUMP_TYPE: ${{ inputs.bump-type }}
|
|
47
|
+
LIBPNG_VERSION_INPUT: ${{ inputs.libpng-version }}
|
|
48
|
+
run: |
|
|
49
|
+
set -euo pipefail
|
|
50
|
+
|
|
51
|
+
if [[ "$BUMP_TYPE" == "current" ]]; then
|
|
52
|
+
NEW_VERSION=$(ruby -Ilib -rlibpng/version -e 'puts Libpng::VERSION')
|
|
53
|
+
echo "new-version=${NEW_VERSION}" >> "$GITHUB_OUTPUT"
|
|
54
|
+
echo "sha=${{ github.sha }}" >> "$GITHUB_OUTPUT"
|
|
55
|
+
echo "Releasing current VERSION (${NEW_VERSION}) -- no bump."
|
|
56
|
+
exit 0
|
|
57
|
+
fi
|
|
58
|
+
|
|
59
|
+
ruby <<'RUBY'
|
|
60
|
+
bump_type = ENV.fetch("BUMP_TYPE")
|
|
61
|
+
path = "lib/libpng/version.rb"
|
|
62
|
+
content = File.read(path)
|
|
63
|
+
|
|
64
|
+
case bump_type
|
|
65
|
+
when "iteration"
|
|
66
|
+
m = %r{LIBPNG_RUBY_ITERATION = (\d+)}.match(content) or
|
|
67
|
+
raise "Could not find LIBPNG_RUBY_ITERATION in #{path}"
|
|
68
|
+
content.sub!(%r{LIBPNG_RUBY_ITERATION = \d+},
|
|
69
|
+
"LIBPNG_RUBY_ITERATION = #{m[1].to_i + 1}") or
|
|
70
|
+
raise "Failed to substitute iteration"
|
|
71
|
+
when "libpng"
|
|
72
|
+
new_v = ENV.fetch("LIBPNG_VERSION_INPUT", "")
|
|
73
|
+
raise "libpng-version input is required when bump-type=libpng" if new_v.empty?
|
|
74
|
+
raise "Invalid version format: #{new_v} (expected X.Y.Z)" unless new_v.match?(/\A\d+\.\d+\.\d+\z/)
|
|
75
|
+
content.sub!(%r{LIBPNG_VERSION = "[^"]+"},
|
|
76
|
+
"LIBPNG_VERSION = \"#{new_v}\"") or
|
|
77
|
+
raise "Failed to substitute libpng version"
|
|
78
|
+
content.sub!(%r{LIBPNG_RUBY_ITERATION = \d+},
|
|
79
|
+
"LIBPNG_RUBY_ITERATION = 0") or
|
|
80
|
+
raise "Failed to reset iteration"
|
|
81
|
+
else
|
|
82
|
+
raise "Unknown bump-type: #{bump_type}"
|
|
83
|
+
end
|
|
84
|
+
|
|
85
|
+
File.write(path, content)
|
|
86
|
+
load File.expand_path(path)
|
|
87
|
+
File.open(ENV.fetch("GITHUB_OUTPUT"), "a") do |f|
|
|
88
|
+
f.puts "new-version=#{Libpng::VERSION}"
|
|
89
|
+
end
|
|
90
|
+
warn "Bumped to #{Libpng::VERSION}"
|
|
91
|
+
RUBY
|
|
92
|
+
|
|
93
|
+
NEW_VERSION=$(ruby -Ilib -rlibpng/version -e 'puts Libpng::VERSION')
|
|
94
|
+
echo "new-version=${NEW_VERSION}" >> "$GITHUB_OUTPUT"
|
|
95
|
+
|
|
96
|
+
git config user.name "github-actions[bot]"
|
|
97
|
+
git config user.email "41898282+github-actions[bot]@users.noreply.github.com"
|
|
98
|
+
git add lib/libpng/version.rb
|
|
99
|
+
git commit -m "Release v${NEW_VERSION}"
|
|
100
|
+
echo "sha=$(git rev-parse HEAD)" >> "$GITHUB_OUTPUT"
|
|
101
|
+
|
|
102
|
+
- name: Show what's being released
|
|
103
|
+
run: |
|
|
104
|
+
echo "Releasing version: ${{ steps.bump.outputs.new-version }}"
|
|
105
|
+
git --no-pager log --oneline -1 "${{ steps.bump.outputs.sha }}"
|
|
106
|
+
|
|
107
|
+
- name: Push bump commit + tag
|
|
108
|
+
env:
|
|
109
|
+
NEW_VERSION: ${{ steps.bump.outputs.new-version }}
|
|
110
|
+
SHA: ${{ steps.bump.outputs.sha }}
|
|
111
|
+
run: |
|
|
112
|
+
if [[ -n "${SHA}" && "${SHA}" != "${{ github.sha }}" ]]; then
|
|
113
|
+
git push origin "HEAD:${{ github.event.repository.default_branch }}"
|
|
114
|
+
fi
|
|
115
|
+
git tag "v${NEW_VERSION}" "${SHA}"
|
|
116
|
+
git push origin "v${NEW_VERSION}"
|
|
117
|
+
|
|
118
|
+
build:
|
|
119
|
+
needs: bump
|
|
120
|
+
if: always() && !cancelled() && !failure() && (needs.bump.result == 'success' || needs.bump.result == 'skipped')
|
|
121
|
+
runs-on: ${{ matrix.os }}
|
|
122
|
+
strategy:
|
|
123
|
+
fail-fast: false
|
|
124
|
+
matrix:
|
|
125
|
+
include:
|
|
126
|
+
- os: ubuntu-latest
|
|
127
|
+
platform: any
|
|
128
|
+
ruby-version: '3.3'
|
|
129
|
+
- os: ubuntu-latest
|
|
130
|
+
platform: x86_64-linux
|
|
131
|
+
ruby-version: '3.3'
|
|
132
|
+
- os: ubuntu-24.04-arm
|
|
133
|
+
platform: aarch64-linux
|
|
134
|
+
ruby-version: '3.3'
|
|
135
|
+
- os: windows-latest
|
|
136
|
+
platform: x64-mingw32
|
|
137
|
+
ruby-version: '3.3'
|
|
138
|
+
- os: windows-latest
|
|
139
|
+
platform: x64-mingw-ucrt
|
|
140
|
+
ruby-version: '3.3'
|
|
141
|
+
- os: windows-11-arm
|
|
142
|
+
platform: aarch64-mingw-ucrt
|
|
143
|
+
ruby-version: '3.4'
|
|
144
|
+
- os: macos-15-intel
|
|
145
|
+
platform: x86_64-darwin
|
|
146
|
+
ruby-version: '3.3'
|
|
147
|
+
- os: macos-latest
|
|
148
|
+
platform: arm64-darwin
|
|
149
|
+
ruby-version: '3.3'
|
|
150
|
+
steps:
|
|
151
|
+
- uses: actions/checkout@v4
|
|
152
|
+
with:
|
|
153
|
+
ref: ${{ needs.bump.outputs.sha || github.ref }}
|
|
154
|
+
|
|
155
|
+
- uses: ruby/setup-ruby@master
|
|
156
|
+
with:
|
|
157
|
+
ruby-version: ${{ matrix.ruby-version }}
|
|
158
|
+
bundler-cache: true
|
|
159
|
+
|
|
160
|
+
- name: Install build tools (Linux)
|
|
161
|
+
if: startsWith(matrix.os, 'ubuntu')
|
|
162
|
+
run: |
|
|
163
|
+
sudo apt-get update
|
|
164
|
+
sudo apt-get install -y cmake ninja-build zlib1g-dev
|
|
165
|
+
|
|
166
|
+
- name: Install build tools (macOS)
|
|
167
|
+
if: startsWith(matrix.os, 'macos')
|
|
168
|
+
run: |
|
|
169
|
+
brew install cmake ninja
|
|
170
|
+
|
|
171
|
+
- name: Install build tools (Windows)
|
|
172
|
+
if: startsWith(matrix.os, 'windows')
|
|
173
|
+
uses: step-security/msvc-dev-cmd@v1
|
|
174
|
+
with:
|
|
175
|
+
arch: ${{ matrix.platform == 'aarch64-mingw-ucrt' && 'arm64' || 'x64' }}
|
|
176
|
+
|
|
177
|
+
- run: bundle exec rake gem:native:${{ matrix.platform }}
|
|
178
|
+
|
|
179
|
+
- uses: actions/upload-artifact@v4
|
|
180
|
+
with:
|
|
181
|
+
name: pkg-${{ matrix.platform }}
|
|
182
|
+
path: pkg/*.gem
|
|
183
|
+
|
|
184
|
+
- name: Install gem
|
|
185
|
+
run: gem install -b pkg/libpng-*.gem
|
|
186
|
+
|
|
187
|
+
- name: Test conversion
|
|
188
|
+
shell: bash
|
|
189
|
+
run: |
|
|
190
|
+
ruby -rlibpng -e 'png = Libpng.encode(2, 2, "\xff" * 16, pixel_format: "RGBA"); puts Libpng.decode(png, pixel_format: "RGBA").inspect'
|
|
191
|
+
|
|
192
|
+
build_musl:
|
|
193
|
+
needs: bump
|
|
194
|
+
if: always() && !cancelled() && !failure() && (needs.bump.result == 'success' || needs.bump.result == 'skipped')
|
|
195
|
+
runs-on: ${{ matrix.os }}
|
|
196
|
+
strategy:
|
|
197
|
+
fail-fast: false
|
|
198
|
+
matrix:
|
|
199
|
+
include:
|
|
200
|
+
- os: ubuntu-latest
|
|
201
|
+
platform: x86_64-linux-musl
|
|
202
|
+
- os: ubuntu-24.04-arm
|
|
203
|
+
platform: aarch64-linux-musl
|
|
204
|
+
steps:
|
|
205
|
+
- uses: actions/checkout@v4
|
|
206
|
+
with:
|
|
207
|
+
ref: ${{ needs.bump.outputs.sha || github.ref }}
|
|
208
|
+
|
|
209
|
+
- name: Build in Alpine container
|
|
210
|
+
shell: bash
|
|
211
|
+
env:
|
|
212
|
+
PLATFORM: ${{ matrix.platform }}
|
|
213
|
+
run: |
|
|
214
|
+
cat > /tmp/alpine-build.sh <<'BUILD_EOF'
|
|
215
|
+
#!/bin/sh
|
|
216
|
+
set -e
|
|
217
|
+
apk add --no-cache build-base cmake ninja git file zlib-dev
|
|
218
|
+
git config --global --add safe.directory /work
|
|
219
|
+
bundle install --jobs 4
|
|
220
|
+
bundle exec rake "gem:native:${PLATFORM}"
|
|
221
|
+
gem install -b pkg/libpng-*.gem
|
|
222
|
+
(cd /tmp && ruby -e 'gem "libpng"; require "libpng"; png = Libpng.encode(2, 2, "\xff" * 16, pixel_format: "RGBA"); puts Libpng.decode(png, pixel_format: "RGBA").inspect')
|
|
223
|
+
BUILD_EOF
|
|
224
|
+
chmod +x /tmp/alpine-build.sh
|
|
225
|
+
docker run --rm \
|
|
226
|
+
-v "$PWD:/work" \
|
|
227
|
+
-v /tmp/alpine-build.sh:/alpine-build.sh \
|
|
228
|
+
-w /work \
|
|
229
|
+
-e PLATFORM \
|
|
230
|
+
ruby:3.3-alpine \
|
|
231
|
+
/alpine-build.sh
|
|
232
|
+
|
|
233
|
+
- uses: actions/upload-artifact@v4
|
|
234
|
+
with:
|
|
235
|
+
name: pkg-${{ matrix.platform }}
|
|
236
|
+
path: pkg/*.gem
|
|
237
|
+
|
|
238
|
+
publish:
|
|
239
|
+
needs: [ bump, build, build_musl ]
|
|
240
|
+
if: always() && !cancelled() && !failure()
|
|
241
|
+
runs-on: ubuntu-latest
|
|
242
|
+
steps:
|
|
243
|
+
- uses: actions/checkout@v4
|
|
244
|
+
with:
|
|
245
|
+
ref: ${{ needs.bump.outputs.sha || github.ref }}
|
|
246
|
+
|
|
247
|
+
- uses: ruby/setup-ruby@master
|
|
248
|
+
with:
|
|
249
|
+
ruby-version: '3.3'
|
|
250
|
+
bundler-cache: true
|
|
251
|
+
|
|
252
|
+
- uses: actions/download-artifact@v4
|
|
253
|
+
with:
|
|
254
|
+
pattern: pkg-*
|
|
255
|
+
path: pkg
|
|
256
|
+
merge-multiple: true
|
|
257
|
+
|
|
258
|
+
- name: Configure RubyGems credentials (Trusted Publishing / OIDC)
|
|
259
|
+
uses: rubygems/configure-rubygems-credentials@main
|
|
260
|
+
|
|
261
|
+
- name: Publish to rubygems.org
|
|
262
|
+
shell: bash
|
|
263
|
+
run: |
|
|
264
|
+
set +e
|
|
265
|
+
for gem in pkg/*.gem; do
|
|
266
|
+
output=$(gem push -V "$gem" 2>&1)
|
|
267
|
+
rc=$?
|
|
268
|
+
if [ $rc -eq 0 ]; then
|
|
269
|
+
echo "$output"
|
|
270
|
+
continue
|
|
271
|
+
fi
|
|
272
|
+
# RubyGems rejects re-pushing the same version with 422, even for
|
|
273
|
+
# identical content. Tolerate that so we can publish newly-added
|
|
274
|
+
# platform variants at a version whose source gem already exists.
|
|
275
|
+
if echo "$output" | grep -qE "already (exists|pushed)|Conflict|Repushing"; then
|
|
276
|
+
echo "Skip $(basename "$gem") (already published)"
|
|
277
|
+
continue
|
|
278
|
+
fi
|
|
279
|
+
echo "$output" >&2
|
|
280
|
+
exit 1
|
|
281
|
+
done
|
data/.gitignore
ADDED
data/.rspec
ADDED
data/.rubocop.yml
ADDED
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
AllCops:
|
|
2
|
+
NewCops: enable
|
|
3
|
+
TargetRubyVersion: 2.7
|
|
4
|
+
SuggestExtensions: false
|
|
5
|
+
|
|
6
|
+
Gemspec/DevelopmentDependencies:
|
|
7
|
+
Enabled: false
|
|
8
|
+
|
|
9
|
+
# The wrapper is by nature a single file with FFI declarations + several
|
|
10
|
+
# methods that walk libpng's chunked API; splitting would obscure the
|
|
11
|
+
# 1-to-1 mapping with the C API.
|
|
12
|
+
Metrics/AbcSize:
|
|
13
|
+
Max: 60
|
|
14
|
+
Metrics/ClassLength:
|
|
15
|
+
Max: 200
|
|
16
|
+
Metrics/CyclomaticComplexity:
|
|
17
|
+
Max: 20
|
|
18
|
+
Metrics/MethodLength:
|
|
19
|
+
Max: 50
|
|
20
|
+
Metrics/ModuleLength:
|
|
21
|
+
Max: 250
|
|
22
|
+
Metrics/PerceivedComplexity:
|
|
23
|
+
Max: 20
|
|
24
|
+
Metrics/ParameterLists:
|
|
25
|
+
Max: 7
|
|
26
|
+
|
|
27
|
+
Metrics/BlockLength:
|
|
28
|
+
Exclude:
|
|
29
|
+
- spec/**/*.rb
|
|
30
|
+
- Rakefile
|
|
31
|
+
- libpng.gemspec
|
|
32
|
+
|
|
33
|
+
Style/SpecialGlobalVars:
|
|
34
|
+
Exclude:
|
|
35
|
+
- ext/extconf.rb
|
|
36
|
+
Style/FrozenStringLiteralComment:
|
|
37
|
+
Exclude:
|
|
38
|
+
- ext/extconf.rb
|
|
39
|
+
- lib/libpng/recipe.rb
|
data/Gemfile
ADDED
data/LICENSE.txt
ADDED
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
Copyright (c) 2026 Ribose Inc.
|
|
2
|
+
|
|
3
|
+
Redistribution and use in source and binary forms, with or without
|
|
4
|
+
modification, are permitted provided that the following conditions are met:
|
|
5
|
+
|
|
6
|
+
1. Redistributions of source code must retain the above copyright notice,
|
|
7
|
+
this list of conditions and the following disclaimer.
|
|
8
|
+
|
|
9
|
+
2. Redistributions in binary form must reproduce the above copyright
|
|
10
|
+
notice, this list of conditions and the following disclaimer in the
|
|
11
|
+
documentation and/or other materials provided with the distribution.
|
|
12
|
+
|
|
13
|
+
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
|
|
14
|
+
AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
|
15
|
+
IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
|
|
16
|
+
ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
|
|
17
|
+
LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
|
|
18
|
+
CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
|
|
19
|
+
SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
|
|
20
|
+
INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
|
|
21
|
+
CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
|
|
22
|
+
ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
|
|
23
|
+
POSSIBILITY OF SUCH DAMAGE.
|
|
24
|
+
|
|
25
|
+
This gem bundles pre-compiled binaries of libpng, which is itself
|
|
26
|
+
distributed under the libpng license (see the upstream LICENSE file
|
|
27
|
+
in https://github.com/pnggroup/libpng for details).
|
data/README.adoc
ADDED
|
@@ -0,0 +1,108 @@
|
|
|
1
|
+
= libpng: pre-compiled libpng for Ruby
|
|
2
|
+
|
|
3
|
+
image:https://img.shields.io/badge/Ruby-%3E%3D%202.7.0-ruby.svg[Ruby]
|
|
4
|
+
image:https://img.shields.io/badge/license-BSD--2--Clause-blue.svg[License]
|
|
5
|
+
|
|
6
|
+
`libpng` is a Ruby binding for the official PNG reference library
|
|
7
|
+
(https://github.com/pnggroup/libpng[libpng]). The native shared library
|
|
8
|
+
is pre-compiled for each target platform and shipped inside the gem, so
|
|
9
|
+
`gem install libpng` Just Works without a C compiler on the host.
|
|
10
|
+
|
|
11
|
+
== Installation
|
|
12
|
+
|
|
13
|
+
Add to your Gemfile:
|
|
14
|
+
|
|
15
|
+
gem "libpng"
|
|
16
|
+
|
|
17
|
+
Then:
|
|
18
|
+
|
|
19
|
+
bundle install
|
|
20
|
+
|
|
21
|
+
Or install manually:
|
|
22
|
+
|
|
23
|
+
gem install libpng
|
|
24
|
+
|
|
25
|
+
The gem downloads a pre-compiled binary for your platform automatically.
|
|
26
|
+
No C compiler, libpng development headers, or system packages are needed
|
|
27
|
+
at install time.
|
|
28
|
+
|
|
29
|
+
== Usage
|
|
30
|
+
|
|
31
|
+
require "libpng"
|
|
32
|
+
|
|
33
|
+
# Encode raw RGBA pixels (row-major, top-down) as a PNG.
|
|
34
|
+
png = Libpng.encode(width, height, rgba_bytes, pixel_format: "RGBA")
|
|
35
|
+
File.binwrite("out.png", png)
|
|
36
|
+
|
|
37
|
+
# Decode a PNG into raw pixels.
|
|
38
|
+
decoded = Libpng.decode(File.binread("out.png"), pixel_format: "RGBA")
|
|
39
|
+
decoded.width # => Integer
|
|
40
|
+
decoded.height # => Integer
|
|
41
|
+
decoded.format # => "RGBA"
|
|
42
|
+
decoded.pixels # => binary String of RGBA bytes
|
|
43
|
+
|
|
44
|
+
=== Supported pixel formats
|
|
45
|
+
|
|
46
|
+
- `"GRAY"` / `"GRAYSCALE"` -- 8-bit grayscale (1 byte/pixel)
|
|
47
|
+
- `"GA"` / `"AG"` -- 8-bit grayscale + alpha (2 bytes/pixel)
|
|
48
|
+
- `"RGB"`, `"BGR"` -- 8-bit truecolor (3 bytes/pixel)
|
|
49
|
+
- `"RGBA"`, `"ARGB"`, `"BGRA"`, `"ABGR"` -- 8-bit truecolor + alpha (4 bytes/pixel)
|
|
50
|
+
|
|
51
|
+
=== Encoding options
|
|
52
|
+
|
|
53
|
+
Libpng.encode(width, height, pixels,
|
|
54
|
+
pixel_format: "RGBA",
|
|
55
|
+
convert_to_8bit: false)
|
|
56
|
+
|
|
57
|
+
`convert_to_8bit: true` causes libpng to convert 16-bit input to 8-bit
|
|
58
|
+
on write (input is still passed as a packed byte buffer; use this if you
|
|
59
|
+
have packed 16-bit-per-channel data).
|
|
60
|
+
|
|
61
|
+
== Ractor safety
|
|
62
|
+
|
|
63
|
+
`Libpng.encode` and `Libpng.decode` are Ractor-safe. Every call
|
|
64
|
+
allocates and frees its own libpng `png_image`; no shared mutable state
|
|
65
|
+
exists on the Ruby side. Calls from multiple Ractors run concurrently
|
|
66
|
+
without locking.
|
|
67
|
+
|
|
68
|
+
Example:
|
|
69
|
+
|
|
70
|
+
r = Ractor.new do
|
|
71
|
+
Libpng.encode(2, 2, "\xFF" * 16, pixel_format: "RGBA")
|
|
72
|
+
end
|
|
73
|
+
r.take # => PNG binary
|
|
74
|
+
|
|
75
|
+
== Versioning
|
|
76
|
+
|
|
77
|
+
This gem follows a `{LIBPNG_VERSION}.{ITERATION}` scheme:
|
|
78
|
+
|
|
79
|
+
- `LIBPNG_VERSION` is the upstream libpng release the gem is built
|
|
80
|
+
against (currently 1.6.48).
|
|
81
|
+
- `ITERATION` is a counter that bumps on Ruby-side changes (recipe bug
|
|
82
|
+
fixes, CI tweaks, doc updates). It resets to 0 each time
|
|
83
|
+
`LIBPNG_VERSION` bumps.
|
|
84
|
+
|
|
85
|
+
For example, `1.6.48.0` is the first release against libpng 1.6.48,
|
|
86
|
+
`1.6.48.1` is a Ruby-side fix, and `1.6.49.0` would be a release against
|
|
87
|
+
the next upstream libpng.
|
|
88
|
+
|
|
89
|
+
== How it works
|
|
90
|
+
|
|
91
|
+
The gem has three layers:
|
|
92
|
+
|
|
93
|
+
1. `lib/libpng.rb` -- Ruby FFI wrapper. Loads `libpng16.{so,dylib,dll}`
|
|
94
|
+
from the gem's `lib/libpng/` directory at runtime.
|
|
95
|
+
2. `lib/libpng/recipe.rb` -- a MiniPortileCMake recipe that downloads
|
|
96
|
+
the libpng source tarball and runs CMake to produce the shared
|
|
97
|
+
library. This is invoked by `ext/extconf.rb` when the gem is installed
|
|
98
|
+
from source.
|
|
99
|
+
3. `Rakefile` defines `gem:native:<platform>` tasks that pre-compile
|
|
100
|
+
the gem for each target platform. The pre-compiled gems bundle the
|
|
101
|
+
`.so`/`.dylib`/`.dll` and disable `extconf.rb`, so installation
|
|
102
|
+
requires no C compiler.
|
|
103
|
+
|
|
104
|
+
== License
|
|
105
|
+
|
|
106
|
+
BSD-2-Clause; see link:LICENSE.txt[LICENSE.txt]. The gem bundles
|
|
107
|
+
pre-compiled libpng binaries; libpng itself is distributed under the
|
|
108
|
+
https://github.com/pnggroup/libpng/blob/main/LICENSE[libpng license].
|