Skip to content

Instantly share code, notes, and snippets.

@pakLebah
Last active May 19, 2021
Embed
What would you like to do?
My VS Code tasks for Apple's Swift programs on Mac.
{
// Use IntelliSense to learn about possible attributes.
// Hover to view descriptions of existing attributes.
// For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387
"version": "0.2.0",
"configurations": [
{
"type": "lldb",
"name": "LLDB",
"cwd" : "${workspaceFolder}",
"request" : "launch",
"program" : ".build/Debug/${fileBasenameNoExtension}",
"terminal": "integrated",
"preLaunchTask": "swift: Build Debug",
// "postDebugTask": "swift: Clean Build Files",
"args": [],
},
]
}
{
// See https://go.microsoft.com/fwlink/?LinkId=733558
// for the documentation about the tasks.json format
"version": "2.0.0",
"options": {
"cwd": "${workspaceFolder}",
"env": {
// for single file based swift project
"PROJECTFILE" : "${relativeFile}",
"PROJECTNAME" : "${fileBasenameNoExtension}",
"OUTPUT" : ".build",
"DEBUG" : "Debug",
"MODULE" : "Module",
"RELEASE" : "Release",
"EXTENSION" : ".cgi", // set this to .cgi for web app
"SYSTEM" : "x86_64-apple-macosx10.10",
"FORMATTER" : "${workspaceFolder}/swift-format",
"FORMATCONFIG": "${workspaceFolder}/swift-format.json",
// import custom module files (module name with -l prefix)
"IMPORT_1" : "-lhello",
"IMPORT_2" : "",
"IMPORT_3" : "",
"IMPORT_4" : "",
"IMPORT_5" : "",
},
},
"tasks": [
{
"label": "swift: Build Debug",
"group": {
"kind" : "build",
"isDefault": true
},
"type" : "shell",
"command": "swiftc",
"args": [
"${PROJECTFILE}",
"-I","${OUTPUT}/${MODULE}",
"-L","${OUTPUT}/${MODULE}",
"-o","${OUTPUT}/${DEBUG}/${PROJECTNAME}",
"-working-directory","${cwd}",
"-target","${SYSTEM}",
"-gdwarf-types",
"-Onone",
"-g",
"-v",
"${IMPORT_1}","${IMPORT_2}","${IMPORT_3}","${IMPORT_4}","${IMPORT_5}",
],
"problemMatcher": []
},
{
"label": "swift: Build Release",
"group": "build",
"type" : "shell",
"command": "swiftc",
"args": [
"${PROJECTFILE}",
"-I","${OUTPUT}/${MODULE}",
"-L","${OUTPUT}/${MODULE}",
"-o","${OUTPUT}/${RELEASE}/${PROJECTNAME}",
"-working-directory","${cwd}",
"-target","${SYSTEM}",
// "-static-executable",
"-O",
"-gnone",
"-v",
"${IMPORT_1}","${IMPORT_2}","${IMPORT_3}","${IMPORT_4}","${IMPORT_5}",
],
"problemMatcher": []
},
{
"label": "swift: Build Module",
"group": "build",
"type" : "shell",
"command": "swiftc",
"args": [
"${PROJECTFILE}",
"-I","${OUTPUT}/${MODULE}",
"-L","${OUTPUT}/${MODULE}",
"-o","${OUTPUT}/${MODULE}/lib${PROJECTNAME}.dylib", // for macOS
"-working-directory","${cwd}",
"-target","${SYSTEM}",
"-emit-module",
"-emit-library",
// "-parse-as-library",
// "-module-name","${PROJECTNAME}",
"-Onone",
"-g",
"-v",
// "${IMPORT_1}","${IMPORT_2}","${IMPORT_3}","${IMPORT_4}","${IMPORT_5}",
],
"problemMatcher": []
},
{
"label": "swift: Run Code (REPL)",
"group": "test",
"type" : "shell",
"command": "swift",
"args": [
// REPL doesn't support custom modules
"${PROJECTFILE}",
"-I","${OUTPUT}/${MODULE}",
"-L","${OUTPUT}/${MODULE}",
"-working-directory","${cwd}",
"-target","${SYSTEM}",
],
"presentation": {
"reveal": "always",
"panel" : "shared",
"clear" : true,
"focus" : true,
},
"problemMatcher": []
},
{
"label": "swift: Run Executable",
"group": {
"kind" : "test",
"isDefault": true
},
"type" : "shell",
"command": "${OUTPUT}/${DEBUG}/${PROJECTNAME}",
"args": [],
"presentation": {
"reveal": "always",
"panel" : "shared",
"clear" : true,
"focus" : true,
},
"problemMatcher": []
},
{
"label": "swift: Create Build Folders",
"type" : "shell",
"command": "mkdir",
"args": [
"${OUTPUT}",
"${OUTPUT}/${DEBUG}",
"${OUTPUT}/${MODULE}",
"${OUTPUT}/${RELEASE}",
],
"presentation": {
"reveal": "silent",
},
"problemMatcher": []
},
{
"label": "swift: Clean Build Files",
"type" : "shell",
"command": "rm",
"args": [
"-rf",
"${OUTPUT}/${DEBUG}/*",
"${OUTPUT}/${RELEASE}/*",
"${OUTPUT}/${PROJECTNAME}.*",
"main.dSYM",
"main",
],
"presentation": {
"reveal": "silent",
},
"problemMatcher": []
},
{
"label": "swift: Clean Module Files",
"type" : "shell",
"command": "rm",
"args": [
"-rf",
"${OUTPUT}/${MODULE}/${PROJECTNAME}.o",
"${OUTPUT}/${MODULE}/${PROJECTNAME}.swiftdoc",
"${OUTPUT}/${MODULE}/${PROJECTNAME}.swiftmodule",
"${OUTPUT}/${MODULE}/lib${PROJECTNAME}.dylib",
"${OUTPUT}/${MODULE}/lib${PROJECTNAME}.dylib.dSYM",
],
"presentation": {
"reveal": "silent",
},
"problemMatcher": []
},
{ // format code using google's swift-format
"label": "swift: Beautify File",
"type" : "shell",
"command": "${FORMATTER}",
"args": [
"-i",
"-m","format",
"--configuration","${FORMATCONFIG}",
"${fileDirname}/${fileBasenameNoExtension}.swift",
],
"presentation": {
"reveal": "silent",
},
"problemMatcher": []
},
]
}
{
// See https://go.microsoft.com/fwlink/?LinkId=733558
// for the documentation about the tasks.json format
"version": "2.0.0",
"options": {
"cwd": "${workspaceFolder}",
"env": {
// for folder based swift project (SPM or xcode)
"PROJECTFILE" : "${workspaceFolderBasename}/*.swift",
"PROJECTNAME" : "${workspaceFolderBasename}",
"OUTPUT" : "Build/Products",
"DEBUG" : "Debug",
"MODULE" : "Module",
"RELEASE" : "Release",
"EXTENSION" : ".cgi", // set this to .cgi for web app
"SYSTEM" : "x86_64-apple-macosx10.10",
"FORMATTER" : "${workspaceFolder}/swift-format",
"FORMATCONFIG": "${workspaceFolder}/swift-format.json",
// import custom module files (module name with -l prefix)
"IMPORT_1" : "-lhelper",
"IMPORT_2" : "",
"IMPORT_3" : "",
"IMPORT_4" : "",
"IMPORT_5" : "",
},
},
"tasks": [
{
"label": "swift: Build Debug",
"group": {
"kind" : "build",
"isDefault": true
},
"type" : "shell",
"command": "swiftc",
"args": [
"${PROJECTFILE}",
"-I","${OUTPUT}/${MODULE}",
"-L","${OUTPUT}/${MODULE}",
"-o","${OUTPUT}/${DEBUG}/${PROJECTNAME}",
"-working-directory","${cwd}",
"-target","${SYSTEM}",
"-gdwarf-types",
"-Onone",
"-g",
"-v",
"${IMPORT_1}","${IMPORT_2}","${IMPORT_3}","${IMPORT_4}","${IMPORT_5}",
],
"problemMatcher": []
},
{
"label": "swift: Build Release",
"group": "build",
"type" : "shell",
"command": "swiftc",
"args": [
"${PROJECTFILE}",
"-I","${OUTPUT}/${MODULE}",
"-L","${OUTPUT}/${MODULE}",
"-o","${OUTPUT}/${RELEASE}/${PROJECTNAME}",
"-working-directory","${cwd}",
"-target","${SYSTEM}",
// "-static-executable",
"-O",
"-gnone",
"-v",
"${IMPORT_1}","${IMPORT_2}","${IMPORT_3}","${IMPORT_4}","${IMPORT_5}",
],
"problemMatcher": []
},
{
"label": "swift: Build Module",
"group": "build",
"type" : "shell",
"command": "swiftc",
"args": [
"${relativeFile}",
"-I","${OUTPUT}/${MODULE}",
"-L","${OUTPUT}/${MODULE}",
"-o","${OUTPUT}/${MODULE}/lib${fileBasenameNoExtension}.dylib", // for macOS
"-working-directory","${cwd}",
"-target","${SYSTEM}",
"-emit-module",
"-emit-library",
// "-parse-as-library",
// "-module-name","${fileBasenameNoExtension}",
"-Onone",
"-g",
"-v",
// "${IMPORT_1}","${IMPORT_2}","${IMPORT_3}","${IMPORT_4}","${IMPORT_5}",
],
"problemMatcher": []
},
{
"label": "swift: Run Executable",
"group": {
"kind" : "test",
"isDefault": true
},
"type" : "shell",
"command": "${OUTPUT}/${DEBUG}/${PROJECTNAME}",
"args": [],
"presentation": {
"reveal": "always",
"panel" : "shared",
"clear" : true,
"focus" : true,
},
"problemMatcher": []
},
{
"label": "swift: Create Build Folders",
"type" : "shell",
"command": "mkdir",
"args": [
"Build",
"${OUTPUT}",
"${OUTPUT}/${DEBUG}",
"${OUTPUT}/${MODULE}",
"${OUTPUT}/${RELEASE}",
],
"presentation": {
"reveal": "silent",
},
"problemMatcher": []
},
{
"label": "swift: Clean Build Files",
"type" : "shell",
"command": "rm",
"args": [
"-rf",
"${OUTPUT}/${DEBUG}/*",
"${OUTPUT}/${RELEASE}/*",
"${OUTPUT}/${PROJECTNAME}.*",
"main.dSYM",
"main",
],
"presentation": {
"reveal": "silent",
},
"problemMatcher": []
},
{
"label": "swift: Clean Module Files",
"type" : "shell",
"command": "rm",
"args": [
"-rf",
"${OUTPUT}/${MODULE}/${fileBasenameNoExtension}.o",
"${OUTPUT}/${MODULE}/${fileBasenameNoExtension}.swiftdoc",
"${OUTPUT}/${MODULE}/${fileBasenameNoExtension}.swiftmodule",
"${OUTPUT}/${MODULE}/lib${fileBasenameNoExtension}.dylib",
"${OUTPUT}/${MODULE}/lib${fileBasenameNoExtension}.dylib.dSYM",
],
"presentation": {
"reveal": "silent",
},
"problemMatcher": []
},
{ // format code using google's swift-format
"label": "swift: Beautify File",
"type" : "shell",
"command": "${FORMATTER}",
"args": [
"-i",
"-m","format",
"--configuration","${FORMATCONFIG}",
"${fileDirname}/${fileBasenameNoExtension}.swift",
],
"presentation": {
"reveal": "silent",
},
"problemMatcher": []
},
]
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment