Closed hyp closed 2 weeks ago
@swift-ci please test
build failures without the fix:
:/r/_work/swift-build/swift-build/SourceCache/swift-foundation/Sources/FoundationEssentials/Platform.swift:168:35: error: cannot find 'group' in scope
166 |
167 | static func gid(forName name: String) -> uid_t? {
168 | withUserGroupBuffer(name, group(), sizeProperty: Int32(_SC_GETGR_R_SIZE_MAX), operation: getgrnam_r) {
| `- error: cannot find 'group' in scope
169 | $0.gr_gid
170 | }
D:/r/_work/swift-build/swift-build/SourceCache/swift-foundation/Sources/FoundationEssentials/Platform.swift:168:98: error: cannot find 'getgrnam_r' in scope
166 |
167 | static func gid(forName name: String) -> uid_t? {
168 | withUserGroupBuffer(name, group(), sizeProperty: Int32(_SC_GETGR_R_SIZE_MAX), operation: getgrnam_r) {
| `- error: cannot find 'getgrnam_r' in scope
169 | $0.gr_gid
170 | }
D:/r/_work/swift-build/swift-build/SourceCache/swift-foundation/Sources/FoundationEssentials/Platform.swift:168:98: error: converting non-escaping value to '(String, UnsafeMutablePointer<Output>, UnsafeMutablePointer<CChar>, Int, UnsafeMutablePointer<UnsafeMutablePointer<Output>?>) -> Int32' (aka '(String, UnsafeMutablePointer<Output>, UnsafeMutablePointer<Int8>, Int, UnsafeMutablePointer<Optional<UnsafeMutablePointer<Output>>>) -> Int32') may allow it to escape
166 |
167 | static func gid(forName name: String) -> uid_t? {
168 | withUserGroupBuffer(name, group(), sizeProperty: Int32(_SC_GETGR_R_SIZE_MAX), operation: getgrnam_r) {
| `- error: converting non-escaping value to '(String, UnsafeMutablePointer<Output>, UnsafeMutablePointer<CChar>, Int, UnsafeMutablePointer<UnsafeMutablePointer<Output>?>) -> Int32' (aka '(String, UnsafeMutablePointer<Output>, UnsafeMutablePointer<Int8>, Int, UnsafeMutablePointer<Optional<UnsafeMutablePointer<Output>>>) -> Int32') may allow it to escape
169 | $0.gr_gid
170 | }
D:/r/_work/swift-build/swift-build/SourceCache/swift-foundation/Sources/FoundationEssentials/Platform.swift:175:32: error: value of optional type 'UnsafeMutablePointer<CChar>?' (aka 'Optional<UnsafeMutablePointer<Int8>>') must be unwrapped to a value of type 'UnsafeMutablePointer<CChar>' (aka 'UnsafeMutablePointer<Int8>')
173 | static func name(forUID uid: uid_t) -> String? {
174 | withUserGroupBuffer(uid, passwd(), sizeProperty: Int32(_SC_GETPW_R_SIZE_MAX), operation: getpwuid_r) {
175 | String(cString: $0.pw_name)
| |- error: value of optional type 'UnsafeMutablePointer<CChar>?' (aka 'Optional<UnsafeMutablePointer<Int8>>') must be unwrapped to a value of type 'UnsafeMutablePointer<CChar>' (aka 'UnsafeMutablePointer<Int8>')
| |- note: coalesce using '??' to provide a default when the optional value contains 'nil'
| `- note: force-unwrap using '!' to abort execution if the optional value contains 'nil'
176 | }
177 | }
D:/r/_work/swift-build/swift-build/SourceCache/swift-foundation/Sources/FoundationEssentials/Platform.swift:181:32: error: value of optional type 'UnsafeMutablePointer<CChar>?' (aka 'Optional<UnsafeMutablePointer<Int8>>') must be unwrapped to a value of type 'UnsafeMutablePointer<CChar>' (aka 'UnsafeMutablePointer<Int8>')
179 | static func fullName(forUID uid: uid_t) -> String? {
180 | withUserGroupBuffer(uid, passwd(), sizeProperty: Int32(_SC_GETPW_R_SIZE_MAX), operation: getpwuid_r) {
181 | String(cString: $0.pw_gecos)
| |- error: value of optional type 'UnsafeMutablePointer<CChar>?' (aka 'Optional<UnsafeMutablePointer<Int8>>') must be unwrapped to a value of type 'UnsafeMutablePointer<CChar>' (aka 'UnsafeMutablePointer<Int8>')
| |- note: coalesce using '??' to provide a default when the optional value contains 'nil'
| `- note: force-unwrap using '!' to abort execution if the optional value contains 'nil'
182 | }
183 | }
D:/r/_work/swift-build/swift-build/SourceCache/swift-foundation/Sources/FoundationEssentials/Platform.swift:186:34: error: cannot find 'group' in scope
184 |
185 | static func name(forGID gid: gid_t) -> String? {
186 | withUserGroupBuffer(gid, group(), sizeProperty: Int32(_SC_GETGR_R_SIZE_MAX), operation: getgrgid_r) {
| `- error: cannot find 'group' in scope
187 | String(cString: $0.gr_name)
188 | }
D:/r/_work/swift-build/swift-build/SourceCache/swift-foundation/Sources/FoundationEssentials/Platform.swift:186:97: error: cannot find 'getgrgid_r' in scope
184 |
185 | static func name(forGID gid: gid_t) -> String? {
186 | withUserGroupBuffer(gid, group(), sizeProperty: Int32(_SC_GETGR_R_SIZE_MAX), operation: getgrgid_r) {
| `- error: cannot find 'getgrgid_r' in scope
187 | String(cString: $0.gr_name)
188 | }
D:/r/_work/swift-build/swift-build/SourceCache/swift-foundation/Sources/FoundationEssentials/Platform.swift:186:97: error: converting non-escaping value to '(gid_t, UnsafeMutablePointer<Output>, UnsafeMutablePointer<CChar>, Int, UnsafeMutablePointer<UnsafeMutablePointer<Output>?>) -> Int32' (aka '(UInt32, UnsafeMutablePointer<Output>, UnsafeMutablePointer<Int8>, Int, UnsafeMutablePointer<Optional<UnsafeMutablePointer<Output>>>) -> Int32') may allow it to escape
184 |
185 | static func name(forGID gid: gid_t) -> String? {
186 | withUserGroupBuffer(gid, group(), sizeProperty: Int32(_SC_GETGR_R_SIZE_MAX), operation: getgrgid_r) {
| `- error: converting non-escaping value to '(gid_t, UnsafeMutablePointer<Output>, UnsafeMutablePointer<CChar>, Int, UnsafeMutablePointer<UnsafeMutablePointer<Output>?>) -> Int32' (aka '(UInt32, UnsafeMutablePointer<Output>, UnsafeMutablePointer<Int8>, Int, UnsafeMutablePointer<Optional<UnsafeMutablePointer<Output>>>) -> Int32') may allow it to escape
187 | String(cString: $0.gr_name)
188 | }
D:/r/_work/swift-build/swift-build/SourceCache/swift-foundation/Sources/FoundationEssentials/Platform.swift:193:32: error: value of optional type 'UnsafeMutablePointer<CChar>?' (aka 'Optional<UnsafeMutablePointer<Int8>>') must be unwrapped to a value of type 'UnsafeMutablePointer<CChar>' (aka 'UnsafeMutablePointer<Int8>')
191 | static func homeDirectory(forUserName userName: String) -> String? {
192 | withUserGroupBuffer(userName, passwd(), sizeProperty: Int32(_SC_GETPW_R_SIZE_MAX), operation: getpwnam_r) {
193 | String(cString: $0.pw_dir)
| |- error: value of optional type 'UnsafeMutablePointer<CChar>?' (aka 'Optional<UnsafeMutablePointer<Int8>>') must be unwrapped to a value of type 'UnsafeMutablePointer<CChar>' (aka 'UnsafeMutablePointer<Int8>')
| |- note: coalesce using '??' to provide a default when the optional value contains 'nil'
| `- note: force-unwrap using '!' to abort execution if the optional value contains 'nil'
194 | }
195 | }
D:/r/_work/swift-build/swift-build/SourceCache/swift-foundation/Sources/FoundationEssentials/Platform.swift:199:32: error: value of optional type 'UnsafeMutablePointer<CChar>?' (aka 'Optional<UnsafeMutablePointer<Int8>>') must be unwrapped to a value of type 'UnsafeMutablePointer<CChar>' (aka 'UnsafeMutablePointer<Int8>')
197 | static func homeDirectory(forUID uid: uid_t) -> String? {
198 | withUserGroupBuffer(uid, passwd(), sizeProperty: Int32(_SC_GETPW_R_SIZE_MAX), operation: getpwuid_r) {
199 | String(cString: $0.pw_dir)
| |- error: value of optional type 'UnsafeMutablePointer<CChar>?' (aka 'Optional<UnsafeMutablePointer<Int8>>') must be unwrapped to a value of type 'UnsafeMutablePointer<CChar>' (aka 'UnsafeMutablePointer<Int8>')
| |- note: coalesce using '??' to provide a default when the optional value contains 'nil'
| `- note: force-unwrap using '!' to abort execution if the optional value contains 'nil'
200 | }
201 | }
[571/577] Building CXX object _deps/swiftfoundationicu-build/icuSources/CMakeFiles/_FoundationICU.dir/common/icu_packaged_data.cpp.o
ninja: build stopped: subcommand failed.
we need to import full Android module to import sub-module grp
to access group
APIs, and also the const char * properties of users/groups are nullable on Android.
@jmschonfeld unfortunately, it looks like Clang's API Notes do not support changing the nullability of a field in a C struct :( , and I would be unable to use API notes to fix the nullability for fields I mentioned above. I'm going to file an issue on the NDK so that they can fix it in source, but in the mean time, do you think it would be ok to land this instead, with fixed up comments that mention that we're waiting on the NDK fix?
@jmschonfeld unfortunately, it looks like Clang's API Notes do not support changing the nullability of a field in a C struct :( , and I would be unable to use API notes to fix the nullability for fields I mentioned above. I'm going to file an issue on the NDK so that they can fix it in source, but in the mean time, do you think it would be ok to land this instead, with fixed up comments that mention that we're waiting on the NDK fix?
Unfortunate but yeah this is probably the best resolution to keep Android building in the meantime. Left one small comment but otherwise this is looking good to me based on that.
@jmschonfeld Updated the PR as requested, and linked to the NDK issue.
@swift-ci please test
Platform.swift regressed after 71eefee7fca08ecbeacc89098b74ab80319baa6b