Skip to content
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.

Commit a5caf7b

Browse files
committedAug 1, 2024·
Initial FTS support
Add FTS implementation derived from musl-fts with a few modifications. The compiled fts.o is included in the libc.a archive, and the fts.h header is installed in the sysroot (`include/fts.h`). * fts/musl-fts: Add a copy of the musl-fts sources with modifications. * fts/patches: A set of patches to apply to the musl-fts sources. * fts/update-musl-fts.sh: A script to update the musl-fts sources with the patches applied. * fts/config.h: A configuration header included by the musl-fts sources. * test/smoke: Add a test suite for wasi-libc specific features that libc-test does not cover.
1 parent b9ef79d commit a5caf7b

21 files changed

+1988
-1
lines changed
 

‎Makefile

+12
Original file line numberDiff line numberDiff line change
@@ -376,6 +376,10 @@ LIBC_TOP_HALF_ALL_SOURCES = \
376376
$(LIBC_TOP_HALF_MUSL_SOURCES) \
377377
$(sort $(shell find $(LIBC_TOP_HALF_SOURCES) -name \*.[cs]))
378378

379+
FTS_SRC_DIR = fts
380+
MUSL_FTS_SRC_DIR = $(FTS_SRC_DIR)/musl-fts
381+
FTS_SOURCES = $(MUSL_FTS_SRC_DIR)/fts.c
382+
379383
# Add any extra flags
380384
CFLAGS = $(EXTRA_CFLAGS)
381385
# Set the target.
@@ -449,6 +453,7 @@ DLMALLOC_OBJS = $(call objs,$(DLMALLOC_SOURCES))
449453
EMMALLOC_OBJS = $(call objs,$(EMMALLOC_SOURCES))
450454
LIBC_BOTTOM_HALF_ALL_OBJS = $(call objs,$(LIBC_BOTTOM_HALF_ALL_SOURCES))
451455
LIBC_TOP_HALF_ALL_OBJS = $(call asmobjs,$(call objs,$(LIBC_TOP_HALF_ALL_SOURCES)))
456+
FTS_OBJS = $(call objs,$(FTS_SOURCES))
452457
ifeq ($(WASI_SNAPSHOT), p2)
453458
LIBC_OBJS += $(OBJDIR)/wasip2_component_type.o
454459
endif
@@ -467,6 +472,7 @@ ifeq ($(BUILD_LIBC_TOP_HALF),yes)
467472
# libc-top-half is musl.
468473
LIBC_OBJS += $(LIBC_TOP_HALF_ALL_OBJS)
469474
endif
475+
LIBC_OBJS += $(FTS_OBJS)
470476
MUSL_PRINTSCAN_OBJS = $(call objs,$(MUSL_PRINTSCAN_SOURCES))
471477
MUSL_PRINTSCAN_LONG_DOUBLE_OBJS = $(patsubst %.o,%.long-double.o,$(MUSL_PRINTSCAN_OBJS))
472478
MUSL_PRINTSCAN_NO_FLOATING_POINT_OBJS = $(patsubst %.o,%.no-floating-point.o,$(MUSL_PRINTSCAN_OBJS))
@@ -736,6 +742,10 @@ $(LIBC_TOP_HALF_ALL_OBJS) $(LIBC_TOP_HALF_ALL_SO_OBJS) $(MUSL_PRINTSCAN_LONG_DOU
736742
-Wno-dangling-else \
737743
-Wno-unknown-pragmas
738744

745+
$(FTS_OBJS): CFLAGS += \
746+
-I$(MUSL_FTS_SRC_DIR) \
747+
-I$(FTS_SRC_DIR) # for config.h
748+
739749
$(LIBWASI_EMULATED_PROCESS_CLOCKS_OBJS) $(LIBWASI_EMULATED_PROCESS_CLOCKS_SO_OBJS): CFLAGS += \
740750
-I$(LIBC_BOTTOM_HALF_CLOUDLIBC_SRC)
741751

@@ -764,6 +774,8 @@ include_dirs:
764774
cp -r "$(LIBC_TOP_HALF_MUSL_DIR)"/arch/generic/bits/* "$(SYSROOT_INC)/bits"
765775
cp -r "$(LIBC_TOP_HALF_MUSL_DIR)"/arch/wasm32/bits/* "$(SYSROOT_INC)/bits"
766776

777+
cp "$(MUSL_FTS_SRC_DIR)/fts.h" "$(SYSROOT_INC)/fts.h"
778+
767779
# Remove selected header files.
768780
$(RM) $(patsubst %,$(SYSROOT_INC)/%,$(MUSL_OMIT_HEADERS))
769781
ifeq ($(WASI_SNAPSHOT), p2)

‎expected/wasm32-wasip1-threads/defined-symbols.txt

+5
Original file line numberDiff line numberDiff line change
@@ -714,6 +714,11 @@ ftello64
714714
ftime
715715
ftruncate
716716
ftrylockfile
717+
fts_children
718+
fts_close
719+
fts_open
720+
fts_read
721+
fts_set
717722
funlockfile
718723
futimens
719724
futimesat

‎expected/wasm32-wasip1-threads/include-all.c

+1
Original file line numberDiff line numberDiff line change
@@ -86,6 +86,7 @@
8686
#include <float.h>
8787
#include <fmtmsg.h>
8888
#include <fnmatch.h>
89+
#include <fts.h>
8990
#include <ftw.h>
9091
#include <getopt.h>
9192
#include <glob.h>

‎expected/wasm32-wasip1-threads/predefined-macros.txt

+42
Original file line numberDiff line numberDiff line change
@@ -384,6 +384,40 @@
384384
#define FSETLOCKING_BYCALLER 2
385385
#define FSETLOCKING_INTERNAL 1
386386
#define FSETLOCKING_QUERY 0
387+
#define FTS_AGAIN 1
388+
#define FTS_COMFOLLOW 0x001
389+
#define FTS_D 1
390+
#define FTS_DC 2
391+
#define FTS_DEFAULT 3
392+
#define FTS_DNR 4
393+
#define FTS_DONTCHDIR 0x01
394+
#define FTS_DOT 5
395+
#define FTS_DP 6
396+
#define FTS_ERR 7
397+
#define FTS_F 8
398+
#define FTS_FOLLOW 2
399+
#define FTS_INIT 9
400+
#define FTS_ISW 0x04
401+
#define FTS_LOGICAL 0x002
402+
#define FTS_NAMEONLY 0x100
403+
#define FTS_NOCHDIR 0x004
404+
#define FTS_NOINSTR 3
405+
#define FTS_NOSTAT 0x008
406+
#define FTS_NS 10
407+
#define FTS_NSOK 11
408+
#define FTS_OPTIONMASK 0x0ff
409+
#define FTS_PHYSICAL 0x010
410+
#define FTS_ROOTLEVEL 0
411+
#define FTS_ROOTPARENTLEVEL -1
412+
#define FTS_SEEDOT 0x020
413+
#define FTS_SKIP 4
414+
#define FTS_SL 12
415+
#define FTS_SLNONE 13
416+
#define FTS_STOP 0x200
417+
#define FTS_SYMFOLLOW 0x02
418+
#define FTS_W 14
419+
#define FTS_WHITEOUT 0x080
420+
#define FTS_XDEV 0x040
387421
#define FTW_CHDIR 4
388422
#define FTW_D 2
389423
#define FTW_DEPTH 8
@@ -2075,6 +2109,7 @@
20752109
#define _FLOAT_H
20762110
#define _FMTMSG_H
20772111
#define _FNMATCH_H
2112+
#define _FTS_H_
20782113
#define _FTW_H
20792114
#define _GETOPT_H
20802115
#define _GLOB_H
@@ -3031,6 +3066,13 @@
30313066
#define __alignof_is_defined 1
30323067
#define __bitop(x,i,o) ((x)[(i)/8] o (1<<(i)%8))
30333068
#define __bool_true_false_are_defined 1
3069+
#define __fts_dev_t dev_t
3070+
#define __fts_ino_t ino_t
3071+
#define __fts_length_t unsigned int
3072+
#define __fts_level_t int
3073+
#define __fts_nlink_t nlink_t
3074+
#define __fts_number_t int64_t
3075+
#define __fts_stat_t struct stat
30343076
#define __inline inline
30353077
#define __restrict restrict
30363078
#define __tg_complex(fun,x) (__RETCAST_CX(x)( __FLTCX((x)+I) && __IS_FP(x) ? fun ## f (x) : __LDBLCX((x)+I) ? fun ## l (x) : fun(x) ))

‎expected/wasm32-wasip1/defined-symbols.txt

+5
Original file line numberDiff line numberDiff line change
@@ -648,6 +648,11 @@ ftello
648648
ftello64
649649
ftime
650650
ftruncate
651+
fts_children
652+
fts_close
653+
fts_open
654+
fts_read
655+
fts_set
651656
futimens
652657
futimesat
653658
fwide

‎expected/wasm32-wasip1/include-all.c

+1
Original file line numberDiff line numberDiff line change
@@ -86,6 +86,7 @@
8686
#include <float.h>
8787
#include <fmtmsg.h>
8888
#include <fnmatch.h>
89+
#include <fts.h>
8990
#include <ftw.h>
9091
#include <getopt.h>
9192
#include <glob.h>

‎expected/wasm32-wasip1/predefined-macros.txt

+42
Original file line numberDiff line numberDiff line change
@@ -384,6 +384,40 @@
384384
#define FSETLOCKING_BYCALLER 2
385385
#define FSETLOCKING_INTERNAL 1
386386
#define FSETLOCKING_QUERY 0
387+
#define FTS_AGAIN 1
388+
#define FTS_COMFOLLOW 0x001
389+
#define FTS_D 1
390+
#define FTS_DC 2
391+
#define FTS_DEFAULT 3
392+
#define FTS_DNR 4
393+
#define FTS_DONTCHDIR 0x01
394+
#define FTS_DOT 5
395+
#define FTS_DP 6
396+
#define FTS_ERR 7
397+
#define FTS_F 8
398+
#define FTS_FOLLOW 2
399+
#define FTS_INIT 9
400+
#define FTS_ISW 0x04
401+
#define FTS_LOGICAL 0x002
402+
#define FTS_NAMEONLY 0x100
403+
#define FTS_NOCHDIR 0x004
404+
#define FTS_NOINSTR 3
405+
#define FTS_NOSTAT 0x008
406+
#define FTS_NS 10
407+
#define FTS_NSOK 11
408+
#define FTS_OPTIONMASK 0x0ff
409+
#define FTS_PHYSICAL 0x010
410+
#define FTS_ROOTLEVEL 0
411+
#define FTS_ROOTPARENTLEVEL -1
412+
#define FTS_SEEDOT 0x020
413+
#define FTS_SKIP 4
414+
#define FTS_SL 12
415+
#define FTS_SLNONE 13
416+
#define FTS_STOP 0x200
417+
#define FTS_SYMFOLLOW 0x02
418+
#define FTS_W 14
419+
#define FTS_WHITEOUT 0x080
420+
#define FTS_XDEV 0x040
387421
#define FTW_CHDIR 4
388422
#define FTW_D 2
389423
#define FTW_DEPTH 8
@@ -2070,6 +2104,7 @@
20702104
#define _FLOAT_H
20712105
#define _FMTMSG_H
20722106
#define _FNMATCH_H
2107+
#define _FTS_H_
20732108
#define _FTW_H
20742109
#define _GETOPT_H
20752110
#define _GLOB_H
@@ -3021,6 +3056,13 @@
30213056
#define __alignof_is_defined 1
30223057
#define __bitop(x,i,o) ((x)[(i)/8] o (1<<(i)%8))
30233058
#define __bool_true_false_are_defined 1
3059+
#define __fts_dev_t dev_t
3060+
#define __fts_ino_t ino_t
3061+
#define __fts_length_t unsigned int
3062+
#define __fts_level_t int
3063+
#define __fts_nlink_t nlink_t
3064+
#define __fts_number_t int64_t
3065+
#define __fts_stat_t struct stat
30243066
#define __inline inline
30253067
#define __restrict restrict
30263068
#define __tg_complex(fun,x) (__RETCAST_CX(x)( __FLTCX((x)+I) && __IS_FP(x) ? fun ## f (x) : __LDBLCX((x)+I) ? fun ## l (x) : fun(x) ))

‎expected/wasm32-wasip2/defined-symbols.txt

+5
Original file line numberDiff line numberDiff line change
@@ -735,6 +735,11 @@ ftello
735735
ftello64
736736
ftime
737737
ftruncate
738+
fts_children
739+
fts_close
740+
fts_open
741+
fts_read
742+
fts_set
738743
futimens
739744
futimesat
740745
fwide

‎expected/wasm32-wasip2/include-all.c

+1
Original file line numberDiff line numberDiff line change
@@ -86,6 +86,7 @@
8686
#include <float.h>
8787
#include <fmtmsg.h>
8888
#include <fnmatch.h>
89+
#include <fts.h>
8990
#include <ftw.h>
9091
#include <getopt.h>
9192
#include <glob.h>

‎expected/wasm32-wasip2/predefined-macros.txt

+42
Original file line numberDiff line numberDiff line change
@@ -474,6 +474,40 @@
474474
#define FSETLOCKING_BYCALLER 2
475475
#define FSETLOCKING_INTERNAL 1
476476
#define FSETLOCKING_QUERY 0
477+
#define FTS_AGAIN 1
478+
#define FTS_COMFOLLOW 0x001
479+
#define FTS_D 1
480+
#define FTS_DC 2
481+
#define FTS_DEFAULT 3
482+
#define FTS_DNR 4
483+
#define FTS_DONTCHDIR 0x01
484+
#define FTS_DOT 5
485+
#define FTS_DP 6
486+
#define FTS_ERR 7
487+
#define FTS_F 8
488+
#define FTS_FOLLOW 2
489+
#define FTS_INIT 9
490+
#define FTS_ISW 0x04
491+
#define FTS_LOGICAL 0x002
492+
#define FTS_NAMEONLY 0x100
493+
#define FTS_NOCHDIR 0x004
494+
#define FTS_NOINSTR 3
495+
#define FTS_NOSTAT 0x008
496+
#define FTS_NS 10
497+
#define FTS_NSOK 11
498+
#define FTS_OPTIONMASK 0x0ff
499+
#define FTS_PHYSICAL 0x010
500+
#define FTS_ROOTLEVEL 0
501+
#define FTS_ROOTPARENTLEVEL -1
502+
#define FTS_SEEDOT 0x020
503+
#define FTS_SKIP 4
504+
#define FTS_SL 12
505+
#define FTS_SLNONE 13
506+
#define FTS_STOP 0x200
507+
#define FTS_SYMFOLLOW 0x02
508+
#define FTS_W 14
509+
#define FTS_WHITEOUT 0x080
510+
#define FTS_XDEV 0x040
477511
#define FTW_CHDIR 4
478512
#define FTW_D 2
479513
#define FTW_DEPTH 8
@@ -2220,6 +2254,7 @@
22202254
#define _FLOAT_H
22212255
#define _FMTMSG_H
22222256
#define _FNMATCH_H
2257+
#define _FTS_H_
22232258
#define _FTW_H
22242259
#define _GETOPT_H
22252260
#define _GLOB_H
@@ -3173,6 +3208,13 @@
31733208
#define __alignof_is_defined 1
31743209
#define __bitop(x,i,o) ((x)[(i)/8] o (1<<(i)%8))
31753210
#define __bool_true_false_are_defined 1
3211+
#define __fts_dev_t dev_t
3212+
#define __fts_ino_t ino_t
3213+
#define __fts_length_t unsigned int
3214+
#define __fts_level_t int
3215+
#define __fts_nlink_t nlink_t
3216+
#define __fts_number_t int64_t
3217+
#define __fts_stat_t struct stat
31763218
#define __inline inline
31773219
#define __restrict restrict
31783220
#define __tg_complex(fun,x) (__RETCAST_CX(x)( __FLTCX((x)+I) && __IS_FP(x) ? fun ## f (x) : __LDBLCX((x)+I) ? fun ## l (x) : fun(x) ))

‎fts/config.h

+7
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
#define HAVE_DECL_MAX 1
2+
3+
#define HAVE_DECL_UINTMAX_MAX 0
4+
5+
#define HAVE_DIRFD 1
6+
7+
#define HAVE_FCHDIR 0

‎fts/musl-fts/COPYING

+26
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
Copyright (c) 1989, 1993
2+
The Regents of the University of California. All rights reserved.
3+
4+
Redistribution and use in source and binary forms, with or without
5+
modification, are permitted provided that the following conditions
6+
are met:
7+
1. Redistributions of source code must retain the above copyright
8+
notice, this list of conditions and the following disclaimer.
9+
2. Redistributions in binary form must reproduce the above copyright
10+
notice, this list of conditions and the following disclaimer in the
11+
documentation and/or other materials provided with the distribution.
12+
3. Neither the name of the University nor the names of its contributors
13+
may be used to endorse or promote products derived from this software
14+
without specific prior written permission.
15+
16+
THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
17+
ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
18+
IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
19+
ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
20+
FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
21+
DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
22+
OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
23+
HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
24+
LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
25+
OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
26+
SUCH DAMAGE.

‎fts/musl-fts/NOTICE.wasi-libc.md

+9
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
This directory contains a copy of the musl-fts library licensed under
2+
BSD-3-Clause with wasi-libc modifications. See COPYING for the full license text.
3+
4+
The original source code can be found at https://github.com/void-linux/musl-fts/archive/refs/tags/v1.2.7.tar.gz
5+
6+
## How to update musl-fts sources
7+
8+
1. Update the `MUSL_FTS_VERSION` variable in `./fts/update-musl-fts.sh`
9+
2. Run `./fts/update-musl-fts.sh`

0 commit comments

Comments
 (0)
Please sign in to comment.