42 Commits

Author SHA1 Message Date
Jake Petroules
90953dfb68
Transparently add the \\?\ prefix to Win32 calls for extended length path handling (#1257)
On Windows, there is a built-in maximum path limitation of 260 characters under most conditions. This can be extended to 32767 characters under either of the following two conditions:

- Adding the longPathAware attribute to the executable's manifest AND enabling the LongPathsEnabled system-wide registry key or group policy.
- Ensuring fully qualified paths passed to Win32 APIs are prefixed with \?\

Unfortunately, the former is not realistic for the Swift ecosystem, since it requires developers to have awareness of this specific Windows limitation, AND set longPathAware in their apps' manifest AND expect end users of those apps to change their system configuration.

Instead, this patch transparently prefixes all eligible paths in calls to Win32 APIs with the \?\ prefix to allow them to work with paths longer than 260 characters without requiring the caller of Foundation to manually prefix the paths.

See https://learn.microsoft.com/en-us/windows/win32/fileio/maximum-file-path-limitation for more info.
2025-04-23 14:51:43 -07:00
3405691582
03fe46f43b
OpenBSD support. (#1126)
* Advise porter on where to make necessary change.

In #1075 the change was already made for BSD (thank you!); my working
edit had this guidance to ensure future porters get an error directing
them where to make a necessary change.

Otherwise, the FoundationEssentials build will fail and complain these
variables are not defined but not have guidance as to where they are
sourced from.

* OpenBSD does not support extended attributes.

* OpenBSD does not have secure_getenv.

* Remaining OpenBSD changes.

* OpenBSD also needs `pthread_mutex_t?`.

* Originally I followed Darwin's check with `d_namlen`, but this should
  work too.

* Correct statvfs type casts for OpenBSD.

On OpenBSD, fsblkcnt_t -- the type of f_blocks -- is a UInt64; therefore,
so must `blockSize` be.

Ultimately, both sides of the `totalSizeBytes` multiplication should
probably be type cast for all platforms, but that's a more significant
functional change for another time.

* Default activeProcessorCount to 1, not 0.

After a rather tedious debugging session trying to figure out why
swiftpm-bootstrap appeared to be deadlocked, this turned out to be the
culprit. Perhaps this should be #error instead, but for now, set a
sensible default.

* Use sysconf for activeProcessorCount.

This is what Dispatch does in some places for OpenBSD anyway, so do
likewise here.
2025-04-07 10:46:18 -07:00
michael-yuji
7abeeef0f2
fix a typo preventing freebsd to build (#1231) 2025-03-28 09:54:42 -07:00
michael-yuji
2f65d91455
Fix _copyDirectoryMetadata compilation error on FreeBSD (#1121)
* Fix FreeBSD build

* address comments
2025-03-17 14:00:41 -07:00
Johannes Weiss
601e847faa
always @preconcurrency import Glibc (#1175)
Co-authored-by: Johannes Weiss <johannes@jweiss.io>
2025-03-04 09:25:51 -08:00
michael-yuji
5ed6c72484
[FreeBSD] Fix FreeBSD build/support (#1075)
* FreeBSD platform specific fixes

- Use "/usr/share/zoneinfo"
- Use platform specific types and values
- Implement extattr ops for FreeBSD
- Use copy_file_range(2) for file cloning

* Revise patch to ProcessInfo to reduce potential impact to other platforms

* Fix macOS build

* typo

* take suggested change
2025-01-10 14:20:27 -08:00
finagolfin
90700c100f
Don't try to set extended attributes on Android (#1106)
Normal users don't have permission to change these, even for their own files.
2025-01-02 10:57:08 -05:00
Yuta Saito
c0532f8c99
Follow-up fixes to make it work with wasi-libc (#1095)
* Gate `fchown` and `fchmod` calls behind `os(WASI)`

They are not available on WASI, so we gate them behind `os(WASI)`.

* Add missing constant shims for wasi-libc

* Use `futimens` instead of legacy `futimes`

wasi-libc does not provide `futimes` as it is a legacy function.
574b88da48/libc-top-half/musl/include/sys/time.h (L34)
2024-12-16 11:19:39 -08:00
Yuta Saito
0b4f13f9f4
Fix WASI build of _copyDirectoryMetadata (#1094)
Extended attributes don't exist in WASI, so we need to exclude the use
of xattr-related APIs including `flistxattr`.
2024-12-13 09:29:45 -08:00
Alex Lorenz
4339393f2c
[android] fix 32-bit build (#1086)
Regression after bb3fccfa360d00f63999ac8faf6ba37224ce5174
2024-12-12 07:34:34 -08:00
Jeremy Schonfeld
bb3fccfa36
Ensure that FileManager.copyItem cannot copy directory metadata to files (#1081)
* (135575520) Ensure that FileManager.copyItem cannot copy directory metadata to files

* Fix whitespacing

* Fix Windows test failure
2024-12-11 15:05:08 -08:00
Jeremy Schonfeld
86d660bfb8
(140535903) Avoid attaching removefile callbacks when delegate does not implement functions (#1070) 2024-12-04 17:24:15 -08:00
Yuta Saito
4784ffb3e4
[wasm] Fix CocoaError construction for unsupported copy/link operations (#944)
This is a follow-up fix for 6c0a3e8453cdde633e1c55f6112fd53a0d756979,
which re-organized CocoaError helper functions.
2024-09-26 08:23:37 +09:00
Jeremy Schonfeld
6c0a3e8453
Performance optimizations for data reading/writing (#942)
* (135743158) Performance optimizations for data reading/writing

* Fix Windows build
2024-09-24 13:16:44 -07:00
Jeremy Schonfeld
e555c629ba
Fix Windows symlink handling in FileManager APIs (#858)
* Fix Windows symlink handling in FileManager APIs

* Address feedback
2024-08-16 10:41:44 -07:00
finagolfin
c15a5e1f5c
[Android] Use the Bionic module in more places (#842)
Also, use `canImport()` wherever importing APIs, reserving `os(Android)` for
platform differences.
2024-08-15 14:34:15 -07:00
Evan Wilde
aecc1b158c
[main] Get Swift-Foundation building against MUSL for Swift Static SDK (#848)
* Get FoundationEssentials building

Adding the missing musl imports to get FoundationEssentials building for
the Swift static SDKs again.

Also providing an option to disable building the macros. The macros
aren't necessary for building the library and will not be run as part of
the static SDK. No need to bloat the SDK or build times further. For
Swift 6, the macros should be provided by the toolchain since the
toolchain and SDK are current revlocked due to swiftmodules.

* Get FoundationInternationalization building

Adding the missing Musl imports to get FoundationInternationalization
building for the static SDK.
2024-08-14 13:34:15 -07:00
Alex Lorenz
ad6ca71b4e
[android] fix the LP32 armv7/i686 android build (#846)
* [android] fix the LP32 armv7/i686 android build

* Update Sources/FoundationEssentials/Android+Extensions.swift

Co-authored-by: Jeremy Schonfeld <1004103+jmschonfeld@users.noreply.github.com>

* drop the android Lp32 specific operator &

---------

Co-authored-by: Jeremy Schonfeld <1004103+jmschonfeld@users.noreply.github.com>
2024-08-14 10:56:25 -07:00
Yuta Saito
bc47ca221d
Port directory enumeration related code to WASI (#836)
* Port directory enumeration related code to WASI

For now wasi-libc does not include fts(3) implementation, so mark
features depending on it as unsupported on WASI. Once wasi-libc includes
fts or we decide to implement and maintain our own fts-like API, we can
remove these `#if os(WASI)` guards.

wasi-libc issue tracking fts support:
https://github.com/WebAssembly/wasi-libc/issues/520

Also, wasi-libc defines some constants in a way that ClangImporter can't
understand, so we need to grab them manually through _FoundationCShims in
function call form.

* Delegate error throwing decisions to the delegate
2024-08-12 19:52:15 -07:00
Yuta Saito
41cbea8b57
[wasm] Fall back to a default chunk size when st_blksize is not available (#835)
The `st_blksize` field in `stat` struct is not provided by WASI, so we
fall back to a default chunk size 4KB, which is a common page size.
2024-08-08 16:22:40 -07:00
Yuta Saito
c82d1673eb
Add WASI platform conditions for libc imports and word size (#776)
* Add `import WASILibc` statements to libc import chains

* Declare wasm32 arch as 32-bit environment

* Switch to _pointerBitWidth for architecture checks

This change switches the architecture checks in Data.swift to use the
_pointerBitWidth instead of the arch() checks for consistency with newer
platforms.
2024-08-02 09:55:56 -07:00
Yuta Saito
2a6afeb50a
Implement _copyRegularFile for WASI without sendfile (#787)
WASI doesn't have `sendfile`, so we need to implement the copy in user
space with `read` and `write`. It's not as efficient as `sendfile`, but
it's the best we can do.
2024-08-01 10:50:04 -07:00
Yuta Saito
0b3974d351
Guard out user/group related code on WASI (#783)
* Guard out user/group related code on WASI

This change guards out the user/group related code on WASI, as WASI does
not have the concept of users or groups.

* Throw explicit unsupported error if trying to set user or group on WASI

Instead of implicitly ignoring user-given values, we should throw
exception to make it clear that those values cannot be set on WASI.
2024-08-01 09:23:13 -07:00
Saleem Abdulrasool
88d6a8d619
FoundationEssentials: make build on Android (#705)
This adjusts the API usage to account for differences on Android. The
biggest source of difference is the nullability, particularly in the
`fts` APIs. Unfortunately, `MMAP_FAILED` is not imported by the clang
importer due to the casting involved so we manually inline the constant
at the single site.
2024-07-01 16:44:47 -07:00
Saleem Abdulrasool
a7692238a8
FoundationEssentials: initial pass to add Android support (#704)
This adds the necessary guards and includes for the Android modules.
While the module does not compile currently due to nullability
differences (and in some cases missing declarations), this at least
brings the module to a point where we can start working on the errors
and differences to create a maintainable codebase for Android.
2024-06-26 16:00:37 -07:00
Charles Hu
60506f3af4
Renamed _CShims to _FoundationCShims (#656)
Rationale: _CShims will effectivly become semi-public in the toolchain. We add the Foundation prefix to make it less generic.
2024-06-21 16:18:38 -07:00
Saleem Abdulrasool
e473ab75be
FoundationEssentials: fix up linkOrCopyFile on Windows (#675)
Adjust the Windows path for copying (or linking) files. This adds the
missing recursion in the copy (the documentation for `CopyFile2` was not
clear that the recursive copy is not performed).
2024-06-12 09:26:03 -07:00
Saleem Abdulrasool
21ed596f06
FoundationEssentials: adjust error code thrown (#671)
Rather than relaying the underlying system error, replace the error with
the expected error code. This repairs the test case expectation of the
thrown error.
2024-06-12 08:37:16 -07:00
Saleem Abdulrasool
9371cbf702
FoundationEssentials: correct callbacks for moveItem(atPath:toPath:) (#661)
In the case that the destination exists, we should check for continue
after error. If the source does not exist, simply do nothing.

Furthermore, adjust the test to ensure that we are using the path
spelling rather than the FSR.

Take the opportunity to correct an error in the tests where we would not
check the correct captured item set.
2024-06-06 13:54:46 -07:00
Saleem Abdulrasool
38d2d4e7a8
FoundationEssentials: silence a warning (#662)
Convert a `var` to `let` as it was originally. This variable is no
longer mutated and causes a warning.
2024-06-06 09:52:59 -07:00
Saleem Abdulrasool
413b15cbd8
FoundationEssentials: tweak removeFile(_:with:) on Windows (#659)
Ensure that we call the callbacks at the appropriate time. Change the
indentation and encapsulating scope to avoid a double callback.
2024-06-05 13:31:20 -07:00
Jeremy Schonfeld
418fe5bf96
Eliminate removefile shims fixing release mode build (#655)
* (128703942) Eliminate removefile shims

* state -> _
2024-06-04 20:03:35 -07:00
Saleem Abdulrasool
2e26c64cc4
FoundationEssentials: correct the entry spelling for iteration (#653)
When running the test suite we would hit an infinite loop due to the use
of the relative path rather than the absolute path for accessing the
attributes of the file entry.
2024-06-04 09:57:02 -07:00
Saleem Abdulrasool
d1ace948b5
(128078378) FoundationEssentials: correct error handling for item removal (#610)
The condition of the error check was inverted as it was meant to be a
`guard` statement. This was resulting in an infinite loop. With this we
now pass a few additional tests and the test suite no longer hangs.
2024-05-14 13:40:54 -07:00
Jeremy Schonfeld
727bd07830
Utilize URL in FileManager (#589)
* Use URL in FileManager

* Fix warnings

* Fix build failures on Linux

* Remove Locale_ICU warning fix
2024-05-07 15:55:08 -07:00
Saleem Abdulrasool
6ff08b28b8
FoundationEssentials: repair the Windows build after tweaks (#570)
The changes to repair the macOS/Linux build adversely impacted the
Windows build. Accommodate the API and logic changes for Windows.
2024-04-30 08:00:13 -07:00
Saleem Abdulrasool
aabac27b21
FoundationEssentials: implement file operations (#566)
This adds an initial implementation for file operations on Windows. With
this, `FileManager` should at least build on Windows, which unblocks
future work as well as brings us closer to enabling
`FoundationEssentials` on Windows.
2024-04-29 15:34:46 -07:00
Saleem Abdulrasool
9491cce69c
FoundationEssentials: add some missing imports for Windows (#520)
This allows us to get further into building FoundationEssentials once
again on Windows. Much of the file system work has resulted in this
module no longer being viable on Windows and will need to be replaced to
allow building on Windows which does not have the `fts` APIs.
2024-03-29 14:19:23 -07:00
Jeremy Schonfeld
e5211f2926
(122981400) Standardize on using internal import 2024-03-06 13:42:02 -08:00
Jeremy Schonfeld
beeea05206
(123438249) FileManager.removeItem does not throw error when encountering long paths
* (123438249) FileManager.removeItem does not throw error when encoutering long paths

The change makes swift-foundation FileManager.removeItem properly throw
on removefile(3) errors.

* Conform POSIXError to Error

* Clean up warnings and produce more detailed test failures

* Fix macOS CI failure
2024-02-28 13:33:55 -08:00
Jeremy Schonfeld
12d6069721
(123104044) Consolidate/standardize file-based error reporting
* Consolidate/standardize file-based error reporting

* Fix build failures

* Fix test failures
2024-02-16 16:50:16 -08:00
Jeremy Schonfeld
33856a556d
(120741818) Port FileManager to swift-foundation
* (120741818) Port FileManager to swift-foundation

* (120741818) Fix linux test failures

* (120741818) Fix build failures
2024-02-09 15:03:43 -08:00