Skip to content

Commit 02a45c7

Browse files
committed
fix: dev: prep msvc cl and github environment for conda on windows
* disable pthreads when using msvc compiler * fix build errors on windows, including the following: missing symbols, non-const, designated initializers, and non-standard explicit type conversions * uncork sys/stat.h and add missing win32 define for S_ISDIR * add clang++ flag to get errors on c++20 initializers and set C99 std Signed-off-by: Stephen L Arnold <sarnold@vctlabs.com>
1 parent 786bf5e commit 02a45c7

File tree

15 files changed

+143
-102
lines changed

15 files changed

+143
-102
lines changed

.github/workflows/conda-dev.yml

Lines changed: 29 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -34,27 +34,54 @@ jobs:
3434
- os: 'windows-2019'
3535
generator: 'Ninja'
3636
build_type: 'Debug'
37-
extra_args: '-DBUILD_SHARED_LIBS=OFF -DABC_USE_NO_READLINE=ON -DVENDOR_GTEST=ON'
37+
extra_args: '-DBUILD_SHARED_LIBS=OFF -DABC_USE_NO_PTHREADS=ON -DABC_USE_NO_READLINE=ON -DVENDOR_GTEST=ON'
3838
env:
3939
OS: ${{ matrix.os }}
4040
PY_VER: ${{ matrix.python-version }}
4141
PYTHONIOENCODING: utf-8
4242
CMAKE_ARGS: ${{ matrix.use_namespace && '-DABC_USE_NAMESPACE=xxx' || '' }}
4343

4444
steps:
45+
#- if: matrix.os == 'windows-2019'
46+
#name: Install newer windows compiler
47+
#id: install_cc
48+
#uses: rlalik/setup-cpp-compiler@master
49+
#with:
50+
#compiler: g++-11.2.0
51+
52+
#- if: matrix.os == 'windows-2019'
53+
#name: Use compiler
54+
#shell: bash -l {0}
55+
#env:
56+
#CC: ${{ steps.install_cc.outputs.cc }}
57+
#CXX: ${{ steps.install_cc.outputs.cxx }}
58+
#run: |
59+
4560
- uses: actions/checkout@v4
4661

4762
- name: Setup base python
4863
uses: actions/setup-python@v5
4964
with:
5065
python-version: ${{ matrix.python-version }}
5166

67+
- name: Prepare build environment for windows
68+
if: runner.os == 'Windows'
69+
uses: ilammy/msvc-dev-cmd@v1
70+
with:
71+
arch: x64
72+
73+
- name: Env (Windows)
74+
if: runner.os == 'Windows'
75+
run: |
76+
echo "CXX=cl.exe" >> $GITHUB_ENV
77+
echo "CC=cl.exe" >> $GITHUB_ENV
78+
5279
- name: Cache conda
5380
id: cache
5481
uses: actions/cache@v4
5582
env:
5683
# Increase this value to reset cache if environment.devenv.yml has not changed
57-
CACHE_NUMBER: 1
84+
CACHE_NUMBER: 2
5885
with:
5986
path: ~/conda_pkgs_dir
6087
key: ${{ runner.os }}-conda-${{ env.CACHE_NUMBER }}-${{ hashFiles('environment.devenv.yml') }}

CMakeLists.txt

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,8 @@ set(CMAKE_CXX_STANDARD 17)
2828
set(CMAKE_CXX_STANDARD_REQUIRED ON)
2929
set(CMAKE_CXX_EXTENSIONS OFF)
3030

31+
set(CMAKE_C_STANDARD 99)
32+
3133
# MSVC has symbols hidden by default. On GCC and Clang we need to explicitly
3234
# set the visibility to hidden to achieve the same result and then manually
3335
# expose what we need. This results in smaller abc dynamic library and thus
@@ -160,6 +162,10 @@ if(CMAKE_CXX_COMPILER_ID STREQUAL "GNU" AND NOT (CMAKE_CXX_COMPILER_VERSION VERS
160162
target_compile_options(abc_interface
161163
INTERFACE -fno-aggressive-loop-optimizations -Wno-unused-but-set-variable
162164
)
165+
elseif(CMAKE_CXX_COMPILER_ID STREQUAL "Clang" OR CMAKE_CXX_COMPILER_ID STREQUAL "AppleClang")
166+
target_compile_options(abc_interface
167+
INTERFACE -Werror=c99-designator
168+
)
163169
endif()
164170

165171
if(CMAKE_CXX_COMPILER_ID STREQUAL "GNU" OR CMAKE_CXX_COMPILER_ID STREQUAL "Clang" OR CMAKE_CXX_COMPILER_ID STREQUAL "AppleClang")
@@ -182,6 +188,7 @@ elseif(CMAKE_CXX_COMPILER_ID STREQUAL "MSVC")
182188
"_MBCS"
183189
"_SCL_SECURE_NO_WARNINGS"
184190
"_CRT_SECURE_NO_WARNINGS"
191+
"_CRT_INTERNAL_NONSTDC_NAMES"
185192
"_XKEYCHECK_H"
186193
"_ALLOW_KEYWORD_MACROS=1"
187194
)

Makefile

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -71,6 +71,7 @@ ifdef ABC_USE_NAMESPACE
7171
DLIBS := -lstdc++
7272
$(info $(MSG_PREFIX)Compiling in namespace $(ABC_NAMESPACE))
7373
else
74+
CFLAGS += -std=gnu99
7475
CXXFLAGS := $(CFLAGS)
7576
ABC_USE_LIBSTDCXX := 1
7677
endif

src/base/abc/abcHieNew.c

Lines changed: 76 additions & 76 deletions
Large diffs are not rendered by default.

src/base/abci/abcNpn.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -340,7 +340,7 @@ void Abc_TruthNpnPerform( Abc_TtStore_t * p, int NpnType, int fVerbose )
340340
// typedef unsigned(*TtCanonicizeFunc)(Abc_TtHieMan_t * p, word * pTruth, int nVars, char * pCanonPerm, int flag);
341341
unsigned Abc_TtCanonicizeWrap(TtCanonicizeFunc func, Abc_TtHieMan_t * p, word * pTruth, int nVars, char * pCanonPerm, int flag);
342342
unsigned Abc_TtCanonicizeAda(Abc_TtHieMan_t * p, word * pTruth, int nVars, char * pCanonPerm, int iThres);
343-
unsigned Abc_TtCanonicizeCA(Abc_TtHieMan_t * p, word * pTruth, int nVars, char * pCanonPerm, int iThres);
343+
extern unsigned Abc_TtCanonicizeCA(Abc_TtHieMan_t * p, word * pTruth, int nVars, char * pCanonPerm, int iThres);
344344

345345
Abc_TtHieMan_t * pMan = Abc_TtHieManStart(p->nVars, 5);
346346
for ( i = 0; i < p->nFuncs; i++ )

src/sat/kissat/bump.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -85,7 +85,7 @@ static void move_analyzed_variables_to_front_of_queue (kissat *solver) {
8585
const links *const links = solver->links;
8686
for (all_stack (unsigned, idx, solver->analyzed)) {
8787
// clang-format off
88-
const datarank rank = { .data = idx, .rank = links[idx].stamp };
88+
const datarank rank = { /*.data = */idx, /*.rank = */links[idx].stamp }; // c++20 only
8989
// clang-format on
9090
PUSH_STACK (solver->ranks, rank);
9191
}

src/sat/kissat/colors.c

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
#include "colors.h"
22

33
#if defined(WIN32) && !defined(__MINGW32__)
4+
#include <io.h>
45
#define isatty _isatty
56
#else
67
#include <unistd.h>

src/sat/kissat/congruence.c

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -846,7 +846,7 @@ static void add_binary_clause (closure *closure, unsigned a, unsigned b) {
846846
kissat_new_binary_clause (solver, a, b);
847847
else {
848848
kissat_new_unwatched_binary_clause (solver, a, b);
849-
litpair litpair = {.lits = {a < b ? a : b, a < b ? b : a}};
849+
litpair litpair = {/*.lits = */{a < b ? a : b, a < b ? b : a}}; // c++20 only
850850
PUSH_STACK (closure->binaries, litpair);
851851
}
852852
}
@@ -2500,7 +2500,7 @@ static bool indexed_binary (closure *closure, unsigned lit,
25002500
SWAP (unsigned, lit, other);
25012501
if (lit > other)
25022502
SWAP (unsigned, lit, other);
2503-
binary_clause binary = {.lits = {lit, other}};
2503+
binary_clause binary = {/*.lits = */{lit, other}}; // c++20 only
25042504
const unsigned hash = hash_binary (closure, &binary);
25052505
const size_t size = bintab->size;
25062506
const size_t size2 = bintab->size2;
@@ -2986,7 +2986,7 @@ static void index_binary (closure *closure, unsigned lit, unsigned other) {
29862986
KISSAT_assert (lit < other);
29872987
binary_hash_table *bintab = &closure->bintab;
29882988
KISSAT_assert (!binaries_hash_table_is_full (bintab));
2989-
binary_clause binary = {.lits = {lit, other}};
2989+
binary_clause binary = {/*.lits = */{lit, other}}; // c++20 only
29902990
const unsigned hash = hash_binary (closure, &binary);
29912991
const size_t size = bintab->size;
29922992
const size_t size2 = bintab->size2;
@@ -3416,10 +3416,10 @@ static void copy_conditional_equivalences (kissat *solver, unsigned lit,
34163416
KISSAT_assert (second != INVALID_LIT);
34173417
litpair pair;
34183418
if (first < second)
3419-
pair = (litpair){.lits = {first, second}};
3419+
pair.lits[0] = first, pair.lits[1] = second;
34203420
else {
34213421
KISSAT_assert (second < first);
3422-
pair = (litpair){.lits = {second, first}};
3422+
pair.lits[0] = second, pair.lits[1] = first;
34233423
}
34243424
LOG ("literal %s conditional binary clause %s %s", LOGLIT (lit),
34253425
LOGLIT (first), LOGLIT (second));
@@ -3491,13 +3491,13 @@ static void search_condeq (closure *closure, unsigned lit, unsigned pos_lit,
34913491
KISSAT_assert (first < second);
34923492
check_ternary (closure, lit, first, NOT (second));
34933493
check_ternary (closure, lit, NOT (first), second);
3494-
litpair equivalence = {.lits = {first, second}};
3494+
litpair equivalence = {/*.lits = */{first, second}}; // c++20 only
34953495
PUSH_STACK (*condeq, equivalence);
34963496
if (NEGATED (second)) {
3497-
litpair inverse_equivalence = {.lits = {NOT (second), NOT (first)}};
3497+
litpair inverse_equivalence = {/*.lits = */{NOT (second), NOT (first)}}; // c++20 only
34983498
PUSH_STACK (*condeq, inverse_equivalence);
34993499
} else {
3500-
litpair inverse_equivalence = {.lits = {second, first}};
3500+
litpair inverse_equivalence = {/*.lits = */{second, first}}; // c++20 only
35013501
PUSH_STACK (*condeq, inverse_equivalence);
35023502
}
35033503
}
@@ -4549,7 +4549,7 @@ static void forward_subsume_matching_clauses (closure *closure) {
45494549
}
45504550
const reference ref = kissat_reference_clause (solver, c);
45514551
KISSAT_assert (size <= UINT_MAX);
4552-
refsize refsize = {.ref = ref, .size = (unsigned)size};
4552+
refsize refsize = {/*.ref = */ref, /*.size = */(unsigned)size}; // c++20 only
45534553
PUSH_STACK (candidates, refsize);
45544554
}
45554555
DEALLOC (matchable, VARS);

src/sat/kissat/dense.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,7 @@ static void flush_large_watches (kissat *solver, litpairs *irredundant) {
6060
if (irredundant) {
6161
const unsigned other = watch.binary.lit;
6262
if (lit < other) {
63-
const litpair litpair = {.lits = {lit, other}};
63+
const litpair litpair = {/*.lits = */{lit, other}}; // c++20 only
6464
PUSH_STACK (*irredundant, litpair);
6565
}
6666
} else

src/sat/kissat/file.c

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,14 +5,19 @@
55
#include <errno.h>
66
#include <stdlib.h>
77
#include <string.h>
8-
#include <sys/stat.h>
8+
99
#include <sys/types.h>
10+
#include <sys/stat.h>
1011

1112
#ifdef WIN32
13+
#include <io.h>
1214
#define unlink _unlink
1315
#define access _access
1416
#define R_OK 4
1517
#define W_OK 2
18+
#ifndef S_ISDIR
19+
# define S_ISDIR(mode) (((mode) & _S_IFMT) == _S_IFDIR)
20+
#endif
1621
#else
1722
#include <unistd.h>
1823
#endif

0 commit comments

Comments
 (0)