tuist / XcodeProj

📝 Read, update and write your Xcode projects
https://xcodeproj.tuist.io
MIT License
2.02k stars 302 forks source link

XcodeGen: error: ambiguous use of 'arc4random_uniform' on Linux distros #845

Open Howler4695 opened 3 weeks ago

Howler4695 commented 3 weeks ago

Context 🕵️‍♀️

When compiling XcodeGen on Linux distros using Swift 5.10.1 the compile will fail with the error:

/root/XcodeGen/.build/checkouts/XcodeProj/Sources/XcodeProj/Extensions/String+Utils.swift:25:31: error: ambiguous use of 'arc4random_uniform'
            let randomValue = arc4random_uniform(UInt32(base.count))

Related XcodeGen issue: https://github.com/yonaskolb/XcodeGen/issues/1495

What

I believe this error is being caused by the random number generator arc4random_uniform and the pattern that overwrites it for linux distros

Proposal 🎉

I propose the following fix: https://github.com/Howler4695/XcodeProj/blob/main/Sources/XcodeProj/Extensions/String%2BUtils.swift

I've tested it on my linux distros and it's fixed my issue and I haven't found any others arising from it. I'm not familiar with swift though so this fix could cause problems with older swift versions or something.