Skip to content

Commit

Permalink
Bring WebP to swift, add CI.
Browse files Browse the repository at this point in the history
Signed-off-by: furby™ <[email protected]>
  • Loading branch information
furby-tm committed Oct 27, 2024
0 parents commit 0c5cd02
Show file tree
Hide file tree
Showing 15 changed files with 423 additions and 0 deletions.
21 changes: 21 additions & 0 deletions .github/workflows/swift-debug-macos.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
name: Run Tests (macOS arm64)

on: [push]

jobs:
build:
name: Swift ${{ matrix.swift }} on ${{ matrix.os }}
strategy:
matrix:
os: [macos-14]
swift: ["5.10"]
runs-on: ${{ matrix.os }}
steps:
- uses: swift-actions/setup-swift@v2
with:
swift-version: ${{ matrix.swift }}
- uses: actions/checkout@v4
- name: 🐙 Fetch Git Submodules
run: git submodule update --init --recursive
- name: 🧪 Test
run: swift test
21 changes: 21 additions & 0 deletions .github/workflows/swift-debug-ubuntu.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
name: Run Tests (Ubuntu x86/64)

on: [push]

jobs:
build:
name: Swift ${{ matrix.swift }} on ${{ matrix.os }}
strategy:
matrix:
os: [ubuntu-latest]
swift: ["5.10"]
runs-on: ${{ matrix.os }}
steps:
- uses: swift-actions/setup-swift@v2
with:
swift-version: ${{ matrix.swift }}
- uses: actions/checkout@v4
- name: 🐙 Fetch Git Submodules
run: git submodule update --init --recursive
- name: 🧪 Test
run: swift test
22 changes: 22 additions & 0 deletions .github/workflows/swift-debug-windows.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
name: Run Tests (Microsoft Windows)

on: [push]

jobs:
build:
name: Swift ${{ matrix.swift }} on ${{ matrix.os }}
strategy:
matrix:
os: [windows-latest]
swift: ["5.10"]
runs-on: ${{ matrix.os }}
steps:
- uses: compnerd/gha-setup-swift@main
with:
branch: swift-5.10-release
tag: 5.10-RELEASE
- uses: actions/checkout@v4
- name: 🐙 Fetch Git Submodules
run: git submodule update --init --recursive
- name: 🧪 Test
run: swift test
21 changes: 21 additions & 0 deletions .github/workflows/swift-macos.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
name: Swift (macOS arm64)

on: [push]

jobs:
build:
name: Swift ${{ matrix.swift }} on ${{ matrix.os }}
strategy:
matrix:
os: [macos-14]
swift: ["5.10"]
runs-on: ${{ matrix.os }}
steps:
- uses: swift-actions/setup-swift@v2
with:
swift-version: ${{ matrix.swift }}
- uses: actions/checkout@v4
- name: 🐙 Fetch Git Submodules
run: git submodule update --init --recursive
- name: 📦 Build
run: swift build -c release
21 changes: 21 additions & 0 deletions .github/workflows/swift-ubuntu.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
name: Swift (Ubuntu x86/64)

on: [push]

jobs:
build:
name: Swift ${{ matrix.swift }} on ${{ matrix.os }}
strategy:
matrix:
os: [ubuntu-latest]
swift: ["5.10"]
runs-on: ${{ matrix.os }}
steps:
- uses: swift-actions/setup-swift@v2
with:
swift-version: ${{ matrix.swift }}
- uses: actions/checkout@v4
- name: 🐙 Fetch Git Submodules
run: git submodule update --init --recursive
- name: 📦 Build
run: swift build -c release
22 changes: 22 additions & 0 deletions .github/workflows/swift-windows.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
name: Swift (Microsoft Windows)

on: [push]

jobs:
build:
name: Swift ${{ matrix.swift }} on ${{ matrix.os }}
strategy:
matrix:
os: [windows-latest]
swift: ["5.10"]
runs-on: ${{ matrix.os }}
steps:
- uses: compnerd/gha-setup-swift@main
with:
branch: swift-5.10-release
tag: 5.10-RELEASE
- uses: actions/checkout@v4
- name: 🐙 Fetch Git Submodules
run: git submodule update --init --recursive
- name: 📦 Build
run: swift build -c release
8 changes: 8 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
.DS_Store
/.build
/Packages
xcuserdata/
DerivedData/
.swiftpm/configuration/registries.json
.swiftpm/xcode/package.xcworkspace/contents.xcworkspacedata
.netrc
3 changes: 3 additions & 0 deletions .gitmodules
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
[submodule "libwebp"]
path = libwebp
url = https://github.com/the-swift-collective/LibWebPC.git
29 changes: 29 additions & 0 deletions LICENSE
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
Copyright (c) 2010, Google Inc. All rights reserved.

Redistribution and use in source and binary forms, with or without
modification, are permitted provided that the following conditions are
met:

* Redistributions of source code must retain the above copyright
notice, this list of conditions and the following disclaimer.

* Redistributions in binary form must reproduce the above copyright
notice, this list of conditions and the following disclaimer in
the documentation and/or other materials provided with the
distribution.

* Neither the name of Google nor the names of its contributors may
be used to endorse or promote products derived from this software
without specific prior written permission.

THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
"AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
25 changes: 25 additions & 0 deletions Package.resolved
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
{
"object": {
"pins": [
{
"package": "libpng",
"repositoryURL": "https://github.com/the-swift-collective/libpng.git",
"state": {
"branch": null,
"revision": "0eff23aca92a086b7892831f5cb4f58e15be9449",
"version": "1.6.45"
}
},
{
"package": "zlib",
"repositoryURL": "https://github.com/the-swift-collective/zlib.git",
"state": {
"branch": null,
"revision": "f35d438c14187cb369dfd82603c3427dc66fbed5",
"version": "1.3.1"
}
}
]
},
"version": 1
}
101 changes: 101 additions & 0 deletions Package.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,101 @@
// swift-tools-version: 5.5
//
// SPDX-License-Identifier: BSD-3-Clause
// Copyright Contributors to the WebP Codec project

import PackageDescription

let package = Package(
name: "webp",
products: [
.library(
name: "libwebp",
targets: ["libwebp", "sharpyuv", "imageioutil"]
),
.library(
name: "WebP",
targets: ["WebP"]
),
],
dependencies: [
.package(url: "https://github.com/the-swift-collective/libpng.git", from: "1.6.45")
],
targets: [
.target(
name: "libwebp",
dependencies: [
.product(name: "LibPNG", package: "libpng")
],
path: "libwebp/src",
publicHeadersPath: ".",
cSettings: [
.headerSearchPath("../."),
.define("WEBP_HAVE_PNG", to: "1")
]
),
.target(
name: "imageioutil",
dependencies: [
.target(name: "libwebp")
],
path: "libwebp",
exclude: [
"cmake",
"doc",
"examples",
"extras",
"gradle",
"infra",
"m4",
"man",
"sharpyuv",
"src",
"swig",
"tests",
"webp_js"
],
publicHeadersPath: ".",
cSettings: [
.headerSearchPath("../.")
]
),
.target(
name: "sharpyuv",
dependencies: [
.target(name: "libwebp")
],
path: "libwebp",
exclude: [
"cmake",
"doc",
"examples",
"extras",
"gradle",
"imageio",
"infra",
"m4",
"man",
"src",
"swig",
"tests",
"webp_js"
],
publicHeadersPath: ".",
cSettings: [
.headerSearchPath("../.")
]
),
.target(
name: "WebP",
dependencies: [
.target(name: "libwebp"),
.target(name: "sharpyuv"),
.target(name: "imageioutil")
]
),
.testTarget(
name: "WebPTests",
dependencies: ["WebP"]
),
]
)
81 changes: 81 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,81 @@
<!-- markdownlint-configure-file {
"MD013": {
"code_blocks": false,
"tables": false
},
"MD033": false,
"MD041": false
} -->

<div align="center">

<h1 align="center">
WebP
</h1>

<p align="center">
<i align="center">Cross platform <b>swift</b> package for the <a href="https://github.com/webmproject/libwebp"><b>libwebp library</b></a>.</i>
</p>

</div>

<h4 align="center">
<a href="https://github.com/the-swift-collective/webp/actions/workflows/swift-ubuntu.yml">
<img src="https://img.shields.io/github/actions/workflow/status/the-swift-collective/webp/swift-ubuntu.yml?style=flat-square&label=ubuntu%20&labelColor=E95420&logoColor=FFFFFF&logo=ubuntu">
</a>
<a href="https://github.com/the-swift-collective/webp/actions/workflows/swift-macos.yml">
<img src="https://img.shields.io/github/actions/workflow/status/the-swift-collective/webp/swift-macos.yml?style=flat-square&label=macOS&labelColor=000000&logo=apple">
</a>
<a href="https://github.com/the-swift-collective/webp/actions/workflows/swift-windows.yml">
<img src="https://img.shields.io/github/actions/workflow/status/the-swift-collective/webp/swift-windows.yml?style=flat-square&label=windows&labelColor=357EC7&logo=gitforwindows">
</a>
</h4>

<div align="center">

### Usage

</div>

##### To use webp in swift, add webp as a package dependency in your project's Package.swift file.
```swift
dependencies: [
.package(url: "https://github.com/the-swift-collective/webp.git", from: "1.4.0"),
]
```


##### Then, for any target you'd like, add the webp product as a target dependency, a complete example.
```swift
// swift-tools-version: 5.8
import PackageDescription

let package = Package(
name: "MyPackage",
products: [
.library(
name: "MyLibrary",
targets: ["MyLibrary"]
),
],
dependencies: [
.package(url: "https://github.com/the-swift-collective/webp.git", from: "1.4.0")
],
targets: [
.target(
name: "MyLibrary",
dependencies: [
/* add the webp product as a library dependency. */
.product(name: "WebP", package: "webp"),
]
),
]
)
```

<br>

<hr/>

###### ***the swift collective** - cross platform **swift packages**.*
###### webp is licensed under the terms of the [BSD 3-Clause "New" or "Revised" License](https://www.webmproject.org/license/software/).
11 changes: 11 additions & 0 deletions Sources/WebP/WebP.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
// SPDX-License-Identifier: BSD-3-Clause
// Copyright Contributors to the WebP Codec project

@_exported import libwebp
@_exported import sharpyuv
@_exported import imageioutil

public enum WebP
{
public static let version = "1.4.0"
}
Loading

0 comments on commit 0c5cd02

Please sign in to comment.