-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
0 parents
commit a6a16af
Showing
8 changed files
with
259 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
*.zig text eol=lf | ||
*.zon text eol=lf |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
name: Continuous Integration | ||
|
||
on: | ||
push: | ||
branches: [main] | ||
|
||
pull_request: | ||
branches: [main] | ||
|
||
workflow_dispatch: | ||
|
||
jobs: | ||
install: | ||
runs-on: ubuntu-latest | ||
|
||
steps: | ||
- name: Check out repository | ||
uses: actions/checkout@v4 | ||
|
||
- name: Set up Zig | ||
uses: mlugg/setup-zig@v1 | ||
|
||
- name: Run `install` | ||
run: zig build install -Duse-curl -Duse-bz2 | ||
|
||
fmt: | ||
runs-on: ubuntu-latest | ||
|
||
steps: | ||
- name: Check out repository | ||
uses: actions/checkout@v4 | ||
|
||
- name: Set up Zig | ||
uses: mlugg/setup-zig@v1 | ||
|
||
- name: Run `fmt` | ||
run: zig build fmt |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
.zig-cache/ | ||
zig-out/ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
MIT License | ||
|
||
Copyright (c) 2024 Jora Troosh | ||
|
||
Permission is hereby granted, free of charge, to any person obtaining a copy | ||
of this software and associated documentation files (the "Software"), to deal | ||
in the Software without restriction, including without limitation the rights | ||
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell | ||
copies of the Software, and to permit persons to whom the Software is | ||
furnished to do so, subject to the following conditions: | ||
|
||
The above copyright notice and this permission notice shall be included in all | ||
copies or substantial portions of the Software. | ||
|
||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR | ||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, | ||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE | ||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER | ||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, | ||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE | ||
SOFTWARE. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
# cfitsio | ||
|
||
[![CI][ci-shd]][ci-url] | ||
[![LC][lc-shd]][lc-url] | ||
|
||
## Zig build of [CFITSIO library](https://github.com/HEASARC/cfitsio). | ||
|
||
### :rocket: Usage | ||
|
||
- Add `cfitsio` dependency to `build.zig.zon`. | ||
|
||
```sh | ||
zig fetch --save https://github.com/tensorush/cfitsio/archive/<git_tag_or_commit_hash>.tar.gz | ||
``` | ||
|
||
- Use `cfitsio` as a module in your `build.zig`. | ||
|
||
```zig | ||
const cfitsio_dep = b.dependency("cfitsio", .{ | ||
.target = target, | ||
.optimize = optimize, | ||
}); | ||
const cfitsio_mod = cfitsio_dep.module("cfitsio"); | ||
<compile>.root_module.addImport("cfitsio", cfitsio_mod);; | ||
``` | ||
|
||
<!-- MARKDOWN LINKS --> | ||
|
||
[ci-shd]: https://img.shields.io/github/actions/workflow/status/tensorush/cfitsio/ci.yaml?branch=main&style=for-the-badge&logo=github&label=CI&labelColor=black | ||
[ci-url]: https://github.com/tensorush/cfitsio/blob/main/.github/workflows/ci.yaml | ||
[lc-shd]: https://img.shields.io/github/license/tensorush/cfitsio.svg?style=for-the-badge&labelColor=black | ||
[lc-url]: https://github.com/tensorush/cfitsio/blob/main/LICENSE |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,144 @@ | ||
const std = @import("std"); | ||
|
||
pub fn build(b: *std.Build) void { | ||
const target = b.standardTargetOptions(.{}); | ||
const optimize = b.standardOptimizeOption(.{}); | ||
const version = std.SemanticVersion{ .major = 4, .minor = 4, .patch = 1 }; | ||
|
||
// Custom options | ||
const use_curl = b.option(bool, "use-curl", "Enable remote file access") orelse false; | ||
const use_bz2 = b.option(bool, "use-bz2", "Enable reading bzip2-compressed files") orelse false; | ||
|
||
// Dependencies | ||
const cfitsio_dep = b.dependency("cfitsio", .{}); | ||
const cfitsio_path = cfitsio_dep.path(""); | ||
|
||
// Library | ||
const lib_step = b.step("lib", "Install library"); | ||
|
||
const lib = b.addStaticLibrary(.{ | ||
.name = "cfitsio", | ||
.target = target, | ||
.version = version, | ||
.optimize = optimize, | ||
}); | ||
|
||
var flags = std.BoundedArray([]const u8, 4){}; | ||
flags.appendSliceAssumeCapacity(&FLAGS); | ||
if (use_curl) { | ||
lib.linkSystemLibrary("curl"); | ||
flags.appendAssumeCapacity("-DCFITSIO_HAVE_CURL"); | ||
} | ||
if (use_bz2) { | ||
lib.linkSystemLibrary("bz2"); | ||
flags.appendAssumeCapacity("-DHAVE_BZIP2=1"); | ||
} | ||
|
||
lib.addCSourceFiles(.{ .root = cfitsio_path, .files = &SOURCES, .flags = flags.constSlice() }); | ||
lib.installHeadersDirectory(cfitsio_path, "", .{ .include_extensions = &HEADERS }); | ||
lib.linkSystemLibrary("z"); | ||
lib.linkLibC(); | ||
|
||
const lib_install = b.addInstallArtifact(lib, .{}); | ||
lib_step.dependOn(&lib_install.step); | ||
b.default_step.dependOn(lib_step); | ||
|
||
// Module | ||
const module = b.addModule("cfitsio", .{ | ||
.target = target, | ||
.optimize = optimize, | ||
.root_source_file = b.path("src/lib.zig"), | ||
}); | ||
module.linkLibrary(lib); | ||
|
||
// Formatting checks | ||
const fmt_step = b.step("fmt", "Run formatting checks"); | ||
|
||
const fmt = b.addFmt(.{ | ||
.paths = &.{ | ||
"build.zig", | ||
}, | ||
.check = true, | ||
}); | ||
fmt_step.dependOn(&fmt.step); | ||
b.default_step.dependOn(fmt_step); | ||
} | ||
|
||
const HEADERS = .{ | ||
"fitsio.h", | ||
"fitsio2.h", | ||
"longnam.h", | ||
"drvrsmem.h", | ||
"cfortran.h", | ||
"f77_wrap.h", | ||
"region.h", | ||
}; | ||
|
||
const SOURCES = .{ | ||
"buffers.c", | ||
"cfileio.c", | ||
"checksum.c", | ||
"drvrfile.c", | ||
"drvrmem.c", | ||
"drvrnet.c", | ||
"drvrsmem.c", | ||
"editcol.c", | ||
"edithdu.c", | ||
"eval_l.c", | ||
"eval_y.c", | ||
"eval_f.c", | ||
"fitscore.c", | ||
"getcol.c", | ||
"getcolb.c", | ||
"getcold.c", | ||
"getcole.c", | ||
"getcoli.c", | ||
"getcolj.c", | ||
"getcolk.c", | ||
"getcoll.c", | ||
"getcols.c", | ||
"getcolsb.c", | ||
"getcoluk.c", | ||
"getcolui.c", | ||
"getcoluj.c", | ||
"getkey.c", | ||
"group.c", | ||
"grparser.c", | ||
"histo.c", | ||
"iraffits.c", | ||
"modkey.c", | ||
"putcol.c", | ||
"putcolb.c", | ||
"putcold.c", | ||
"putcole.c", | ||
"putcoli.c", | ||
"putcolj.c", | ||
"putcolk.c", | ||
"putcoluk.c", | ||
"putcoll.c", | ||
"putcols.c", | ||
"putcolsb.c", | ||
"putcolu.c", | ||
"putcolui.c", | ||
"putcoluj.c", | ||
"putkey.c", | ||
"region.c", | ||
"scalnull.c", | ||
"swapproc.c", | ||
"wcssub.c", | ||
"wcsutil.c", | ||
"imcompress.c", | ||
"quantize.c", | ||
"ricecomp.c", | ||
"pliocomp.c", | ||
"fits_hcompress.c", | ||
"fits_hdecompress.c", | ||
"simplerng.c", | ||
"zcompress.c", | ||
"zuncompress.c", | ||
}; | ||
|
||
const FLAGS = .{ | ||
"-std=c89", | ||
"-D_REENTRANT", | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
.{ | ||
.name = "cfitsio", | ||
.version = "4.4.1", | ||
.minimum_zig_version = "0.13.0", | ||
.dependencies = .{ | ||
.cfitsio = .{ | ||
.url = "https://github.com/HEASARC/cfitsio/archive/cfitsio4_4_1_20240617.tar.gz", | ||
.hash = "1220d9b5104c0d9cd8158f52ce64d891eb76a083b43962aed62c611addb920e5a9bb", | ||
}, | ||
}, | ||
.paths = .{ | ||
"src/", | ||
"build.zig", | ||
"build.zig.zon", | ||
"LICENSE", | ||
"README.md", | ||
}, | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
pub const c = @cImport({ | ||
@cInclude("fitsio/fitsio.h"); | ||
}); |