Skip to content

Commit

Permalink
Merge pull request #4 from dr8co/dev
Browse files Browse the repository at this point in the history
Version 1.0.0 release
  • Loading branch information
dr8co authored Apr 30, 2024
2 parents f184129 + 3283151 commit 68ea09f
Show file tree
Hide file tree
Showing 12 changed files with 369 additions and 162 deletions.
41 changes: 13 additions & 28 deletions .github/workflows/cpack-multi-platform.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5,16 +5,15 @@ on:
branches: [ "main" ]

jobs:
build:
package:
runs-on: ${{ matrix.os }}

strategy:
fail-fast: false

matrix:
os: [ubuntu-latest, windows-latest, macos-latest]
build_type: [Release]
c_compiler: [gcc-13, clang, cl]
os: [ ubuntu-latest, windows-latest, macos-latest ]
c_compiler: [ gcc-13, clang, cl ]
include:
- os: windows-latest
c_compiler: cl
Expand Down Expand Up @@ -63,46 +62,32 @@ jobs:
if [[ "${{ runner.os }}" == "Windows" ]]; then
echo "generator='Visual Studio 17 2022'" >> "$GITHUB_OUTPUT"
elif [[ "${{ runner.os }}" == "macOS" ]]; then
echo "generator='Xcode'" >> "$GITHUB_OUTPUT"
echo "generator=Xcode" >> "$GITHUB_OUTPUT"
else
echo "generator='Ninja'" >> "$GITHUB_OUTPUT"
echo "generator=Ninja" >> "$GITHUB_OUTPUT"
fi
- name: Configure CMake for Static Build
- name: Configure CMake
run: >
cmake -B ${{ steps.strings.outputs.build-output-dir }}
-DCMAKE_CXX_COMPILER=${{ matrix.cpp_compiler }}
-DCMAKE_C_COMPILER=${{ matrix.c_compiler }}
-DCMAKE_BUILD_TYPE=${{ matrix.build_type }}
-S ${{ github.workspace }} -G ${{ steps.set-generator.outputs.generator }}
-DBUILD_SHARED_LIBS=OFF -DBUILD_TESTING=OFF -DBUILD_EXAMPLES=OFF
- name: Build Static Library
run: cmake --build ${{ steps.strings.outputs.build-output-dir }} --config ${{ matrix.build_type }} -j 4

- name: Configure CMake for Shared Build
if: matrix.os != 'windows-latest'
run: >
cmake -B ${{ steps.strings.outputs.build-output-dir }}
-DCMAKE_CXX_COMPILER=${{ matrix.cpp_compiler }}
-DCMAKE_C_COMPILER=${{ matrix.c_compiler }}
-DCMAKE_BUILD_TYPE=${{ matrix.build_type }}
-S ${{ github.workspace }} -G ${{ steps.set-generator.outputs.generator }}
-DCMAKE_BUILD_TYPE=Release -S ${{ github.workspace }}
-G ${{ steps.set-generator.outputs.generator }}
-DBUILD_SHARED_LIBS=ON -DBUILD_TESTING=OFF -DBUILD_EXAMPLES=OFF
- name: Build Shared Library
if: matrix.os != 'windows-latest'
run: cmake --build ${{ steps.strings.outputs.build-output-dir }} --config ${{ matrix.build_type }} -j 4
- name: Build Shared Libraries
run: |
cmake --build ${{ steps.strings.outputs.build-output-dir }} --config Release -j 4
- name: Package
working-directory: ${{ steps.strings.outputs.build-output-dir }}
run: cpack

- name: Upload Release Artifacts
if: matrix.build_type == 'Release'
uses: actions/upload-artifact@v4
with:
name: "${{ matrix.os }}-${{ matrix.c_compiler }}-release"
name: "${{ runner.os }}-${{ matrix.c_compiler }}-release"
path: "${{ steps.strings.outputs.build-output-dir }}/Packages"
overwrite: true
if-no-files-found: 'warn'
if-no-files-found: 'error'
133 changes: 132 additions & 1 deletion CHANGELOG.md

Large diffs are not rendered by default.

27 changes: 20 additions & 7 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
cmake_minimum_required(VERSION 3.28)

project(LiteString
VERSION 0.1.0
VERSION 1.0.0
DESCRIPTION "A lightweight byte string library for C"
HOMEPAGE_URL "https://github.com/dr8co/LiteString"
LANGUAGES C CXX)
Expand All @@ -20,7 +20,17 @@ set(CMAKE_CXX_STANDARD_REQUIRED ON)
# Options
option(BUILD_SHARED_LIBS "Build shared libraries" OFF)
option(BUILD_EXAMPLES "Build examples" ON)
option(BUILD_TESTS "Build tests" ON)
option(BUILD_TESTING "Build tests" OFF)

# MSVC Runtime Library and other settings
if (MSVC)
if (BUILD_SHARED_LIBS)
set(CMAKE_MSVC_RUNTIME_LIBRARY "MultiThreaded$<$<CONFIG:Debug>:Debug>DLL")
set(CMAKE_WINDOWS_EXPORT_ALL_SYMBOLS ON)
else ()
set(CMAKE_MSVC_RUNTIME_LIBRARY "MultiThreaded$<$<CONFIG:Debug>:Debug>")
endif ()
endif ()

# Additional compile options for the Debug build
if (NOT MSVC AND CMAKE_C_COMPILER_ID MATCHES "GNU|Clang|AppleClang")
Expand Down Expand Up @@ -60,7 +70,8 @@ if (${CMAKE_C_COMPILER_ID} STREQUAL "Clang")
endif ()
endif ()

set(CMAKE_MODULE_PATH ${CMAKE_MODULE_PATH} "${CMAKE_CURRENT_SOURCE_DIR}/cmake")
# Add the CMake module path
list(APPEND CMAKE_MODULE_PATH "${CMAKE_CURRENT_SOURCE_DIR}/cmake")

add_library(lite-string)
target_sources(lite-string PRIVATE lite_string.c)
Expand Down Expand Up @@ -102,7 +113,7 @@ install(EXPORT LiteStringTargets

include(CMakePackageConfigHelpers)

configure_package_config_file(LiteStringConfig.cmake.in
configure_package_config_file("${CMAKE_CURRENT_SOURCE_DIR}/input_files/LiteStringConfig.cmake.in"
"${CMAKE_CURRENT_BINARY_DIR}/LiteStringConfig.cmake"
INSTALL_DESTINATION "${CMAKE_INSTALL_LIBDIR}/cmake/LiteString")

Expand All @@ -118,7 +129,8 @@ install(FILES
COMPONENT CMakeConfig
)

configure_file(liblite-string.pc.in liblite-string.pc @ONLY)
configure_file("${CMAKE_CURRENT_SOURCE_DIR}/input_files/liblite-string.pc.in"
"${CMAKE_CURRENT_BINARY_DIR}/liblite-string.pc" @ONLY)

install(FILES "${CMAKE_CURRENT_BINARY_DIR}/liblite-string.pc"
DESTINATION "${CMAKE_INSTALL_LIBDIR}/pkgconfig"
Expand All @@ -139,7 +151,8 @@ string(TOUPPER "${FLAGS_VAR}" FLAGS_VAR)
string(CONFIGURE "@${FLAGS_VAR}@" BUILD_FLAGS)

# Configure the version_info.txt file
configure_file(version_info.txt.in "${CMAKE_CURRENT_BINARY_DIR}/version_info.txt" @ONLY)
configure_file("${CMAKE_CURRENT_SOURCE_DIR}/input_files/version_info.txt.in"
"${CMAKE_CURRENT_BINARY_DIR}/version_info.txt" @ONLY)

# Install the version_info.txt file
install(FILES "${CMAKE_CURRENT_BINARY_DIR}/version_info.txt"
Expand All @@ -153,7 +166,7 @@ if (BUILD_EXAMPLES)
endif ()

# Testing
if (BUILD_TESTS)
if (BUILD_TESTING)
include(FetchContent)
FetchContent_Declare(
googletest
Expand Down
43 changes: 43 additions & 0 deletions ConfigurePkgConfig.pas
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
var
AppPath: string;

procedure ReplacePlaceholderInPkgConfig;
var
PkgConfigFile: TStringList;
Index: Integer;
ModifiedAppPath: string;
begin
// Read the contents of the liblite-string.pc file
PkgConfigFile := TStringList.Create;
try
PkgConfigFile.LoadFromFile(ExpandConstant('{app}\lib\pkgconfig\liblite-string.pc'));

// Modify the installation prefix to match the chosen installation destination
if PkgConfigFile.Count > 0 then
begin
// Replace backslashes with forward slashes
ModifiedAppPath := '';
for Index := 1 to Length(AppPath) do
begin
if AppPath[Index] = '\' then
ModifiedAppPath := ModifiedAppPath + '/'
else
ModifiedAppPath := ModifiedAppPath + AppPath[Index];
end;
// Update the prefix
PkgConfigFile[0] := 'prefix = "' + ModifiedAppPath + '"';
end;

// Write the modified contents back to the file
PkgConfigFile.SaveToFile(ExpandConstant('{app}\lib\pkgconfig\liblite-string.pc'));
finally
PkgConfigFile.Free;
end;
end;

// Run after the installation has completed
procedure DeinitializeSetup();
begin
AppPath := ExpandConstant('{app}');
ReplacePlaceholderInPkgConfig;
end;
42 changes: 26 additions & 16 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -101,14 +101,15 @@ cmake --build build --config Release -j 4
Replace `Ninja` with `"Unix Makefiles"` or another generator if Ninja is not available.
The `-G` option can be omitted to use the default generator.

To skip building tests and examples, add `-DBUILD_TESTS=OFF` and `-DBUILD_EXAMPLES=OFF`
To skip building tests and examples, add `-DBUILD_TESTING=OFF` and `-DBUILD_EXAMPLES=OFF`
to the Configuration step:

```bash
cmake -S . -B build -DCMAKE_BUILD_TYPE=Release -DCMAKE_C_COMPILER=gcc -DBUILD_TESTS=OFF -DBUILD_EXAMPLES=OFF -G Ninja
cmake -S . -B build -DCMAKE_BUILD_TYPE=Release -DCMAKE_C_COMPILER=gcc -DBUILD_TESTING=OFF -DBUILD_EXAMPLES=OFF -G Ninja
```

The library will be built in the `build` directory.
The library will be built in the `build` directory
(or `Release` subdirectory of the `build` directory, if using a multi-configuration generator).

### Building Manually

Expand Down Expand Up @@ -136,8 +137,8 @@ or use the full path to the MinGW `gcc` and `ar` executables.
For Visual Studio, use the Developer Command Prompt or Powershell:

```cmd
cl /c /O2 /std:clatest lite_string.c
lib /OUT:liblite-string.lib lite_string.obj
cl /c /O2 lite_string.c
lib /OUT:lite-string.lib lite_string.obj
```

`clang-cl` can be used instead of `cl` if available.
Expand All @@ -163,15 +164,15 @@ or [MSYS2](https://www.msys2.org/ "MSYS2"), follow the [UNIX instructions](#unix
For Visual Studio, use the Developer Command Prompt or Powershell:

```cmd
cl /c /O2 /std:clatest /LD lite_string.c
cl /c /O2 /LD lite_string.c
link /DLL /OUT:lite-string.dll lite_string.obj
```

## Installation and Uninstallation

### Installation

Pre-built binaries are available for Windows, Linux, and macOS are available on the
Pre-built binaries for Windows, Linux, and macOS are available on the
[Releases](https://github.com/dr8co/LiteString/releases "LiteString Releases") page.

The following packages are available:
Expand All @@ -180,10 +181,12 @@ The following packages are available:
|:--------------:|:-----------------------:|---------------------------------------|
| win64.exe | Windows 64-bit | Self installing executable |
| win64.zip | Windows 64-bit | Extraction to appropriate directories |
| x86_64.rpm | RPM-based Linux 64-bit | rpm installers, such as apt and dpkg |
| amd64.deb | DEB-based Linux 64-bit | deb installers, such as yum and dnf |
| minGW64.exe | MinGW-w64 Windows | Self installing executable |
| minGW64.zip | MinGW-w64 Windows | Extraction to appropriate directories |
| x86_64.rpm | RPM-based Linux, 64-bit | rpm installers, such as apt and dpkg |
| amd64.deb | DEB-based Linux, 64-bit | deb installers, such as yum and dnf |
| Linux.tar.gz | Linux 64-bit | Extraction to appropriate directories |
| Darwin.dmg | macOS 64-bit | Drag and Drop |
| Darwin.dmg | macOS 64-bit | Drag and Drop to Applications |
| Darwin.tar.gz | macOS 64-bit | Extraction to appropriate directories |

SHA-256 checksums are provided for each package to verify the integrity of the files.
Expand All @@ -192,12 +195,12 @@ Alternatively, you can install the library directly after
[building with CMake](#building-with-cmake-recommended):

```bash
# Install from the build directory.
# Install from the build directory. Run this from the project root directory.
cmake --install build --config Release
```

Escalation of privileges may be required to install the library system-wide.
Use `sudo` on UNIX or run the command prompt (or powershell) as an administrator on Windows.
Use `sudo` on UNIX or run the command prompt/PowerShell/Windows Terminal as an administrator on Windows.

### Uninstallation

Expand All @@ -210,7 +213,7 @@ For UNIX, use the following command:

```bash
# In the build directory, run:
xargs rm -f < install_manifest.txt # May require sudo
xargs rm -f < install_manifest.txt # May require sudo/escalation of privileges
```

For Windows, use the following command in the build directory:
Expand All @@ -235,7 +238,7 @@ To use the library, include the header file in your source code:
#include <lite_string.h>
// or:
#include "lite_string.h"
// Depending on whether the library was installed or not.
// Depending on the location of the header file.
...
```

Expand All @@ -247,6 +250,12 @@ To link the library with a CMake project, include the following lines in the `CM

```cmake
########### If the library was installed: ###########
# For Windows only: Update CMake module path.
list(APPEND CMAKE_MODULE_PATH "C:/path/to/LiteString/cmake")
# The path should point to the directory containing the LiteStringConfig.cmake file, depending on the installation.
# In UNIX, the library installation path is usually scanned automatically.
# Locate the required files.
find_package(LiteString REQUIRED)
Expand All @@ -256,6 +265,7 @@ target_link_libraries(yourTarget LiteString::lite-string)
######## If the library was built manually, or is not installed: ########
# Add the library to the project.
add_library(LiteString STATIC IMPORTED)
# Set the path to the library. For Windows, use the .lib file.
set_target_properties(LiteString PROPERTIES IMPORTED_LOCATION /path/to/libLiteString.a)
# Link the library to the target.
Expand Down Expand Up @@ -288,10 +298,10 @@ On Windows:

```powershell
# C
cl /O2 /std:clatest example.c /OUT:example.exe /link /LIBPATH:"C:\path\to\built\library" liblite-string.lib
cl /O2 example.c /OUT:example.exe /link /LIBPATH:"C:\path\to\built\library" lite-string.lib
# C++
cl /O2 /std:c++20 example.cpp /OUT:example.exe /link /LIBPATH:"C:\path\to\built\library" liblite-string.lib
cl /O2 /std:c++20 /EHsc example.cpp /OUT:example.exe /link /LIBPATH:"C:\path\to\built\library" lite-string.lib
```

## API
Expand Down
3 changes: 2 additions & 1 deletion cmake/Packing.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ set(CPACK_COMPONENT_HEADERS_DISPLAY_NAME "Headers")
set(CPACK_COMPONENT_HEADERS_DESCRIPTION "Header files for LiteString.")
set(CPACK_COMPONENT_HEADERS_REQUIRED ON)

set(CPACK_COMPONENT_DATA_DISPLAY_NAME "Data")
set(CPACK_COMPONENT_DATA_DISPLAY_NAME "Version Info")
set(CPACK_COMPONENT_DATA_DESCRIPTION "Information about this build of LiteString.")

# Resource files
Expand Down Expand Up @@ -129,5 +129,6 @@ set(CPACK_INNOSETUP_SETUP_DisableWelcomePage OFF)
set(CPACK_INNOSETUP_SETUP_AppCopyright "Copyright (C) 2024 Ian Duncan")
set(CPACK_INNOSETUP_SETUP_AppComments "For more information, visit https://github.com/dr8co/LiteString")
set(CPACK_INNOSETUP_SETUP_VersionInfoVersion "${CPACK_PACKAGE_VERSION}")
set(CPACK_INNOSETUP_CODE_FILES "${CMAKE_CURRENT_SOURCE_DIR}/ConfigurePkgConfig.pas")

include(CPack)
18 changes: 10 additions & 8 deletions examples/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,12 +13,12 @@ For building the LiteString library, refer to the

The text file should not be bigger than 1MB.

```bash
```console
# Compile and link the example
gcc -std=c2x -o word_stats word_stats.c -L /path/to/built/lite-string/library -llite-string
ian@github:examples$ gcc -std=c2x -o word_stats word_stats.c -L /path/to/built/lite-string/library -llite-string

# Run the example
./word_stats blindtext.txt
ian@github:examples$ ./word_stats blindtext.txt
# Expected output:
Word count: 5800
Character count: 33355
Expand All @@ -29,15 +29,15 @@ Average word length: 5.75

[grep clone](./cheap_grep.cpp) - A simple clone of the `grep` command.

```bash
```console
# Compile and link the example
g++ -std=c++20 -o cheap_grep cheap_grep.cpp -L /path/to/built/lite-string/library -llite-string
ian@github:examples$ g++ -std=c++20 -o cheap_grep cheap_grep.cpp -L /path/to/built/lite-string/library -llite-string

# Run the example
./cheap_grep -i "ipsum dolor" blindtext.txt
ian@github:examples$ ./cheap_grep -i "ipsum dolor" blindtext.txt

# The program can also read from standard input, when the file name is replaced with a hyphen
cat blindtext.txt | ./cheap_grep -i "ipsum dolor" -
ian@github:examples$ cat blindtext.txt | ./cheap_grep -i "ipsum dolor" -
./cheap_grep -i "lorem ipsum dolor sit amet consectetur adipiscing" - < blindtext.txt
```

Expand All @@ -52,7 +52,9 @@ cmake -S . -B build -DCMAKE_BUILD_TYPE=Release -G Ninja
cmake --build build --config Release -j 4
```

The examples can be found in the `build` directory.
The examples can be run from the `build` directory.
(Or, from the `Release` subdirectory of `build` directory,
if you have built with a multi-configuration generator, like Visual Studio.)

```bash
# From this directory (examples), run:
Expand Down
File renamed without changes.
2 changes: 1 addition & 1 deletion liblite-string.pc.in → input_files/liblite-string.pc.in
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
prefix="@CMAKE_INSTALL_PREFIX@
prefix="@CMAKE_INSTALL_PREFIX@"
exec_prefix="${prefix}"
libdir="${prefix}/@CMAKE_INSTALL_LIBDIR@"
includedir="${prefix}/@CMAKE_INSTALL_INCLUDEDIR@"
Expand Down
File renamed without changes.
Loading

0 comments on commit 68ea09f

Please sign in to comment.