Skip to content
This repository was archived by the owner on Jul 11, 2025. It is now read-only.
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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: 0 additions & 42 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ name: CI/CD Pipeline
on:
push:
branches: [ "main", "develop" ]
tags: [ "v*" ]
pull_request:
branches: [ "main", "develop" ]

Expand Down Expand Up @@ -136,44 +135,3 @@ jobs:
name: coverage-report
path: .build/meson-logs/coverage/
retention-days: 5


release:
name: Release
if: startsWith(github.ref, 'refs/tags/v')
needs: [build, test]
runs-on: ubuntu-latest
permissions:
contents: write

steps:
- uses: actions/checkout@v3
with:
fetch-depth: 0

- name: Install dependencies
run: |
sudo apt-get update
sudo apt-get install -y meson ninja-build libpcre2-dev

- name: Build release
run: |
meson setup -Dbuildtype=release .build
meson compile -C .build

- name: Create release archive
run: |
mkdir -p release/include release/lib
cp -r includes/cargs* release/include/
cp includes/cargs.h release/include/
cp .build/libcargs.a release/lib/
cp .build/libcargs.so release/lib/
tar -czf cargs-${{ github.ref_name }}.tar.gz release/

- name: Create GitHub Release
uses: softprops/action-gh-release@v1
with:
files: cargs-${{ github.ref_name }}.tar.gz
draft: false
prerelease: false
generate_release_notes: true
107 changes: 107 additions & 0 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,107 @@
name: Create Release Package

on:
release:
types: [created]

jobs:
build-package:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
with:
fetch-depth: 0

- name: Install dependencies
run: |
sudo apt-get update
sudo apt-get install -y meson ninja-build libpcre2-dev

- name: Build library
run: |
meson setup -Dbuildtype=release .build
meson compile -C .build

- name: Extract version from tag
id: get_version
run: echo "VERSION=${GITHUB_REF#refs/tags/v}" >> $GITHUB_ENV

- name: Create package with installer
run: |
mkdir -p cargs-${{ env.VERSION }}/{include,lib}

cp -r includes/* cargs-${{ env.VERSION }}/include/
cp .build/libcargs.a cargs-${{ env.VERSION }}/lib/
cp .build/libcargs.so* cargs-${{ env.VERSION }}/lib/

cp packaging/installers/install.sh cargs-${{ env.VERSION }}/
chmod +x cargs-${{ env.VERSION }}/install.sh

cp README.md LICENSE cargs-${{ env.VERSION }}/

tar -czf cargs-${{ env.VERSION }}.tar.gz cargs-${{ env.VERSION }}
zip -r cargs-${{ env.VERSION }}.zip cargs-${{ env.VERSION }}

- name: Upload tar.gz to GitHub Release
uses: actions/upload-release-asset@v1
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
with:
upload_url: ${{ github.event.release.upload_url }}
asset_path: ./cargs-${{ env.VERSION }}.tar.gz
asset_name: cargs-${{ env.VERSION }}.tar.gz
asset_content_type: application/gzip

- name: Upload zip to GitHub Release
uses: actions/upload-release-asset@v1
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
with:
upload_url: ${{ github.event.release.upload_url }}
asset_path: ./cargs-${{ env.VERSION }}.zip
asset_name: cargs-${{ env.VERSION }}.zip
asset_content_type: application/zip




# release:
# name: Release
# if: startsWith(github.ref, 'refs/tags/v')
# needs: [build, test]
# runs-on: ubuntu-latest
# permissions:
# contents: write

# steps:
# - uses: actions/checkout@v3
# with:
# fetch-depth: 0

# - name: Install dependencies
# run: |
# sudo apt-get update
# sudo apt-get install -y meson ninja-build libpcre2-dev

# - name: Build release
# run: |
# meson setup -Dbuildtype=release .build
# meson compile -C .build

# - name: Create release archive
# run: |
# mkdir -p release/include release/lib
# cp -r includes/cargs* release/include/
# cp includes/cargs.h release/include/
# cp .build/libcargs.a release/lib/
# cp .build/libcargs.so release/lib/
# tar -czf cargs-${{ github.ref_name }}.tar.gz release/

# - name: Create GitHub Release
# uses: softprops/action-gh-release@v1
# with:
# files: cargs-${{ github.ref_name }}.tar.gz
# draft: false
# prerelease: false
# generate_release_notes: true

3 changes: 1 addition & 2 deletions meson.build
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
project(
'cargs', 'c',
version: '0.1.0',
version: '1.1.0',
license: 'MIT',
default_options: [
'warning_level=3',
Expand All @@ -11,7 +11,6 @@ project(
meson_version: '>=1.0.0',
)

# Compiler configuration based on type (Meson ≥ 1.0.0 compatible)
cc = meson.get_compiler('c')
if cc.get_id() == 'clang'
add_project_arguments('-Wno-gnu-zero-variadic-macro-arguments', language: 'c')
Expand Down
191 changes: 191 additions & 0 deletions packaging/installers/install.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,191 @@
#!/bin/bash
set -e

VERSION="0.1.0"

PREFIX="/usr/local"
LIBDIR="${PREFIX}/lib"
INCLUDEDIR="${PREFIX}/include"
INSTALL_LOCAL=0
VERBOSE=0
UNINSTALL=0

RED='\033[0;31m'
GREEN='\033[0;32m'
YELLOW='\033[0;33m'
BLUE='\033[0;34m'
NC='\033[0m' # No Color

show_help() {
echo -e "${BLUE}cargs installer${NC} - v${VERSION}"
echo ""
echo "Usage: $0 [options]"
echo ""
echo "Options:"
echo " --prefix=PATH Installation prefix (default: /usr/local)"
echo " --libdir=PATH Library directory (default: \$prefix/lib)"
echo " --includedir=PATH Include directory (default: \$prefix/include)"
echo " --local Install to ~/.local instead of system directories"
echo " --uninstall Uninstall the library"
echo " --verbose Show detailed output"
echo " --help Display this help message"
echo ""
echo "Example: $0 --prefix=/opt --verbose"
}

for arg in "$@"; do
case $arg in
--prefix=*)
PREFIX="${arg#*=}"
;;
--libdir=*)
LIBDIR="${arg#*=}"
;;
--includedir=*)
INCLUDEDIR="${arg#*=}"
;;
--local)
INSTALL_LOCAL=1
PREFIX="$HOME/.local"
LIBDIR="$HOME/.local/lib"
INCLUDEDIR="$HOME/.local/include"
;;
--verbose)
VERBOSE=1
;;
--uninstall)
UNINSTALL=1
;;
--help)
show_help
exit 0
;;
*)
echo -e "${RED}Error:${NC} Unknown option: $arg"
show_help
exit 1
;;
esac
done

log() {
if [ $VERBOSE -eq 1 ]; then
echo -e "$1"
fi
}

check_dependencies() {
log "${BLUE}Checking dependencies...${NC}"

# Vérifier pcre2
if ! pkg-config --exists libpcre2-8; then
echo -e "${RED}Error:${NC} pcre2 library not found"
echo "Please install pcre2 development files:"
echo " - Ubuntu/Debian: sudo apt install libpcre2-dev"
echo " - Fedora/RHEL: sudo dnf install pcre2-devel"
echo " - macOS: brew install pcre2"
exit 1
fi

log "${GREEN}All dependencies satisfied.${NC}"
}

check_permissions() {
if [ $INSTALL_LOCAL -eq 0 ]; then
if [ "$(id -u)" -ne 0 ] && [ -w "$PREFIX" ] ; then
echo -e "${YELLOW}Warning:${NC} Installing system-wide without root privileges."
echo "If installation fails, try with sudo or use --local"
elif [ "$(id -u)" -ne 0 ]; then
echo -e "${RED}Error:${NC} Installing system-wide requires root privileges."
echo "Either run with sudo or use --local option to install in your home directory."
exit 1
fi
fi
}

install_library() {
log "${BLUE}Installing cargs to:${NC}"
log " Library: $LIBDIR"
log " Headers: $INCLUDEDIR"

mkdir -p "$LIBDIR" "$INCLUDEDIR"

log "${BLUE}Copying files...${NC}"
cp -r lib/* "$LIBDIR/"
cp -r include/* "$INCLUDEDIR/"

if [ "$(id -u)" -eq 0 ] && [ "$(uname)" = "Linux" ]; then
log "${BLUE}Updating library cache...${NC}"
ldconfig
fi

if [ -d "$LIBDIR/pkgconfig" ] || mkdir -p "$LIBDIR/pkgconfig"; then
log "${BLUE}Creating pkg-config file...${NC}"
cat > "$LIBDIR/pkgconfig/cargs.pc" << EOF
prefix=$PREFIX
exec_prefix=\${prefix}
libdir=$LIBDIR
includedir=$INCLUDEDIR

Name: cargs
Description: Modern C library for command-line argument parsing
Version: $VERSION
Requires.private: libpcre2-8
Libs: -L\${libdir} -lcargs
Cflags: -I\${includedir}
EOF
fi

echo -e "${GREEN}cargs has been successfully installed!${NC}"

echo ""
echo "You can now use cargs in your projects:"
echo ""
if [ $INSTALL_LOCAL -eq 1 ]; then
echo " With pkg-config: gcc -o myapp myapp.c \$(pkg-config --cflags --libs cargs)"
echo " Or directly: gcc -o myapp myapp.c -I$INCLUDEDIR -L$LIBDIR -lcargs"
else
echo " Direct linking: gcc -o myapp myapp.c -lcargs"
echo " Or with pkg-config: gcc -o myapp myapp.c \$(pkg-config --cflags --libs cargs)"
fi

if [ $INSTALL_LOCAL -eq 1 ]; then
echo ""
echo "Since you installed in a non-standard location, you might need to:"
echo " - Add $LIBDIR to LD_LIBRARY_PATH"
echo " - Add $LIBDIR/pkgconfig to PKG_CONFIG_PATH"
echo ""
echo "For example, add these lines to your ~/.bashrc:"
echo " export LD_LIBRARY_PATH=\$LD_LIBRARY_PATH:$LIBDIR"
echo " export PKG_CONFIG_PATH=\$PKG_CONFIG_PATH:$LIBDIR/pkgconfig"
fi
}

uninstall_library() {
log "${BLUE}Uninstalling cargs from:${NC}"
log " Library: $LIBDIR"
log " Headers: $INCLUDEDIR"

rm -f "$LIBDIR/libcargs.a" "$LIBDIR/libcargs.so"*
rm -f "$LIBDIR/pkgconfig/cargs.pc"
rm -rf "$INCLUDEDIR/cargs"
rm -f "$INCLUDEDIR/cargs.h"

if [ "$(id -u)" -eq 0 ] && [ "$(uname)" = "Linux" ]; then
log "${BLUE}Updating library cache...${NC}"
ldconfig
fi

echo -e "${GREEN}cargs has been successfully uninstalled!${NC}"
}

if [ $UNINSTALL -eq 1 ]; then
check_permissions
uninstall_library
else
check_dependencies
check_permissions
install_library
fi

exit 0
Loading