Skip to content

Commit

Permalink
COMP: libminc WASI undefined symbols
Browse files Browse the repository at this point in the history
wasm-ld-18: error: /ITK-build/lib/libitkminc2-5.4.a(files.c.o): undefined symbol: system
wasm-ld-18: error: /ITK-build/lib/libitkminc2-5.4.a(files.c.o): undefined symbol: system
wasm-ld-18: error: /ITK-build/lib/libitkminc2-5.4.a(volume.c.o): undefined symbol: gethostname
wasm-ld-18: error: /ITK-build/lib/libitkminc2-5.4.a(volume.c.o): undefined symbol: getpid
  • Loading branch information
thewtex committed Aug 3, 2024
1 parent d03c261 commit 31b51f2
Show file tree
Hide file tree
Showing 3 changed files with 33 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -1486,6 +1486,7 @@ MNCAPI int micreate_ident( char * id_str, size_t length )
char *temp_ptr;
char time_str[26];
int result;
pid_t pid;

if (gethostname(host_str, sizeof(host_str)) != 0) {
strcpy(host_str, "unknown");
Expand All @@ -1508,14 +1509,20 @@ MNCAPI int micreate_ident( char * id_str, size_t length )
#endif
strftime(time_str, sizeof(time_str), "%Y.%m.%d.%H.%M.%S", &tm_buf);

#ifdef __wasi__
pid = 0;
#else
pid = getpid();
#endif

result = snprintf(id_str, length, "%s%c%s%c%s%c%u%c%u",
user_str,
MI_IDENT_SEP,
host_str,
MI_IDENT_SEP,
time_str,
MI_IDENT_SEP,
getpid(),
pid,
MI_IDENT_SEP,
identx++);
return (result);
Expand Down
11 changes: 9 additions & 2 deletions Modules/ThirdParty/MINC/src/libminc/libsrc2/volume.c
Original file line number Diff line number Diff line change
Expand Up @@ -72,9 +72,10 @@ static int _generate_ident( char * id_str, size_t length )
char *temp_ptr;
char time_str[26];
int result;
pid_t pid;

// Linking in ws2_32 for gethostname is problematic with static libraries.
#ifdef _WIN32
#if defined(_WIN32) || defined(__wasi__)
strcpy(host_str, "unknown");
#else
if (gethostname(host_str, sizeof(host_str)) != 0) {
Expand All @@ -99,11 +100,17 @@ static int _generate_ident( char * id_str, size_t length )
#endif
strftime(time_str, sizeof(time_str), "%Y.%m.%d.%H.%M.%S", &tm_buf);

#ifdef __wasi__
pid = 0;
#else
pid = getpid();
#endif

result = snprintf(id_str, length, "%s:%s:%s:%u:%u",
user_str,
host_str,
time_str,
getpid(),
pid,
identx++);
return result;
}
Expand Down
16 changes: 16 additions & 0 deletions Modules/ThirdParty/MINC/src/libminc/volume_io/Prog_utils/files.c
Original file line number Diff line number Diff line change
Expand Up @@ -489,6 +489,9 @@ VIOAPI VIO_Status copy_file(
concat_to_string( &command, " " );
concat_to_string( &command, dest_expanded );

#ifdef __wasi__
status = VIO_ERROR;
#else
if( system( command ) != 0 )
{
print_error( "Error copying file %s to %s: ",
Expand All @@ -498,6 +501,7 @@ VIOAPI VIO_Status copy_file(
}
else
status = VIO_OK;
#endif

delete_string( src_expanded );
delete_string( dest_expanded );
Expand Down Expand Up @@ -534,6 +538,9 @@ VIOAPI VIO_Status move_file(
concat_to_string( &command, " " );
concat_to_string( &command, dest_expanded );

#ifdef __wasi__
status = VIO_ERROR;
#else
if( system( command ) != 0 )
{
print_error( "Error moving file %s to %s: ",
Expand All @@ -543,6 +550,7 @@ VIOAPI VIO_Status move_file(
}
else
status = VIO_OK;
#endif

delete_string( src_expanded );
delete_string( dest_expanded );
Expand Down Expand Up @@ -1013,13 +1021,21 @@ VIOAPI VIO_Status open_file(
tmp_name = get_temporary_filename();

(void) snprintf( command, sizeof(command), "gunzip -c %s > %s", expanded, tmp_name );
#ifdef __wasi__
command_status = VIO_ERROR;
#else
command_status = system( command );
#endif

/* Try again, using bzip2 */
if( command_status != 0 )
{
(void) snprintf( command, sizeof(command), "bunzip2 -c %s > %s", expanded, tmp_name );
#ifdef __wasi__
command_status = VIO_ERROR;
#else
command_status = system( command );
#endif
}

/* Check for failure */
Expand Down

0 comments on commit 31b51f2

Please sign in to comment.