{"id":17021424,"url":"https://github.com/uliwitness/cpptoswift","last_synced_at":"2025-08-05T11:12:39.403Z","repository":{"id":136633730,"uuid":"44489042","full_name":"uliwitness/cpptoswift","owner":"uliwitness","description":"Hack that'll hopefully one day auto-generate a Swift wrapper around C++ source code.","archived":false,"fork":false,"pushed_at":"2015-10-21T23:22:49.000Z","size":136,"stargazers_count":13,"open_issues_count":0,"forks_count":1,"subscribers_count":2,"default_branch":"master","last_synced_at":"2025-05-19T06:08:38.219Z","etag":null,"topics":["personal-utility","work-in-progress"],"latest_commit_sha":null,"homepage":"","language":"Swift","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/uliwitness.png","metadata":{"files":{"readme":"Readme.md","changelog":null,"contributing":null,"funding":null,"license":null,"code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2015-10-18T17:45:32.000Z","updated_at":"2021-03-19T06:24:10.000Z","dependencies_parsed_at":"2023-03-18T13:47:01.297Z","dependency_job_id":null,"html_url":"https://github.com/uliwitness/cpptoswift","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"purl":"pkg:github/uliwitness/cpptoswift","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/uliwitness%2Fcpptoswift","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/uliwitness%2Fcpptoswift/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/uliwitness%2Fcpptoswift/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/uliwitness%2Fcpptoswift/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/uliwitness","download_url":"https://codeload.github.com/uliwitness/cpptoswift/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/uliwitness%2Fcpptoswift/sbom","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":268883500,"owners_count":24323148,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","status":"online","status_checked_at":"2025-08-05T02:00:12.334Z","response_time":2576,"last_error":null,"robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":true,"can_crawl_api":true,"host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["personal-utility","work-in-progress"],"created_at":"2024-10-14T07:07:37.127Z","updated_at":"2025-08-05T11:12:39.381Z","avatar_url":"https://github.com/uliwitness.png","language":"Swift","funding_links":[],"categories":[],"sub_categories":[],"readme":"Hack for generating a Swift class around a C++ class. It does this by wrapping the\nC++ class in C and then generating a Swift class that calls this\n\nUsage\n-----\n\nPut the following in your prefix header or at the start of every exported C++ header:\n\n\t#ifndef CP2SINIT\n\t#define CP2SINIT\n\t#define CP2SMETHOD\n\t#define CP2SCLASS\n\t#endif\n\n(This will hide cpp2swift's markup from the C++ compiler)\n\nThen mark up every class, constructor and method that you want to export from\nyour class to Swift with CP2SCLASS, CP2SINIT resp. CP2SMETHOD. E.g. a simple example:\n\n\t#include \u003cstdio.h\u003e\n\t\n\t#ifndef CP2SINIT\n\t#define CP2SINIT\n\t#define CP2SMETHOD\n\t#define CP2SCLASS\n\t#endif\n\n\n\tclass cppclass CP2SCLASS\n\t{\n\tpublic:\n\t\tcppclass() CP2SINIT : ivar(1234)\t{}\n\t\t\n\t\tvoid\tmethod( int theNum ) CP2SMETHOD;\n\t\tvoid\tmethod2() CP2SMETHOD { printf(\"yay!\"); }\n\t\t\n\tprotected:\n\t\tint\tivar;\n\t};\n\nThen run the cpptoswift tool with your C++ header as the first argument\nand the path and base name (without filename suffix) you want for the\noutput files as the second argument, E.g.:\n\n\tcpptoswift mysource.hpp generated/mysource\n\nIt will generate 3 files:\n\n\tgenerated/mysource.cpp\t-\tThe glue code that bridges your C++ class to C.\n\tgenerated/mysource.h\t-\tA header that you should include from your\n\t\t\t\t\t\t\t\tSwift app's bridging header.\n\tgenerated/mysource.swift-\tA Swift class that calls the functions declared\n\t\t\t\t\t\t\t\tand defined by the other two files to create and\n\t\t\t\t\t\t\t\tdestruct the C++ object.\n\nNote that this software is a work in progress and might not fully work,\nespecially as C++ code becomes more complex.\n\nIt is recommended that you put all the generated code in a framework, which\ncan then have its own bridging header, leaving your actual project that uses\nthe Swift wrapper free from C++ and C, and mostly ignorant of the C++ code's\ninternal file structure.\n\n\nLicense\n-------\n\n    Copyright 2015 by Uli Kusterer.\n\n    This software is provided 'as-is', without any express or implied\n    warranty. In no event will the authors be held liable for any damages\n    arising from the use of this software.\n\n    Permission is granted to anyone to use this software for any purpose,\n    including commercial applications, and to alter it and redistribute it\n    freely, subject to the following restrictions:\n\n    1. The origin of this software must not be misrepresented; you must not\n    claim that you wrote the original software. If you use this software\n    in a product, an acknowledgment in the product documentation would be\n    appreciated but is not required.\n\n    2. Altered source versions must be plainly marked as such, and must not be\n    misrepresented as being the original software.\n\n    3. This notice may not be removed or altered from any source\n    distribution.\n\nThe source code files generated by this software based on your files are exempt\nfrom this license and are subject to whatever original license the input files\nwere under.","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fuliwitness%2Fcpptoswift","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fuliwitness%2Fcpptoswift","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fuliwitness%2Fcpptoswift/lists"}