Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
15 commits
Select commit Hold shift + click to select a range
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
42 changes: 39 additions & 3 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -73,8 +73,44 @@ jobs:
${{ needs.docker-image.outputs.tags }}
```

binary-files:
name: Publish the binary files (${{ matrix.platform }})
binary-files-macos:
name: Publish macOS binary files (${{ matrix.arch }})
runs-on: ${{ matrix.runner }}
strategy:
fail-fast: false
matrix:
include:
- {arch: x86_64, runner: macos-13} # Intel runner
- {arch: arm64, runner: macos-14} # Apple Silicon runner
steps:
- uses: actions/checkout@v6
- run: make CC=clang C_LDFLAGS_EXTRA="-arch ${{ matrix.arch }}"
Copy link

Copilot AI Dec 4, 2025

Choose a reason for hiding this comment

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

Same issue as in tests.yml: The -arch flag is being passed only as a linker flag (C_LDFLAGS_EXTRA), but it also needs to be passed during the compilation phase. Additionally, the macOS-specific C_LDFLAGS override on line 18 of the Makefile doesn't include $(C_LDFLAGS_EXTRA), so the linker won't receive the -arch flag either.

Suggested change
- run: make CC=clang C_LDFLAGS_EXTRA="-arch ${{ matrix.arch }}"
- run: make CC=clang C_CFLAGS_EXTRA="-arch ${{ matrix.arch }}" C_LDFLAGS_EXTRA="-arch ${{ matrix.arch }}"

Copilot uses AI. Check for mistakes.
- run: mkdir ./dist
- run: |
mv ./build/bin/httpcheck ./dist/httpcheck
mv ./build/bin/httpscheck ./dist/httpscheck
mv ./build/bin/portcheck ./dist/portcheck
mv ./build/bin/parallel ./dist/parallel
mv ./build/bin/pidcheck ./dist/pidcheck
cd ./dist
tar -czf ../release.tar.gz *
zip -r ../release.zip .
- {uses: gacts/github-slug@v1, id: filename, with: {to-slug: 'macos-${{ matrix.arch }}'}}
- uses: svenstaro/upload-release-action@v2
with:
repo_token: ${{ secrets.GITHUB_TOKEN }}
file: ./release.tar.gz
asset_name: ${{ steps.filename.outputs.slug }}.tar.gz
tag: ${{ github.ref }}
- uses: svenstaro/upload-release-action@v2
with:
repo_token: ${{ secrets.GITHUB_TOKEN }}
file: ./release.zip
asset_name: ${{ steps.filename.outputs.slug }}.zip
tag: ${{ github.ref }}

binary-files-linux:
name: Publish Linux binary files (${{ matrix.platform }})
runs-on: ubuntu-latest
needs: [docker-image]
strategy:
Expand Down Expand Up @@ -121,7 +157,7 @@ jobs:
generate-checksums:
name: Generate checksums.txt
runs-on: ubuntu-latest
needs: [binary-files]
needs: [binary-files-linux, binary-files-macos]
steps:
- uses: robinraju/release-downloader@v1
with:
Expand Down
19 changes: 18 additions & 1 deletion .github/workflows/tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ jobs:
name: Check for GitLeaks
runs-on: ubuntu-latest
steps:
- {uses: actions/checkout@v4, with: {fetch-depth: 0}}
- {uses: actions/checkout@v6, with: {fetch-depth: 0}}
- uses: gacts/gitleaks@v1

build:
Expand All @@ -32,6 +32,23 @@ jobs:
- run: make
- run: make test

build-macos:
name: Build for macOS (${{ matrix.arch }})
runs-on: ${{ matrix.runner }}
strategy:
fail-fast: false
matrix:
include:
- {arch: x86_64, runner: macos-13} # Intel runner
- {arch: arm64, runner: macos-14} # Apple Silicon runner
steps:
- uses: actions/checkout@v6
- run: make CC=clang C_LDFLAGS_EXTRA="-arch ${{ matrix.arch }}"
Copy link

Copilot AI Dec 4, 2025

Choose a reason for hiding this comment

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

The -arch flag is being passed only as a linker flag (C_LDFLAGS_EXTRA), but it also needs to be passed during the compilation phase. On macOS, object files need to be compiled for the target architecture. Consider passing the architecture flag as part of CFLAGS or as a separate variable that's included in both CFLAGS and LDFLAGS. For example: make CC=clang CFLAGS="... -arch ${{ matrix.arch }}" C_LDFLAGS_EXTRA="-arch ${{ matrix.arch }}"

Suggested change
- run: make CC=clang C_LDFLAGS_EXTRA="-arch ${{ matrix.arch }}"
- run: make CC=clang CFLAGS="-arch ${{ matrix.arch }}" C_LDFLAGS_EXTRA="-arch ${{ matrix.arch }}"

Copilot uses AI. Check for mistakes.
- run: |
ls -lh ./build/bin/
./build/bin/httpcheck --help # try to execute some binaries
./build/bin/httpscheck --help
Comment on lines +46 to +50
Copy link

Copilot AI Dec 4, 2025

Choose a reason for hiding this comment

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

The macOS build job doesn't run the test suite (make test), unlike the Linux build job which runs both make and make test. To ensure consistent quality across platforms, consider adding - run: make test after the build step to verify the binaries work correctly on macOS.

Copilot uses AI. Check for mistakes.

build-image:
name: Build docker image (${{ matrix.platform }})
runs-on: ubuntu-latest
Expand Down
44 changes: 26 additions & 18 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -7,12 +7,21 @@ C_SIZE_FLAGS = -Os -ffunction-sections -fdata-sections -fmerge-all-constants
C_SECURITY_FLAGS = -fstack-protector-strong -D_FORTIFY_SOURCE=2
C_WARNING_FLAGS = -Wall -Wextra -Werror -Wpedantic -Wformat=2 -Wformat-security -Wnull-dereference \
-Wstack-protector -Wstrict-overflow=3 -Wwrite-strings -Wconversion -Wshadow
C_STRIP_FLAGS = -s -fno-asynchronous-unwind-tables -fno-ident -Wl,--build-id=none -Wl,--hash-style=gnu
C_LDFLAGS = -static -Wl,--gc-sections -Wl,--as-needed -Wl,-O1 -Wl,--strip-all
CFLAGS = -std=c99 -D_POSIX_C_SOURCE=200809L
CFLAGS += $(C_SIZE_FLAGS) $(C_SECURITY_FLAGS) $(C_WARNING_FLAGS) $(C_STRIP_FLAGS) $(C_LDFLAGS)
STRIP_FLAGS = -s -R .comment -R .gnu.version -R .note -R .note.ABI-tag -R .note.gnu.build-id -R .gnu.hash \
-R .eh_frame -R .eh_frame_hdr
C_STRIP_FLAGS = -fno-asynchronous-unwind-tables -fno-ident
C_LDFLAGS_EXTRA ?= -static
C_LDFLAGS = -Wl,--gc-sections -Wl,--as-needed -Wl,-O1 \
-Wl,--build-id=none -Wl,--hash-style=gnu $(C_LDFLAGS_EXTRA)
STRIP_FLAGS = -s -R .comment -R .gnu.version -R .note -R .note.ABI-tag \
-R .note.gnu.build-id -R .gnu.hash -R .eh_frame -R .eh_frame_hdr

ifeq ($(shell uname -s),Darwin) # macOS linker flags (https://github.com/tarampampam/microcheck/issues/11)
C_LDFLAGS = -Wl,-dead_strip
Copy link

Copilot AI Dec 4, 2025

Choose a reason for hiding this comment

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

The macOS linker flags override on line 18 doesn't include $(C_LDFLAGS_EXTRA), which means the -arch flag passed from the GitHub Actions workflow won't be applied during linking. This should be: C_LDFLAGS = -Wl,-dead_strip $(C_LDFLAGS_EXTRA) to ensure the architecture flag is properly included.

Suggested change
C_LDFLAGS = -Wl,-dead_strip
C_LDFLAGS = -Wl,-dead_strip $(C_LDFLAGS_EXTRA)

Copilot uses AI. Check for mistakes.
STRIP_FLAGS = -x
endif

CFLAGS = -std=c99 -D_POSIX_C_SOURCE=200809L
CFLAGS += $(C_SIZE_FLAGS) $(C_SECURITY_FLAGS) $(C_WARNING_FLAGS) $(C_STRIP_FLAGS)
LDFLAGS = $(C_LDFLAGS)

.DEFAULT_GOAL: all
all: \
Expand Down Expand Up @@ -47,7 +56,7 @@ build/lib/cli.a: $(patsubst lib/cli/%.c,build/obj/%.o,$(wildcard lib/cli/*.c))
## Build CLI module test binary
build/bin/cli_test: tests/unit/cli/cli_test.c build/lib/cli.a
mkdir -p $(dir $@)
$(CC) $(CFLAGS) -o $@ $< build/lib/cli.a
$(CC) $(CFLAGS) $(LDFLAGS) -o $@ $< build/lib/cli.a

## Compile COMMAND module source files
build/obj/%.o: lib/command/%.c lib/command/command.h
Expand All @@ -62,7 +71,7 @@ build/lib/command.a: $(patsubst lib/command/%.c,build/obj/%.o,$(wildcard lib/com
## Build COMMAND module test binary
build/bin/command_test: tests/unit/command/command_test.c build/lib/command.a
mkdir -p $(dir $@)
$(CC) $(CFLAGS) -o $@ $< build/lib/command.a
$(CC) $(CFLAGS) $(LDFLAGS) -o $@ $< build/lib/command.a

## Compile HTTP module source files
build/obj/%.o: lib/http/%.c lib/http/http.h
Expand All @@ -77,45 +86,42 @@ build/lib/http.a: $(patsubst lib/http/%.c,build/obj/%.o,$(wildcard lib/http/*.c)
## Build HTTP module test binary
build/bin/http_test: tests/unit/http/http_test.c build/lib/http.a
mkdir -p $(dir $@)
$(CC) $(CFLAGS) -o $@ $< build/lib/http.a
$(CC) $(CFLAGS) $(LDFLAGS) -o $@ $< build/lib/http.a

.PHONY: apps/version.h
apps/version.h:
@printf '// Code generated by make; DO NOT EDIT.\n\n\
#ifndef VERSION_H\n#define VERSION_H\n#define APP_VERSION "%s"\n#endif\n' "$(APP_VERSION)" > $@

#src/modules/obj/cli.o: lib/cli lib/cli
# $(CC) -c $(CFLAGS) -o $@ $<

build/bin/httpscheck: apps/httpcheck.c apps/version.h build/lib/cli.a build/lib/http.a lib/mbedtls4/build
mkdir -p $(dir $@)
$(CC) $(CFLAGS) -DWITH_TLS \
-Ilib/mbedtls4/include \
-Ilib/mbedtls4/tf-psa-crypto/include \
-Ilib/mbedtls4/tf-psa-crypto/drivers/builtin/include \
-Llib/mbedtls4/build/library \
$(LDFLAGS) -Llib/mbedtls4/build/library \
-o $@ $< build/lib/cli.a build/lib/http.a \
-lmbedtls -lmbedx509 -ltfpsacrypto
strip $(STRIP_FLAGS) $@

build/bin/httpcheck: apps/httpcheck.c apps/version.h build/lib/cli.a build/lib/http.a
mkdir -p $(dir $@)
$(CC) $(CFLAGS) -o $@ $< build/lib/cli.a build/lib/http.a
$(CC) $(CFLAGS) $(LDFLAGS) -o $@ $< build/lib/cli.a build/lib/http.a
strip $(STRIP_FLAGS) $@

build/bin/portcheck: apps/portcheck.c apps/version.h build/lib/cli.a
mkdir -p $(dir $@)
$(CC) $(CFLAGS) -o $@ $< build/lib/cli.a
$(CC) $(CFLAGS) $(LDFLAGS) -o $@ $< build/lib/cli.a
strip $(STRIP_FLAGS) $@

build/bin/parallel: apps/parallel.c apps/version.h build/lib/cli.a build/lib/command.a
mkdir -p $(dir $@)
$(CC) $(CFLAGS) -o $@ $< build/lib/cli.a build/lib/command.a
$(CC) $(CFLAGS) $(LDFLAGS) -o $@ $< build/lib/cli.a build/lib/command.a
strip $(STRIP_FLAGS) $@

build/bin/pidcheck: apps/pidcheck.c apps/version.h build/lib/cli.a
mkdir -p $(dir $@)
$(CC) $(CFLAGS) -o $@ $< build/lib/cli.a
$(CC) $(CFLAGS) $(LDFLAGS) -o $@ $< build/lib/cli.a
strip $(STRIP_FLAGS) $@

SRC_FILES := $(shell find ./apps ./lib -type f \( -name '*.c' -o -name '*.h' \) ! -path '*/apps/version.h' ! -path '*/lib/mbedtls4/*')
Expand All @@ -129,9 +135,11 @@ test: build/bin/httpcheck \
build/bin/parallel \
build/bin/pidcheck \
build/bin/cli_test \
build/bin/command_test
build/bin/command_test \
build/bin/http_test
./build/bin/cli_test
./build/bin/command_test
./build/bin/http_test
python3 ./tests/feature/httpcheck.py --bin ./build/bin/httpcheck
python3 ./tests/feature/httpcheck.py --bin ./build/bin/httpscheck --https
python3 ./tests/feature/httpcheck.py --bin ./build/bin/httpscheck
Expand Down
8 changes: 7 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,8 @@ So, think of this as an alternative to:

* **Statically linked**: Works in minimal containers (e.g., `scratch`, `distroless`)
* **Pretty fast**: Written in pure `C`, compiled with `musl`
* **Multi-arch and cross-compiled** (x86_64, ARM, etc.)
* **Multi-arch and cross-compiled** (x86_64, ARM, etc.), even for macOS you may find precompiled binaries in
the releases
Comment on lines +63 to +64
Copy link

Copilot AI Dec 4, 2025

Choose a reason for hiding this comment

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

[nitpick] The sentence structure is awkward. Consider rephrasing to: "Multi-arch and cross-compiled (x86_64, ARM, etc.); macOS precompiled binaries are available in the releases"

Suggested change
* **Multi-arch and cross-compiled** (x86_64, ARM, etc.), even for macOS you may find precompiled binaries in
the releases
* **Multi-arch and cross-compiled** (x86_64, ARM, etc.); macOS precompiled binaries are available in the releases

Copilot uses AI. Check for mistakes.
* **Distributed** as single binaries (see the releases page) and Docker image
* **Minimal size**: Optimized for small Docker images
* **TLS support**: Uses `mbedTLS` for HTTPS (accepts self-signed certificates and does NOT verify SSL/TLS certificates)
Expand Down Expand Up @@ -131,6 +132,11 @@ determine if the port is open or closed.
> which may not receive a response from many services. Use UDP checks only when you are certain the target
> will respond appropriately.

> [!NOTE]
> You need to specify the target host and port explicitly via flags or environment variables. Don't try to pass
> them as positional arguments like `portcheck --port 80 example.com`, as this tool does not accept them that way.
> Use `--host` and `--port` options instead - `portcheck --port 80 --host example.com`.

```
Options:
-h, --help Show this help message
Expand Down
2 changes: 2 additions & 0 deletions apps/portcheck.c
Original file line number Diff line number Diff line change
Expand Up @@ -437,8 +437,10 @@ static bool check_udp_port(const struct in_addr addr, const int port,

// enable ICMP error reporting via MSG_ERRQUEUE (Linux-specific, the best
// effort)
#ifdef __linux__
const int on = 1;
setsockopt(sockfd, IPPROTO_IP, IP_RECVERR, &on, sizeof(on));
#endif

// prepare address
struct sockaddr_in server_addr;
Expand Down
Loading