Skip to content

Commit

Permalink
Initial FTS support
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
kateinoigakukun committed Aug 1, 2024
1 parent b9ef79d commit f6bb78d
Show file tree
Hide file tree
Showing 22 changed files with 1,989 additions and 1 deletion.
1 change: 1 addition & 0 deletions LICENSE
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ dlmalloc/ - CC0; see the notice in malloc.c for details
emmalloc/ - MIT; see the notice in emmalloc.c for details
libc-bottom-half/cloudlibc/ - BSD-2-Clause; see the LICENSE file for details
libc-top-half/musl/ - MIT; see the COPYRIGHT file for details
fts/musl-fts/ - BSD-3-Clause; see the COPYING file for details

wasi-libc's changes to these files are multi-licensed under the
Apache License v2.0 with LLVM Exceptions, the Apache License v2.0,
Expand Down
12 changes: 12 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -376,6 +376,10 @@ LIBC_TOP_HALF_ALL_SOURCES = \
$(LIBC_TOP_HALF_MUSL_SOURCES) \
$(sort $(shell find $(LIBC_TOP_HALF_SOURCES) -name \*.[cs]))

FTS_SRC_DIR = fts
MUSL_FTS_SRC_DIR = $(FTS_SRC_DIR)/musl-fts
FTS_SOURCES = $(MUSL_FTS_SRC_DIR)/fts.c

# Add any extra flags
CFLAGS = $(EXTRA_CFLAGS)
# Set the target.
Expand Down Expand Up @@ -449,6 +453,7 @@ DLMALLOC_OBJS = $(call objs,$(DLMALLOC_SOURCES))
EMMALLOC_OBJS = $(call objs,$(EMMALLOC_SOURCES))
LIBC_BOTTOM_HALF_ALL_OBJS = $(call objs,$(LIBC_BOTTOM_HALF_ALL_SOURCES))
LIBC_TOP_HALF_ALL_OBJS = $(call asmobjs,$(call objs,$(LIBC_TOP_HALF_ALL_SOURCES)))
FTS_OBJS = $(call objs,$(FTS_SOURCES))
ifeq ($(WASI_SNAPSHOT), p2)
LIBC_OBJS += $(OBJDIR)/wasip2_component_type.o
endif
Expand All @@ -467,6 +472,7 @@ ifeq ($(BUILD_LIBC_TOP_HALF),yes)
# libc-top-half is musl.
LIBC_OBJS += $(LIBC_TOP_HALF_ALL_OBJS)
endif
LIBC_OBJS += $(FTS_OBJS)
MUSL_PRINTSCAN_OBJS = $(call objs,$(MUSL_PRINTSCAN_SOURCES))
MUSL_PRINTSCAN_LONG_DOUBLE_OBJS = $(patsubst %.o,%.long-double.o,$(MUSL_PRINTSCAN_OBJS))
MUSL_PRINTSCAN_NO_FLOATING_POINT_OBJS = $(patsubst %.o,%.no-floating-point.o,$(MUSL_PRINTSCAN_OBJS))
Expand Down Expand Up @@ -736,6 +742,10 @@ $(LIBC_TOP_HALF_ALL_OBJS) $(LIBC_TOP_HALF_ALL_SO_OBJS) $(MUSL_PRINTSCAN_LONG_DOU
-Wno-dangling-else \
-Wno-unknown-pragmas

$(FTS_OBJS): CFLAGS += \
-I$(MUSL_FTS_SRC_DIR) \
-I$(FTS_SRC_DIR) # for config.h

$(LIBWASI_EMULATED_PROCESS_CLOCKS_OBJS) $(LIBWASI_EMULATED_PROCESS_CLOCKS_SO_OBJS): CFLAGS += \
-I$(LIBC_BOTTOM_HALF_CLOUDLIBC_SRC)

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

cp "$(MUSL_FTS_SRC_DIR)/fts.h" "$(SYSROOT_INC)/fts.h"

# Remove selected header files.
$(RM) $(patsubst %,$(SYSROOT_INC)/%,$(MUSL_OMIT_HEADERS))
ifeq ($(WASI_SNAPSHOT), p2)
Expand Down
5 changes: 5 additions & 0 deletions expected/wasm32-wasip1-threads/defined-symbols.txt
Original file line number Diff line number Diff line change
Expand Up @@ -714,6 +714,11 @@ ftello64
ftime
ftruncate
ftrylockfile
fts_children
fts_close
fts_open
fts_read
fts_set
funlockfile
futimens
futimesat
Expand Down
1 change: 1 addition & 0 deletions expected/wasm32-wasip1-threads/include-all.c
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,7 @@
#include <float.h>
#include <fmtmsg.h>
#include <fnmatch.h>
#include <fts.h>
#include <ftw.h>
#include <getopt.h>
#include <glob.h>
Expand Down
42 changes: 42 additions & 0 deletions expected/wasm32-wasip1-threads/predefined-macros.txt
Original file line number Diff line number Diff line change
Expand Up @@ -384,6 +384,40 @@
#define FSETLOCKING_BYCALLER 2
#define FSETLOCKING_INTERNAL 1
#define FSETLOCKING_QUERY 0
#define FTS_AGAIN 1
#define FTS_COMFOLLOW 0x001
#define FTS_D 1
#define FTS_DC 2
#define FTS_DEFAULT 3
#define FTS_DNR 4
#define FTS_DONTCHDIR 0x01
#define FTS_DOT 5
#define FTS_DP 6
#define FTS_ERR 7
#define FTS_F 8
#define FTS_FOLLOW 2
#define FTS_INIT 9
#define FTS_ISW 0x04
#define FTS_LOGICAL 0x002
#define FTS_NAMEONLY 0x100
#define FTS_NOCHDIR 0x004
#define FTS_NOINSTR 3
#define FTS_NOSTAT 0x008
#define FTS_NS 10
#define FTS_NSOK 11
#define FTS_OPTIONMASK 0x0ff
#define FTS_PHYSICAL 0x010
#define FTS_ROOTLEVEL 0
#define FTS_ROOTPARENTLEVEL -1
#define FTS_SEEDOT 0x020
#define FTS_SKIP 4
#define FTS_SL 12
#define FTS_SLNONE 13
#define FTS_STOP 0x200
#define FTS_SYMFOLLOW 0x02
#define FTS_W 14
#define FTS_WHITEOUT 0x080
#define FTS_XDEV 0x040
#define FTW_CHDIR 4
#define FTW_D 2
#define FTW_DEPTH 8
Expand Down Expand Up @@ -2075,6 +2109,7 @@
#define _FLOAT_H
#define _FMTMSG_H
#define _FNMATCH_H
#define _FTS_H_
#define _FTW_H
#define _GETOPT_H
#define _GLOB_H
Expand Down Expand Up @@ -3031,6 +3066,13 @@
#define __alignof_is_defined 1
#define __bitop(x,i,o) ((x)[(i)/8] o (1<<(i)%8))
#define __bool_true_false_are_defined 1
#define __fts_dev_t dev_t
#define __fts_ino_t ino_t
#define __fts_length_t unsigned int
#define __fts_level_t int
#define __fts_nlink_t nlink_t
#define __fts_number_t int64_t
#define __fts_stat_t struct stat
#define __inline inline
#define __restrict restrict
#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) ))
Expand Down
5 changes: 5 additions & 0 deletions expected/wasm32-wasip1/defined-symbols.txt
Original file line number Diff line number Diff line change
Expand Up @@ -648,6 +648,11 @@ ftello
ftello64
ftime
ftruncate
fts_children
fts_close
fts_open
fts_read
fts_set
futimens
futimesat
fwide
Expand Down
1 change: 1 addition & 0 deletions expected/wasm32-wasip1/include-all.c
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,7 @@
#include <float.h>
#include <fmtmsg.h>
#include <fnmatch.h>
#include <fts.h>
#include <ftw.h>
#include <getopt.h>
#include <glob.h>
Expand Down
42 changes: 42 additions & 0 deletions expected/wasm32-wasip1/predefined-macros.txt
Original file line number Diff line number Diff line change
Expand Up @@ -384,6 +384,40 @@
#define FSETLOCKING_BYCALLER 2
#define FSETLOCKING_INTERNAL 1
#define FSETLOCKING_QUERY 0
#define FTS_AGAIN 1
#define FTS_COMFOLLOW 0x001
#define FTS_D 1
#define FTS_DC 2
#define FTS_DEFAULT 3
#define FTS_DNR 4
#define FTS_DONTCHDIR 0x01
#define FTS_DOT 5
#define FTS_DP 6
#define FTS_ERR 7
#define FTS_F 8
#define FTS_FOLLOW 2
#define FTS_INIT 9
#define FTS_ISW 0x04
#define FTS_LOGICAL 0x002
#define FTS_NAMEONLY 0x100
#define FTS_NOCHDIR 0x004
#define FTS_NOINSTR 3
#define FTS_NOSTAT 0x008
#define FTS_NS 10
#define FTS_NSOK 11
#define FTS_OPTIONMASK 0x0ff
#define FTS_PHYSICAL 0x010
#define FTS_ROOTLEVEL 0
#define FTS_ROOTPARENTLEVEL -1
#define FTS_SEEDOT 0x020
#define FTS_SKIP 4
#define FTS_SL 12
#define FTS_SLNONE 13
#define FTS_STOP 0x200
#define FTS_SYMFOLLOW 0x02
#define FTS_W 14
#define FTS_WHITEOUT 0x080
#define FTS_XDEV 0x040
#define FTW_CHDIR 4
#define FTW_D 2
#define FTW_DEPTH 8
Expand Down Expand Up @@ -2070,6 +2104,7 @@
#define _FLOAT_H
#define _FMTMSG_H
#define _FNMATCH_H
#define _FTS_H_
#define _FTW_H
#define _GETOPT_H
#define _GLOB_H
Expand Down Expand Up @@ -3021,6 +3056,13 @@
#define __alignof_is_defined 1
#define __bitop(x,i,o) ((x)[(i)/8] o (1<<(i)%8))
#define __bool_true_false_are_defined 1
#define __fts_dev_t dev_t
#define __fts_ino_t ino_t
#define __fts_length_t unsigned int
#define __fts_level_t int
#define __fts_nlink_t nlink_t
#define __fts_number_t int64_t
#define __fts_stat_t struct stat
#define __inline inline
#define __restrict restrict
#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) ))
Expand Down
5 changes: 5 additions & 0 deletions expected/wasm32-wasip2/defined-symbols.txt
Original file line number Diff line number Diff line change
Expand Up @@ -735,6 +735,11 @@ ftello
ftello64
ftime
ftruncate
fts_children
fts_close
fts_open
fts_read
fts_set
futimens
futimesat
fwide
Expand Down
1 change: 1 addition & 0 deletions expected/wasm32-wasip2/include-all.c
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,7 @@
#include <float.h>
#include <fmtmsg.h>
#include <fnmatch.h>
#include <fts.h>
#include <ftw.h>
#include <getopt.h>
#include <glob.h>
Expand Down
42 changes: 42 additions & 0 deletions expected/wasm32-wasip2/predefined-macros.txt
Original file line number Diff line number Diff line change
Expand Up @@ -474,6 +474,40 @@
#define FSETLOCKING_BYCALLER 2
#define FSETLOCKING_INTERNAL 1
#define FSETLOCKING_QUERY 0
#define FTS_AGAIN 1
#define FTS_COMFOLLOW 0x001
#define FTS_D 1
#define FTS_DC 2
#define FTS_DEFAULT 3
#define FTS_DNR 4
#define FTS_DONTCHDIR 0x01
#define FTS_DOT 5
#define FTS_DP 6
#define FTS_ERR 7
#define FTS_F 8
#define FTS_FOLLOW 2
#define FTS_INIT 9
#define FTS_ISW 0x04
#define FTS_LOGICAL 0x002
#define FTS_NAMEONLY 0x100
#define FTS_NOCHDIR 0x004
#define FTS_NOINSTR 3
#define FTS_NOSTAT 0x008
#define FTS_NS 10
#define FTS_NSOK 11
#define FTS_OPTIONMASK 0x0ff
#define FTS_PHYSICAL 0x010
#define FTS_ROOTLEVEL 0
#define FTS_ROOTPARENTLEVEL -1
#define FTS_SEEDOT 0x020
#define FTS_SKIP 4
#define FTS_SL 12
#define FTS_SLNONE 13
#define FTS_STOP 0x200
#define FTS_SYMFOLLOW 0x02
#define FTS_W 14
#define FTS_WHITEOUT 0x080
#define FTS_XDEV 0x040
#define FTW_CHDIR 4
#define FTW_D 2
#define FTW_DEPTH 8
Expand Down Expand Up @@ -2220,6 +2254,7 @@
#define _FLOAT_H
#define _FMTMSG_H
#define _FNMATCH_H
#define _FTS_H_
#define _FTW_H
#define _GETOPT_H
#define _GLOB_H
Expand Down Expand Up @@ -3173,6 +3208,13 @@
#define __alignof_is_defined 1
#define __bitop(x,i,o) ((x)[(i)/8] o (1<<(i)%8))
#define __bool_true_false_are_defined 1
#define __fts_dev_t dev_t
#define __fts_ino_t ino_t
#define __fts_length_t unsigned int
#define __fts_level_t int
#define __fts_nlink_t nlink_t
#define __fts_number_t int64_t
#define __fts_stat_t struct stat
#define __inline inline
#define __restrict restrict
#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) ))
Expand Down
7 changes: 7 additions & 0 deletions fts/config.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
#define HAVE_DECL_MAX 1

#define HAVE_DECL_UINTMAX_MAX 0

#define HAVE_DIRFD 1

#define HAVE_FCHDIR 0
26 changes: 26 additions & 0 deletions fts/musl-fts/COPYING
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
Copyright (c) 1989, 1993
The Regents of the University of California. All rights reserved.

Redistribution and use in source and binary forms, with or without
modification, are permitted provided that the following conditions
are met:
1. Redistributions of source code must retain the above copyright
notice, this list of conditions and the following disclaimer.
2. Redistributions in binary form must reproduce the above copyright
notice, this list of conditions and the following disclaimer in the
documentation and/or other materials provided with the distribution.
3. Neither the name of the University nor the names of its contributors
may be used to endorse or promote products derived from this software
without specific prior written permission.

THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
SUCH DAMAGE.
9 changes: 9 additions & 0 deletions fts/musl-fts/NOTICE.wasi-libc.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
This directory contains a copy of the musl-fts library licensed under
BSD-3-Clause with wasi-libc modifications. See COPYING for the full license text.

The original source code can be found at https://github.com/void-linux/musl-fts/archive/refs/tags/v1.2.7.tar.gz

## How to update musl-fts sources

1. Update the `MUSL_FTS_VERSION` variable in `./fts/update-musl-fts.sh`
2. Run `./fts/update-musl-fts.sh`
Loading

0 comments on commit f6bb78d

Please sign in to comment.