diff --git a/.github/workflows/windows.yml b/.github/workflows/windows.yml index 05b1435..556965f 100644 --- a/.github/workflows/windows.yml +++ b/.github/workflows/windows.yml @@ -21,8 +21,33 @@ on: - '**/windows.yml' jobs: + msvc: + runs-on: windows-latest + steps: + - uses: actions/checkout@v6 + + - name: Set up MSVC environment + uses: ilammy/msvc-dev-cmd@v1 + with: + arch: x64 + + - name: Install Meson and Ninja + run: pip install meson ninja + + - name: Meson setup + env: + PKG_CONFIG_PATH: ${{ env.VCPKG_INSTALLATION_ROOT }}\installed\x64-windows\lib\pkgconfig + run: | + meson setup _build -Db_sanitize=none + + - name: Build + run: meson compile -C _build + + - name: Test + run: meson test --no-stdsplit -v -C _build MSYS2: runs-on: windows-latest + needs: msvc steps: - uses: actions/checkout@v6 - uses: msys2/setup-msys2@v2 diff --git a/deckhandler.c b/deckhandler.c index 5dd1033..31b5b89 100644 --- a/deckhandler.c +++ b/deckhandler.c @@ -73,8 +73,8 @@ static void DH_init_deck(DH_Deck *deck) { deck->top_card = 0; int card = 0; - int suit = 0; - int face = DH_CARD_ACE; + int8_t suit = 0; + int8_t face = DH_CARD_ACE; while (suit < DH_SUIT_MAX) { deck->card[card].face_val = face++; diff --git a/deckhandler.h b/deckhandler.h index 89f3624..8c4c011 100644 --- a/deckhandler.h +++ b/deckhandler.h @@ -20,6 +20,16 @@ extern "C" { #include #include +#if defined(_WIN32) || defined(__CYGWIN__) +# ifdef DECKHANDLER_BUILD +# define DH_API __declspec(dllexport) +# else +# define DH_API __declspec(dllimport) +# endif +#else +# define DH_API +#endif + /// Number of face values in a standard card deck (Ace to King). #define NUM_OF_FACES 13 @@ -64,12 +74,12 @@ typedef struct { int8_t suit; ///< Suit of the card (see enum) } DH_Card; -extern const DH_Card DH_card_back; -extern const DH_Card DH_card_null; +extern DH_API const DH_Card DH_card_back; +extern DH_API const DH_Card DH_card_null; -bool DH_is_card_back(DH_Card a); +DH_API bool DH_is_card_back(DH_Card a); -bool DH_is_card_null(DH_Card a); +DH_API bool DH_is_card_null(DH_Card a); /** * @DH_Deck @@ -86,14 +96,14 @@ typedef struct { * @param initstate Initialization state value. * @param initseq Initialization sequence value. */ -void DH_pcg_srand(uint64_t initstate, uint64_t initseq); +DH_API void DH_pcg_srand(uint64_t initstate, uint64_t initseq); /** * @brief Automatically seed the PCG random number generator with internal defaults. * * Uses `time(NULL)` and pointer values for entropy. */ -void DH_pcg_srand_auto(void); +DH_API void DH_pcg_srand_auto(void); /** * @brief Create and initialize a new deck of cards. @@ -103,7 +113,7 @@ void DH_pcg_srand_auto(void); * * @return A fully initialized deck of cards. */ -DH_Deck DH_get_new_deck(void); +DH_API DH_Deck DH_get_new_deck(void); /** * @brief Deal the top card from the deck. @@ -115,14 +125,14 @@ DH_Deck DH_get_new_deck(void); * @param deck Pointer to the deck from which to deal a card. * @return The card at the current top position of the deck. */ -DH_Card DH_deal_top_card(DH_Deck *deck); +DH_API DH_Card DH_deal_top_card(DH_Deck *deck); /** * @brief Shuffle a deck of cards using the PCG random number generator. * * @param deck_dh Pointer to the deck to shuffle. */ -void DH_shuffle_deck(DH_Deck *deck_dh); +DH_API void DH_shuffle_deck(DH_Deck *deck_dh); /** * @brief Cuts the deck at the specified index, simulating a real-life card cut. @@ -140,7 +150,7 @@ void DH_shuffle_deck(DH_Deck *deck_dh); * * @see DH_shuffle_deck */ -void DH_cut_deck(DH_Deck *deck, int cut_point); +DH_API void DH_cut_deck(DH_Deck *deck, int cut_point); /** * @brief Get the string name of a card's face value (e.g., "Ace", "10", "King"). @@ -148,7 +158,7 @@ void DH_cut_deck(DH_Deck *deck, int cut_point); * @param card The card to query. * @return Pointer to a constant string. */ -const char *DH_get_card_face(DH_Card card); +DH_API const char *DH_get_card_face(DH_Card card); /** * @brief Get the string name of a card's suit (e.g., "Hearts", "Spades"). @@ -156,7 +166,7 @@ const char *DH_get_card_face(DH_Card card); * @param card The card to query. * @return Pointer to a constant string. */ -const char *DH_get_card_suit(DH_Card card); +DH_API const char *DH_get_card_suit(DH_Card card); /** * @brief Get the Unicode symbol representing the card's suit. @@ -166,9 +176,9 @@ const char *DH_get_card_suit(DH_Card card); * @param card The card to query. * @return Pointer to a UTF-8 encoded Unicode string. */ -const char *DH_get_card_unicode_suit(DH_Card card); +DH_API const char *DH_get_card_unicode_suit(DH_Card card); -const char *DH_get_unicode_suit(DH_suit suit); +DH_API const char *DH_get_unicode_suit(DH_suit suit); /** * @brief Get the string name of a face value given its integer representation. @@ -176,7 +186,7 @@ const char *DH_get_unicode_suit(DH_suit suit); * @param val Integer value representing a face (1–13). * @return Pointer to a constant string. */ -const char *DH_get_card_face_str(int val); +DH_API const char *DH_get_card_face_str(int val); #ifdef __cplusplus } diff --git a/meson.build b/meson.build index d986333..c498a1d 100644 --- a/meson.build +++ b/meson.build @@ -1,7 +1,7 @@ project( 'deckhandler', 'c', - version: '0.1.0999', + version: '0.0.1', meson_version: '>= 0.56.0', default_options: ['warning_level=3', 'c_std=c99'], ) @@ -20,6 +20,18 @@ extra_flags = [ add_project_arguments(cc.get_supported_arguments(extra_flags), language: 'c') +# Parse version components +version_components = meson.project_version().split('.') +major_version = version_components[0] +minor_version = version_components[1] +patch_version = version_components[2] + +conf = configuration_data() +conf.set('DH_VERSION_MAJOR', major_version) +conf.set('DH_VERSION_MINOR', minor_version) +conf.set('DH_VERSION_PATCH', patch_version) +config_h = configure_file(output : 'config.h', configuration : conf) + src = files('deckhandler.c') pcg = subproject('pcg') @@ -28,6 +40,7 @@ pcg_dep = pcg.get_variable('pcg_dep') buildtarget = library( meson.project_name(), src, + c_args: '-DDECKHANDLER_BUILD', dependencies: pcg_dep, version: meson.project_version(), install: not meson.is_subproject(), diff --git a/subprojects/pcg/meson.build b/subprojects/pcg/meson.build index 4d32243..e84e6b7 100644 --- a/subprojects/pcg/meson.build +++ b/subprojects/pcg/meson.build @@ -6,6 +6,8 @@ project( default_options: ['warning_level=3', 'c_std=c99'], ) +cc = meson.get_compiler('c') + extra_flags = [ '-fno-common', '-fstack-protector-strong', @@ -16,7 +18,7 @@ extra_flags = [ '-Werror=strict-aliasing', ] -add_project_arguments(extra_flags, language: 'c') +add_project_arguments(cc.get_supported_arguments(extra_flags), language: 'c') _pcg = static_library('pcg', 'pcg_basic.c') diff --git a/test/test_01.c b/test/test_01.c index 01d4253..8e8701d 100644 --- a/test/test_01.c +++ b/test/test_01.c @@ -95,7 +95,7 @@ int main(int argc, char *argv[]) { } while (deals_num++ < deals_max); puts("\n\n\t]=[ Create 4 decks, shuffle each one, and deal them all out ]=[\n"); - int total_decks = 4; + enum { total_decks = 4 }; DH_Deck deck_num[total_decks]; for (int i = 0; i < total_decks; i++) deck_num[i] = DH_get_new_deck();