Skip to content

Commit e55d316

Browse files
committed
WASI build fix
1 parent 20416c1 commit e55d316

File tree

7 files changed

+40
-10
lines changed

7 files changed

+40
-10
lines changed

src/opt/eslim/synthesisEngine.tpp

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -614,7 +614,11 @@ namespace eSLIM {
614614
// sprintf( pCommand, "%s -q %s > %s", pKissat, pFileNameIn, pFileNameOut );
615615

616616
sprintf( pCommand, "%s -q %s > %s", pKissat, pFileNameIn, pFileNameOut );
617+
#ifdef __wasm
618+
if ( 1 ) {
619+
#else
617620
if ( system( pCommand ) == -1 ) {
621+
#endif
618622
std::cerr << "Command " << pCommand << " failed\n";
619623
return nullptr;
620624
}

src/sat/cadical/cadical_file.cpp

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,9 @@ extern "C" {
3333
#else
3434

3535
extern "C" {
36+
#if !defined(__wasm)
3637
#include <sys/wait.h>
38+
#endif
3739
#include <unistd.h>
3840
}
3941

@@ -245,6 +247,7 @@ void File::delete_str_vector (std::vector<char *> &argv) {
245247

246248
FILE *File::open_pipe (Internal *internal, const char *fmt,
247249
const char *path, const char *mode) {
250+
#if !defined(__wasm)
248251
#ifdef CADICAL_QUIET
249252
(void) internal;
250253
#endif
@@ -269,6 +272,9 @@ FILE *File::open_pipe (Internal *internal, const char *fmt,
269272
FILE *res = popen (cmd, mode);
270273
delete[] cmd;
271274
return res;
275+
#else
276+
return 0;
277+
#endif
272278
}
273279

274280
FILE *File::read_pipe (Internal *internal, const char *fmt, const int *sig,
@@ -285,7 +291,7 @@ FILE *File::read_pipe (Internal *internal, const char *fmt, const int *sig,
285291
return open_pipe (internal, fmt, path, "r");
286292
}
287293

288-
#ifndef _WIN32
294+
#if !defined(_WIN32) && !defined(__wasm)
289295

290296
#if defined(__APPLE__) || defined(__MACH__)
291297
static std::mutex compressed_file_writing_mutex;
@@ -420,7 +426,7 @@ File *File::read (Internal *internal, const char *path) {
420426
File *File::write (Internal *internal, const char *path) {
421427
FILE *file;
422428
int close_output = 3, child_pid = 0;
423-
#ifndef _WIN32
429+
#if !defined(_WIN32) && !defined(__wasm)
424430
if (has_suffix (path, ".xz"))
425431
file = write_pipe (internal, "xz -c", path, child_pid);
426432
else if (has_suffix (path, ".bz2"))
@@ -456,12 +462,14 @@ void File::close (bool print) {
456462
MSG ("closing file '%s'", name ());
457463
fclose (file);
458464
}
465+
#if !defined(__wasm)
459466
if (close_file == 2) {
460467
if (print)
461468
MSG ("closing input pipe to read '%s'", name ());
462469
pclose (file);
463470
}
464-
#ifndef _WIN32
471+
#endif
472+
#if !defined(_WIN32) && !defined(__wasm)
465473
if (close_file == 3) {
466474
if (print)
467475
MSG ("closing output pipe to write '%s'", name ());

src/sat/cadical/cadical_random.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -84,7 +84,7 @@ ABC_NAMESPACE_IMPL_END
8484
// work. As an additional measure to increase the possibility to get
8585
// different seeds we are now also using network addresses (explicitly).
8686

87-
#ifndef WIN32
87+
#if !defined(_WIN32) && !defined(__wasm)
8888

8989
extern "C" {
9090
#include <ifaddrs.h>
@@ -110,7 +110,7 @@ static uint64_t hash_network_addresses () {
110110
// you really need to run 'mobical' on a Windows cluster where each node
111111
// has identical IP addresses.
112112

113-
#ifndef WIN32
113+
#if !defined(_WIN32) && !defined(__wasm)
114114
struct ifaddrs *addrs;
115115
if (!getifaddrs (&addrs)) {
116116
for (struct ifaddrs *addr = addrs; addr; addr = addr->ifa_next) {

src/sat/cadical/cadical_resources.cpp

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -131,10 +131,14 @@ uint64_t maximum_resident_set_size () {
131131
// This seems to work on Linux (man page says since Linux 2.6.32).
132132

133133
uint64_t maximum_resident_set_size () {
134+
#ifdef __wasm
135+
return 0;
136+
#else
134137
struct rusage u;
135138
if (getrusage (RUSAGE_SELF, &u))
136139
return 0;
137140
return ((uint64_t) u.ru_maxrss) << 10;
141+
#endif
138142
}
139143

140144
// Unfortunately 'getrusage' on Linux does not support current resident set

src/sat/cadical/cadical_signal.cpp

Lines changed: 16 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -7,11 +7,13 @@
77
/*------------------------------------------------------------------------*/
88

99
#include <cassert>
10+
#if !defined(__wasm)
1011
#include <csignal>
12+
#endif
1113

1214
/*------------------------------------------------------------------------*/
1315

14-
#ifndef WIN32
16+
#if !defined(_WIN32) && !defined(__wasm)
1517
extern "C" {
1618
#include <unistd.h>
1719
}
@@ -28,7 +30,7 @@ namespace CaDiCaL {
2830
static volatile bool caught_signal = false;
2931
static Handler *signal_handler;
3032

31-
#ifndef WIN32
33+
#if !defined(_WIN32) && !defined(__wasm)
3234

3335
static volatile bool caught_alarm = false;
3436
static volatile bool alarm_set = false;
@@ -38,6 +40,7 @@ void Handler::catch_alarm () { catch_signal (SIGALRM); }
3840

3941
#endif
4042

43+
#if !defined(__wasm)
4144
#define SIGNALS \
4245
SIGNAL (SIGABRT) \
4346
SIGNAL (SIGINT) \
@@ -47,8 +50,9 @@ void Handler::catch_alarm () { catch_signal (SIGALRM); }
4750
#define SIGNAL(SIG) static void (*SIG##_handler) (int);
4851
SIGNALS
4952
#undef SIGNAL
53+
#endif
5054

51-
#ifndef WIN32
55+
#if !defined(_WIN32) && !defined(__wasm)
5256

5357
static void (*SIGALRM_handler) (int);
5458

@@ -66,18 +70,21 @@ void Signal::reset_alarm () {
6670

6771
void Signal::reset () {
6872
signal_handler = 0;
73+
#if !defined(__wasm)
6974
#define SIGNAL(SIG) \
7075
(void) signal (SIG, SIG##_handler); \
7176
SIG##_handler = 0;
7277
SIGNALS
7378
#undef SIGNAL
7479
#ifndef WIN32
7580
reset_alarm ();
81+
#endif
7682
#endif
7783
caught_signal = false;
7884
}
7985

8086
const char *Signal::name (int sig) {
87+
#if !defined(__wasm)
8188
#define SIGNAL(SIG) \
8289
if (sig == SIG) \
8390
return #SIG;
@@ -86,6 +93,7 @@ const char *Signal::name (int sig) {
8693
#ifndef WIN32
8794
if (sig == SIGALRM)
8895
return "SIGALRM";
96+
#endif
8997
#endif
9098
return "UNKNOWN";
9199
}
@@ -97,6 +105,7 @@ const char *Signal::name (int sig) {
97105
// exclusive access to. All these solutions are painful and not elegant.
98106

99107
static void catch_signal (int sig) {
108+
#if !defined(__wasm)
100109
#ifndef WIN32
101110
if (sig == SIGALRM && absolute_real_time () >= alarm_time) {
102111
if (!caught_alarm) {
@@ -116,16 +125,19 @@ static void catch_signal (int sig) {
116125
Signal::reset ();
117126
::raise (sig);
118127
}
128+
#endif
119129
}
120130

121131
void Signal::set (Handler *h) {
132+
#if !defined(__wasm)
122133
signal_handler = h;
123134
#define SIGNAL(SIG) SIG##_handler = signal (SIG, catch_signal);
124135
SIGNALS
125136
#undef SIGNAL
137+
#endif
126138
}
127139

128-
#ifndef WIN32
140+
#if !defined(_WIN32) && !defined(__wasm)
129141

130142
void Signal::alarm (int seconds) {
131143
CADICAL_assert (seconds >= 0);

src/sat/cadical/file.hpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,7 @@ class File {
6666
const char *mode);
6767
static FILE *read_pipe (Internal *, const char *fmt, const int *sig,
6868
const char *path);
69-
#ifndef WIN32
69+
#if !defined(_WIN32) && !defined(__wasm)
7070
static FILE *write_pipe (Internal *, const char *fmt, const char *path,
7171
int &child_pid);
7272
#endif

src/sat/cadical/internal.hpp

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,9 @@
1717
#include <cctype>
1818
#include <climits>
1919
#include <cmath>
20+
#if !defined(__wasm)
2021
#include <csignal>
22+
#endif
2123
#include <cstdio>
2224
#include <cstdlib>
2325
#include <cstring>

0 commit comments

Comments
 (0)