From 31b51f299ac12f9e4d56a18e6020127f359cb426 Mon Sep 17 00:00:00 2001 From: Matt McCormick Date: Sat, 3 Aug 2024 08:42:52 -0400 Subject: [PATCH] COMP: libminc WASI undefined symbols 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 --- .../MINC/src/libminc/libsrc/minc_convenience.c | 9 ++++++++- .../ThirdParty/MINC/src/libminc/libsrc2/volume.c | 11 +++++++++-- .../src/libminc/volume_io/Prog_utils/files.c | 16 ++++++++++++++++ 3 files changed, 33 insertions(+), 3 deletions(-) diff --git a/Modules/ThirdParty/MINC/src/libminc/libsrc/minc_convenience.c b/Modules/ThirdParty/MINC/src/libminc/libsrc/minc_convenience.c index 5e41caef2a6..f342dd4f697 100644 --- a/Modules/ThirdParty/MINC/src/libminc/libsrc/minc_convenience.c +++ b/Modules/ThirdParty/MINC/src/libminc/libsrc/minc_convenience.c @@ -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"); @@ -1508,6 +1509,12 @@ 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, @@ -1515,7 +1522,7 @@ MNCAPI int micreate_ident( char * id_str, size_t length ) MI_IDENT_SEP, time_str, MI_IDENT_SEP, - getpid(), + pid, MI_IDENT_SEP, identx++); return (result); diff --git a/Modules/ThirdParty/MINC/src/libminc/libsrc2/volume.c b/Modules/ThirdParty/MINC/src/libminc/libsrc2/volume.c index 6a74cedd96e..93e7bd8e191 100644 --- a/Modules/ThirdParty/MINC/src/libminc/libsrc2/volume.c +++ b/Modules/ThirdParty/MINC/src/libminc/libsrc2/volume.c @@ -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) { @@ -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; } diff --git a/Modules/ThirdParty/MINC/src/libminc/volume_io/Prog_utils/files.c b/Modules/ThirdParty/MINC/src/libminc/volume_io/Prog_utils/files.c index 7c86aa31417..5491e6bd6a6 100644 --- a/Modules/ThirdParty/MINC/src/libminc/volume_io/Prog_utils/files.c +++ b/Modules/ThirdParty/MINC/src/libminc/volume_io/Prog_utils/files.c @@ -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: ", @@ -498,6 +501,7 @@ VIOAPI VIO_Status copy_file( } else status = VIO_OK; +#endif delete_string( src_expanded ); delete_string( dest_expanded ); @@ -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: ", @@ -543,6 +550,7 @@ VIOAPI VIO_Status move_file( } else status = VIO_OK; +#endif delete_string( src_expanded ); delete_string( dest_expanded ); @@ -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 */