I have a simple cli written in Swift that I want to run on Alpine. I want the binary to be self-contained. How can I do that? I have tried:
- using
swift runandswift buildwith--static-swift-stdlib(but that has no musl support?) - static linking with
docker run -v "$PWD:/sources" -w /sources --platform linux/amd64 swift:latest swiftc -emit-executable -static-executable -O main.swift testit, but then the executabletestitwhen running it on Alpine, says it isUnable to obtain Swift runtime path Aborted.
The code of the program:
// The Swift Programming Language
// https://docs.swift.org/swift-book
func getSecret() -> String {
let CharArr: [Character] = ["T", "h", "i", "s", " ", "a", " ", "s", "e", "c", "r", "e", "t"]
let newStr = String(CharArr)
return newStr
}
if(CommandLine.arguments.count == 2){
if (CommandLine.arguments[1] == "spoil"){
print(getSecret())
} else {
if (CommandLine.arguments[1] == getSecret()){
print("This is correct! Congrats!");
}else{
print("This is incorrect. Try again");
}
}
} else if (CommandLine.arguments.count==1) {
print("Welcome to the wrongsecrets Swift binary which hides a secret.");
print("Use args spoil or a string to guess the password.");
} else {
print("Too many arguments supplied.");
}
Can you help me please?