├── .gitignore ├── LICENSE ├── Makefile ├── PLSwift.xcodeproj └── project.pbxproj ├── Package.swift ├── README.md ├── Sources └── PLSwift │ ├── PGDatum.swift │ ├── PGExtension.swift │ └── PGFunction.swift ├── configure ├── shims └── PLSwiftShim.h ├── swift-pl ├── swift-pl ├── swift-pl-build ├── swift-pl-clean ├── swift-pl-init ├── swift-pl-install └── swift-pl-validate └── xcconfig ├── PGExtSwiftLib.xcconfig ├── config.make └── rules-pgconfig.make /.gitignore: -------------------------------------------------------------------------------- 1 | # Xcode 2 | # 3 | # gitignore contributors: remember to update Global/Xcode.gitignore, Objective-C.gitignore & Swift.gitignore 4 | 5 | ## Build generated 6 | build/ 7 | DerivedData/ 8 | 9 | ## Various settings 10 | *.pbxuser 11 | !default.pbxuser 12 | *.mode1v3 13 | !default.mode1v3 14 | *.mode2v3 15 | !default.mode2v3 16 | *.perspectivev3 17 | !default.perspectivev3 18 | xcuserdata/ 19 | 20 | ## Other 21 | *.moved-aside 22 | *.xcuserstate 23 | 24 | ## Obj-C/Swift specific 25 | *.hmap 26 | *.ipa 27 | *.dSYM.zip 28 | *.dSYM 29 | 30 | ## Playgrounds 31 | timeline.xctimeline 32 | playground.xcworkspace 33 | 34 | # Swift Package Manager 35 | # 36 | # Add this line if you want to avoid checking in source code from Swift Package Manager dependencies. 37 | # Packages/ 38 | .build/ 39 | 40 | # CocoaPods 41 | # 42 | # We recommend against adding the Pods directory to your .gitignore. However 43 | # you should judge for yourself, the pros and cons are mentioned at: 44 | # https://guides.cocoapods.org/using/using-cocoapods.html#should-i-check-the-pods-directory-into-source-control 45 | # 46 | # Pods/ 47 | 48 | # Carthage 49 | # 50 | # Add this line if you want to avoid checking in source code from Carthage dependencies. 51 | # Carthage/Checkouts 52 | 53 | Carthage/Build 54 | 55 | # fastlane 56 | # 57 | # It is recommended to not store the screenshots in the git repo. Instead, use fastlane to re-generate the 58 | # screenshots whenever they are needed. 59 | # For more information about the recommended setup visit: 60 | # https://github.com/fastlane/fastlane/blob/master/fastlane/docs/Gitignore.md 61 | 62 | fastlane/report.xml 63 | fastlane/Preview.html 64 | fastlane/screenshots 65 | fastlane/test_output 66 | 67 | # hh 68 | .libs 69 | *.la 70 | *.lo 71 | *.slo 72 | *.so 73 | build 74 | *.build 75 | Debug 76 | Release 77 | *.pid 78 | *.xcscmblueprint 79 | 80 | *~ 81 | *.o 82 | 83 | .DS_Store 84 | /.build 85 | /Packages 86 | Package.resolved 87 | config.make 88 | 89 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | Apache License 2 | Version 2.0, January 2004 3 | http://www.apache.org/licenses/ 4 | 5 | TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION 6 | 7 | 1. Definitions. 8 | 9 | "License" shall mean the terms and conditions for use, reproduction, 10 | and distribution as defined by Sections 1 through 9 of this document. 11 | 12 | "Licensor" shall mean the copyright owner or entity authorized by 13 | the copyright owner that is granting the License. 14 | 15 | "Legal Entity" shall mean the union of the acting entity and all 16 | other entities that control, are controlled by, or are under common 17 | control with that entity. For the purposes of this definition, 18 | "control" means (i) the power, direct or indirect, to cause the 19 | direction or management of such entity, whether by contract or 20 | otherwise, or (ii) ownership of fifty percent (50%) or more of the 21 | outstanding shares, or (iii) beneficial ownership of such entity. 22 | 23 | "You" (or "Your") shall mean an individual or Legal Entity 24 | exercising permissions granted by this License. 25 | 26 | "Source" form shall mean the preferred form for making modifications, 27 | including but not limited to software source code, documentation 28 | source, and configuration files. 29 | 30 | "Object" form shall mean any form resulting from mechanical 31 | transformation or translation of a Source form, including but 32 | not limited to compiled object code, generated documentation, 33 | and conversions to other media types. 34 | 35 | "Work" shall mean the work of authorship, whether in Source or 36 | Object form, made available under the License, as indicated by a 37 | copyright notice that is included in or attached to the work 38 | (an example is provided in the Appendix below). 39 | 40 | "Derivative Works" shall mean any work, whether in Source or Object 41 | form, that is based on (or derived from) the Work and for which the 42 | editorial revisions, annotations, elaborations, or other modifications 43 | represent, as a whole, an original work of authorship. For the purposes 44 | of this License, Derivative Works shall not include works that remain 45 | separable from, or merely link (or bind by name) to the interfaces of, 46 | the Work and Derivative Works thereof. 47 | 48 | "Contribution" shall mean any work of authorship, including 49 | the original version of the Work and any modifications or additions 50 | to that Work or Derivative Works thereof, that is intentionally 51 | submitted to Licensor for inclusion in the Work by the copyright owner 52 | or by an individual or Legal Entity authorized to submit on behalf of 53 | the copyright owner. For the purposes of this definition, "submitted" 54 | means any form of electronic, verbal, or written communication sent 55 | to the Licensor or its representatives, including but not limited to 56 | communication on electronic mailing lists, source code control systems, 57 | and issue tracking systems that are managed by, or on behalf of, the 58 | Licensor for the purpose of discussing and improving the Work, but 59 | excluding communication that is conspicuously marked or otherwise 60 | designated in writing by the copyright owner as "Not a Contribution." 61 | 62 | "Contributor" shall mean Licensor and any individual or Legal Entity 63 | on behalf of whom a Contribution has been received by Licensor and 64 | subsequently incorporated within the Work. 65 | 66 | 2. Grant of Copyright License. Subject to the terms and conditions of 67 | this License, each Contributor hereby grants to You a perpetual, 68 | worldwide, non-exclusive, no-charge, royalty-free, irrevocable 69 | copyright license to reproduce, prepare Derivative Works of, 70 | publicly display, publicly perform, sublicense, and distribute the 71 | Work and such Derivative Works in Source or Object form. 72 | 73 | 3. Grant of Patent License. Subject to the terms and conditions of 74 | this License, each Contributor hereby grants to You a perpetual, 75 | worldwide, non-exclusive, no-charge, royalty-free, irrevocable 76 | (except as stated in this section) patent license to make, have made, 77 | use, offer to sell, sell, import, and otherwise transfer the Work, 78 | where such license applies only to those patent claims licensable 79 | by such Contributor that are necessarily infringed by their 80 | Contribution(s) alone or by combination of their Contribution(s) 81 | with the Work to which such Contribution(s) was submitted. If You 82 | institute patent litigation against any entity (including a 83 | cross-claim or counterclaim in a lawsuit) alleging that the Work 84 | or a Contribution incorporated within the Work constitutes direct 85 | or contributory patent infringement, then any patent licenses 86 | granted to You under this License for that Work shall terminate 87 | as of the date such litigation is filed. 88 | 89 | 4. Redistribution. You may reproduce and distribute copies of the 90 | Work or Derivative Works thereof in any medium, with or without 91 | modifications, and in Source or Object form, provided that You 92 | meet the following conditions: 93 | 94 | (a) You must give any other recipients of the Work or 95 | Derivative Works a copy of this License; and 96 | 97 | (b) You must cause any modified files to carry prominent notices 98 | stating that You changed the files; and 99 | 100 | (c) You must retain, in the Source form of any Derivative Works 101 | that You distribute, all copyright, patent, trademark, and 102 | attribution notices from the Source form of the Work, 103 | excluding those notices that do not pertain to any part of 104 | the Derivative Works; and 105 | 106 | (d) If the Work includes a "NOTICE" text file as part of its 107 | distribution, then any Derivative Works that You distribute must 108 | include a readable copy of the attribution notices contained 109 | within such NOTICE file, excluding those notices that do not 110 | pertain to any part of the Derivative Works, in at least one 111 | of the following places: within a NOTICE text file distributed 112 | as part of the Derivative Works; within the Source form or 113 | documentation, if provided along with the Derivative Works; or, 114 | within a display generated by the Derivative Works, if and 115 | wherever such third-party notices normally appear. The contents 116 | of the NOTICE file are for informational purposes only and 117 | do not modify the License. You may add Your own attribution 118 | notices within Derivative Works that You distribute, alongside 119 | or as an addendum to the NOTICE text from the Work, provided 120 | that such additional attribution notices cannot be construed 121 | as modifying the License. 122 | 123 | You may add Your own copyright statement to Your modifications and 124 | may provide additional or different license terms and conditions 125 | for use, reproduction, or distribution of Your modifications, or 126 | for any such Derivative Works as a whole, provided Your use, 127 | reproduction, and distribution of the Work otherwise complies with 128 | the conditions stated in this License. 129 | 130 | 5. Submission of Contributions. Unless You explicitly state otherwise, 131 | any Contribution intentionally submitted for inclusion in the Work 132 | by You to the Licensor shall be under the terms and conditions of 133 | this License, without any additional terms or conditions. 134 | Notwithstanding the above, nothing herein shall supersede or modify 135 | the terms of any separate license agreement you may have executed 136 | with Licensor regarding such Contributions. 137 | 138 | 6. Trademarks. This License does not grant permission to use the trade 139 | names, trademarks, service marks, or product names of the Licensor, 140 | except as required for reasonable and customary use in describing the 141 | origin of the Work and reproducing the content of the NOTICE file. 142 | 143 | 7. Disclaimer of Warranty. Unless required by applicable law or 144 | agreed to in writing, Licensor provides the Work (and each 145 | Contributor provides its Contributions) on an "AS IS" BASIS, 146 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or 147 | implied, including, without limitation, any warranties or conditions 148 | of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A 149 | PARTICULAR PURPOSE. You are solely responsible for determining the 150 | appropriateness of using or redistributing the Work and assume any 151 | risks associated with Your exercise of permissions under this License. 152 | 153 | 8. Limitation of Liability. In no event and under no legal theory, 154 | whether in tort (including negligence), contract, or otherwise, 155 | unless required by applicable law (such as deliberate and grossly 156 | negligent acts) or agreed to in writing, shall any Contributor be 157 | liable to You for damages, including any direct, indirect, special, 158 | incidental, or consequential damages of any character arising as a 159 | result of this License or out of the use or inability to use the 160 | Work (including but not limited to damages for loss of goodwill, 161 | work stoppage, computer failure or malfunction, or any and all 162 | other commercial damages or losses), even if such Contributor 163 | has been advised of the possibility of such damages. 164 | 165 | 9. Accepting Warranty or Additional Liability. While redistributing 166 | the Work or Derivative Works thereof, You may choose to offer, 167 | and charge a fee for, acceptance of support, warranty, indemnity, 168 | or other liability obligations and/or rights consistent with this 169 | License. However, in accepting such obligations, You may act only 170 | on Your own behalf and on Your sole responsibility, not on behalf 171 | of any other Contributor, and only if You agree to indemnify, 172 | defend, and hold each Contributor harmless for any liability 173 | incurred by, or claims asserted against, such Contributor by reason 174 | of your accepting any such warranty or additional liability. 175 | 176 | END OF TERMS AND CONDITIONS 177 | 178 | APPENDIX: How to apply the Apache License to your work. 179 | 180 | To apply the Apache License to your work, attach the following 181 | boilerplate notice, with the fields enclosed by brackets "{}" 182 | replaced with your own identifying information. (Don't include 183 | the brackets!) The text should be enclosed in the appropriate 184 | comment syntax for the file format. We also recommend that a 185 | file or class name and description of purpose be included on the 186 | same "printed page" as the copyright notice for easier 187 | identification within third-party archives. 188 | 189 | Copyright {yyyy} {name of copyright owner} 190 | 191 | Licensed under the Apache License, Version 2.0 (the "License"); 192 | you may not use this file except in compliance with the License. 193 | You may obtain a copy of the License at 194 | 195 | http://www.apache.org/licenses/LICENSE-2.0 196 | 197 | Unless required by applicable law or agreed to in writing, software 198 | distributed under the License is distributed on an "AS IS" BASIS, 199 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 200 | See the License for the specific language governing permissions and 201 | limitations under the License. 202 | -------------------------------------------------------------------------------- /Makefile: -------------------------------------------------------------------------------- 1 | # GNUmakefile 2 | 3 | -include config.make 4 | include xcconfig/config.make 5 | 6 | PACKAGE=plswift 7 | 8 | MAJOR=0 9 | MINOR=1 10 | SUBMINOR=0 11 | 12 | SWIFT_SHIM_FILES = $(wildcard shims/*.h) 13 | 14 | SCRIPTS = $(wildcard swift-pl/swift-pl*) 15 | 16 | PACKAGE_DESCRIPTION = "Swift language support for PostgreSQL Server Extensions" 17 | 18 | include xcconfig/rules-pgconfig.make 19 | -------------------------------------------------------------------------------- /PLSwift.xcodeproj/project.pbxproj: -------------------------------------------------------------------------------- 1 | // !$*UTF8*$! 2 | { 3 | archiveVersion = 1; 4 | classes = { 5 | }; 6 | objectVersion = 48; 7 | objects = { 8 | 9 | /* Begin PBXBuildFile section */ 10 | E8227E1B1FFFED7F00356B2E /* PGDatum.swift in Sources */ = {isa = PBXBuildFile; fileRef = E8227E181FFFED7F00356B2E /* PGDatum.swift */; }; 11 | E8227E1C1FFFED7F00356B2E /* PGExtension.swift in Sources */ = {isa = PBXBuildFile; fileRef = E8227E191FFFED7F00356B2E /* PGExtension.swift */; }; 12 | E8227E1D1FFFED7F00356B2E /* PGFunction.swift in Sources */ = {isa = PBXBuildFile; fileRef = E8227E1A1FFFED7F00356B2E /* PGFunction.swift */; }; 13 | /* End PBXBuildFile section */ 14 | 15 | /* Begin PBXFileReference section */ 16 | E8227E101FFFECF600356B2E /* libPLSwift.dylib */ = {isa = PBXFileReference; explicitFileType = "compiled.mach-o.dylib"; includeInIndex = 0; path = libPLSwift.dylib; sourceTree = BUILT_PRODUCTS_DIR; }; 17 | E8227E181FFFED7F00356B2E /* PGDatum.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = PGDatum.swift; sourceTree = ""; }; 18 | E8227E191FFFED7F00356B2E /* PGExtension.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = PGExtension.swift; sourceTree = ""; }; 19 | E8227E1A1FFFED7F00356B2E /* PGFunction.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = PGFunction.swift; sourceTree = ""; }; 20 | E8227E1F1FFFED9200356B2E /* PGExtSwiftLib.xcconfig */ = {isa = PBXFileReference; lastKnownFileType = text.xcconfig; path = PGExtSwiftLib.xcconfig; sourceTree = ""; }; 21 | /* End PBXFileReference section */ 22 | 23 | /* Begin PBXFrameworksBuildPhase section */ 24 | E8227E0D1FFFECF600356B2E /* Frameworks */ = { 25 | isa = PBXFrameworksBuildPhase; 26 | buildActionMask = 2147483647; 27 | files = ( 28 | ); 29 | runOnlyForDeploymentPostprocessing = 0; 30 | }; 31 | /* End PBXFrameworksBuildPhase section */ 32 | 33 | /* Begin PBXGroup section */ 34 | E8227E071FFFECF600356B2E = { 35 | isa = PBXGroup; 36 | children = ( 37 | E8227E171FFFED7F00356B2E /* Sources */, 38 | E8227E1E1FFFED9200356B2E /* xcconfig */, 39 | E8227E111FFFECF600356B2E /* Products */, 40 | ); 41 | sourceTree = ""; 42 | }; 43 | E8227E111FFFECF600356B2E /* Products */ = { 44 | isa = PBXGroup; 45 | children = ( 46 | E8227E101FFFECF600356B2E /* libPLSwift.dylib */, 47 | ); 48 | name = Products; 49 | sourceTree = ""; 50 | }; 51 | E8227E171FFFED7F00356B2E /* Sources */ = { 52 | isa = PBXGroup; 53 | children = ( 54 | E8227E181FFFED7F00356B2E /* PGDatum.swift */, 55 | E8227E191FFFED7F00356B2E /* PGExtension.swift */, 56 | E8227E1A1FFFED7F00356B2E /* PGFunction.swift */, 57 | ); 58 | path = Sources; 59 | sourceTree = ""; 60 | }; 61 | E8227E1E1FFFED9200356B2E /* xcconfig */ = { 62 | isa = PBXGroup; 63 | children = ( 64 | E8227E1F1FFFED9200356B2E /* PGExtSwiftLib.xcconfig */, 65 | ); 66 | path = xcconfig; 67 | sourceTree = ""; 68 | }; 69 | /* End PBXGroup section */ 70 | 71 | /* Begin PBXHeadersBuildPhase section */ 72 | E8227E0E1FFFECF600356B2E /* Headers */ = { 73 | isa = PBXHeadersBuildPhase; 74 | buildActionMask = 2147483647; 75 | files = ( 76 | ); 77 | runOnlyForDeploymentPostprocessing = 0; 78 | }; 79 | /* End PBXHeadersBuildPhase section */ 80 | 81 | /* Begin PBXNativeTarget section */ 82 | E8227E0F1FFFECF600356B2E /* PLSwift */ = { 83 | isa = PBXNativeTarget; 84 | buildConfigurationList = E8227E141FFFECF600356B2E /* Build configuration list for PBXNativeTarget "PLSwift" */; 85 | buildPhases = ( 86 | E8227E0C1FFFECF600356B2E /* Sources */, 87 | E8227E0D1FFFECF600356B2E /* Frameworks */, 88 | E8227E0E1FFFECF600356B2E /* Headers */, 89 | ); 90 | buildRules = ( 91 | ); 92 | dependencies = ( 93 | ); 94 | name = PLSwift; 95 | productName = PLSwift; 96 | productReference = E8227E101FFFECF600356B2E /* libPLSwift.dylib */; 97 | productType = "com.apple.product-type.library.dynamic"; 98 | }; 99 | /* End PBXNativeTarget section */ 100 | 101 | /* Begin PBXProject section */ 102 | E8227E081FFFECF600356B2E /* Project object */ = { 103 | isa = PBXProject; 104 | attributes = { 105 | LastUpgradeCheck = 0920; 106 | ORGANIZATIONNAME = "ZeeZide GmbH"; 107 | TargetAttributes = { 108 | E8227E0F1FFFECF600356B2E = { 109 | CreatedOnToolsVersion = 9.2; 110 | LastSwiftMigration = 0920; 111 | ProvisioningStyle = Automatic; 112 | }; 113 | }; 114 | }; 115 | buildConfigurationList = E8227E0B1FFFECF600356B2E /* Build configuration list for PBXProject "PLSwift" */; 116 | compatibilityVersion = "Xcode 8.0"; 117 | developmentRegion = en; 118 | hasScannedForEncodings = 0; 119 | knownRegions = ( 120 | en, 121 | ); 122 | mainGroup = E8227E071FFFECF600356B2E; 123 | productRefGroup = E8227E111FFFECF600356B2E /* Products */; 124 | projectDirPath = ""; 125 | projectRoot = ""; 126 | targets = ( 127 | E8227E0F1FFFECF600356B2E /* PLSwift */, 128 | ); 129 | }; 130 | /* End PBXProject section */ 131 | 132 | /* Begin PBXSourcesBuildPhase section */ 133 | E8227E0C1FFFECF600356B2E /* Sources */ = { 134 | isa = PBXSourcesBuildPhase; 135 | buildActionMask = 2147483647; 136 | files = ( 137 | E8227E1C1FFFED7F00356B2E /* PGExtension.swift in Sources */, 138 | E8227E1B1FFFED7F00356B2E /* PGDatum.swift in Sources */, 139 | E8227E1D1FFFED7F00356B2E /* PGFunction.swift in Sources */, 140 | ); 141 | runOnlyForDeploymentPostprocessing = 0; 142 | }; 143 | /* End PBXSourcesBuildPhase section */ 144 | 145 | /* Begin XCBuildConfiguration section */ 146 | E8227E121FFFECF600356B2E /* Debug */ = { 147 | isa = XCBuildConfiguration; 148 | buildSettings = { 149 | ALWAYS_SEARCH_USER_PATHS = NO; 150 | CLANG_ANALYZER_NONNULL = YES; 151 | CLANG_ANALYZER_NUMBER_OBJECT_CONVERSION = YES_AGGRESSIVE; 152 | CLANG_CXX_LANGUAGE_STANDARD = "gnu++14"; 153 | CLANG_CXX_LIBRARY = "libc++"; 154 | CLANG_ENABLE_MODULES = YES; 155 | CLANG_ENABLE_OBJC_ARC = YES; 156 | CLANG_WARN_BLOCK_CAPTURE_AUTORELEASING = YES; 157 | CLANG_WARN_BOOL_CONVERSION = YES; 158 | CLANG_WARN_COMMA = YES; 159 | CLANG_WARN_CONSTANT_CONVERSION = YES; 160 | CLANG_WARN_DIRECT_OBJC_ISA_USAGE = YES_ERROR; 161 | CLANG_WARN_DOCUMENTATION_COMMENTS = YES; 162 | CLANG_WARN_EMPTY_BODY = YES; 163 | CLANG_WARN_ENUM_CONVERSION = YES; 164 | CLANG_WARN_INFINITE_RECURSION = YES; 165 | CLANG_WARN_INT_CONVERSION = YES; 166 | CLANG_WARN_NON_LITERAL_NULL_CONVERSION = YES; 167 | CLANG_WARN_OBJC_LITERAL_CONVERSION = YES; 168 | CLANG_WARN_OBJC_ROOT_CLASS = YES_ERROR; 169 | CLANG_WARN_RANGE_LOOP_ANALYSIS = YES; 170 | CLANG_WARN_STRICT_PROTOTYPES = YES; 171 | CLANG_WARN_SUSPICIOUS_MOVE = YES; 172 | CLANG_WARN_UNGUARDED_AVAILABILITY = YES_AGGRESSIVE; 173 | CLANG_WARN_UNREACHABLE_CODE = YES; 174 | CLANG_WARN__DUPLICATE_METHOD_MATCH = YES; 175 | CODE_SIGN_IDENTITY = "-"; 176 | COPY_PHASE_STRIP = NO; 177 | DEBUG_INFORMATION_FORMAT = dwarf; 178 | ENABLE_STRICT_OBJC_MSGSEND = YES; 179 | ENABLE_TESTABILITY = YES; 180 | GCC_C_LANGUAGE_STANDARD = gnu11; 181 | GCC_DYNAMIC_NO_PIC = NO; 182 | GCC_NO_COMMON_BLOCKS = YES; 183 | GCC_OPTIMIZATION_LEVEL = 0; 184 | GCC_PREPROCESSOR_DEFINITIONS = ( 185 | "DEBUG=1", 186 | "$(inherited)", 187 | ); 188 | GCC_WARN_64_TO_32_BIT_CONVERSION = YES; 189 | GCC_WARN_ABOUT_RETURN_TYPE = YES_ERROR; 190 | GCC_WARN_UNDECLARED_SELECTOR = YES; 191 | GCC_WARN_UNINITIALIZED_AUTOS = YES_AGGRESSIVE; 192 | GCC_WARN_UNUSED_FUNCTION = YES; 193 | GCC_WARN_UNUSED_VARIABLE = YES; 194 | MACOSX_DEPLOYMENT_TARGET = 10.12; 195 | MTL_ENABLE_DEBUG_INFO = YES; 196 | ONLY_ACTIVE_ARCH = YES; 197 | SDKROOT = macosx; 198 | }; 199 | name = Debug; 200 | }; 201 | E8227E131FFFECF600356B2E /* Release */ = { 202 | isa = XCBuildConfiguration; 203 | buildSettings = { 204 | ALWAYS_SEARCH_USER_PATHS = NO; 205 | CLANG_ANALYZER_NONNULL = YES; 206 | CLANG_ANALYZER_NUMBER_OBJECT_CONVERSION = YES_AGGRESSIVE; 207 | CLANG_CXX_LANGUAGE_STANDARD = "gnu++14"; 208 | CLANG_CXX_LIBRARY = "libc++"; 209 | CLANG_ENABLE_MODULES = YES; 210 | CLANG_ENABLE_OBJC_ARC = YES; 211 | CLANG_WARN_BLOCK_CAPTURE_AUTORELEASING = YES; 212 | CLANG_WARN_BOOL_CONVERSION = YES; 213 | CLANG_WARN_COMMA = YES; 214 | CLANG_WARN_CONSTANT_CONVERSION = YES; 215 | CLANG_WARN_DIRECT_OBJC_ISA_USAGE = YES_ERROR; 216 | CLANG_WARN_DOCUMENTATION_COMMENTS = YES; 217 | CLANG_WARN_EMPTY_BODY = YES; 218 | CLANG_WARN_ENUM_CONVERSION = YES; 219 | CLANG_WARN_INFINITE_RECURSION = YES; 220 | CLANG_WARN_INT_CONVERSION = YES; 221 | CLANG_WARN_NON_LITERAL_NULL_CONVERSION = YES; 222 | CLANG_WARN_OBJC_LITERAL_CONVERSION = YES; 223 | CLANG_WARN_OBJC_ROOT_CLASS = YES_ERROR; 224 | CLANG_WARN_RANGE_LOOP_ANALYSIS = YES; 225 | CLANG_WARN_STRICT_PROTOTYPES = YES; 226 | CLANG_WARN_SUSPICIOUS_MOVE = YES; 227 | CLANG_WARN_UNGUARDED_AVAILABILITY = YES_AGGRESSIVE; 228 | CLANG_WARN_UNREACHABLE_CODE = YES; 229 | CLANG_WARN__DUPLICATE_METHOD_MATCH = YES; 230 | CODE_SIGN_IDENTITY = "-"; 231 | COPY_PHASE_STRIP = NO; 232 | DEBUG_INFORMATION_FORMAT = "dwarf-with-dsym"; 233 | ENABLE_NS_ASSERTIONS = NO; 234 | ENABLE_STRICT_OBJC_MSGSEND = YES; 235 | GCC_C_LANGUAGE_STANDARD = gnu11; 236 | GCC_NO_COMMON_BLOCKS = YES; 237 | GCC_WARN_64_TO_32_BIT_CONVERSION = YES; 238 | GCC_WARN_ABOUT_RETURN_TYPE = YES_ERROR; 239 | GCC_WARN_UNDECLARED_SELECTOR = YES; 240 | GCC_WARN_UNINITIALIZED_AUTOS = YES_AGGRESSIVE; 241 | GCC_WARN_UNUSED_FUNCTION = YES; 242 | GCC_WARN_UNUSED_VARIABLE = YES; 243 | MACOSX_DEPLOYMENT_TARGET = 10.12; 244 | MTL_ENABLE_DEBUG_INFO = NO; 245 | SDKROOT = macosx; 246 | }; 247 | name = Release; 248 | }; 249 | E8227E151FFFECF600356B2E /* Debug */ = { 250 | isa = XCBuildConfiguration; 251 | baseConfigurationReference = E8227E1F1FFFED9200356B2E /* PGExtSwiftLib.xcconfig */; 252 | buildSettings = { 253 | CODE_SIGN_STYLE = Automatic; 254 | DYLIB_COMPATIBILITY_VERSION = 1; 255 | DYLIB_CURRENT_VERSION = 1; 256 | EXECUTABLE_PREFIX = lib; 257 | PRODUCT_NAME = "$(TARGET_NAME)"; 258 | }; 259 | name = Debug; 260 | }; 261 | E8227E161FFFECF600356B2E /* Release */ = { 262 | isa = XCBuildConfiguration; 263 | baseConfigurationReference = E8227E1F1FFFED9200356B2E /* PGExtSwiftLib.xcconfig */; 264 | buildSettings = { 265 | CODE_SIGN_STYLE = Automatic; 266 | DYLIB_COMPATIBILITY_VERSION = 1; 267 | DYLIB_CURRENT_VERSION = 1; 268 | EXECUTABLE_PREFIX = lib; 269 | PRODUCT_NAME = "$(TARGET_NAME)"; 270 | }; 271 | name = Release; 272 | }; 273 | /* End XCBuildConfiguration section */ 274 | 275 | /* Begin XCConfigurationList section */ 276 | E8227E0B1FFFECF600356B2E /* Build configuration list for PBXProject "PLSwift" */ = { 277 | isa = XCConfigurationList; 278 | buildConfigurations = ( 279 | E8227E121FFFECF600356B2E /* Debug */, 280 | E8227E131FFFECF600356B2E /* Release */, 281 | ); 282 | defaultConfigurationIsVisible = 0; 283 | defaultConfigurationName = Release; 284 | }; 285 | E8227E141FFFECF600356B2E /* Build configuration list for PBXNativeTarget "PLSwift" */ = { 286 | isa = XCConfigurationList; 287 | buildConfigurations = ( 288 | E8227E151FFFECF600356B2E /* Debug */, 289 | E8227E161FFFECF600356B2E /* Release */, 290 | ); 291 | defaultConfigurationIsVisible = 0; 292 | defaultConfigurationName = Release; 293 | }; 294 | /* End XCConfigurationList section */ 295 | }; 296 | rootObject = E8227E081FFFECF600356B2E /* Project object */; 297 | } 298 | -------------------------------------------------------------------------------- /Package.swift: -------------------------------------------------------------------------------- 1 | // swift-tools-version:4.2 2 | // 3 | // Package.swift 4 | // PL/Swift 5 | // 6 | // Created by Helge Hess on 11.05.18. 7 | // Copyright © 2019 ZeeZide. All rights reserved. 8 | // 9 | import PackageDescription 10 | 11 | let package = Package( 12 | name: "PLSwift", 13 | 14 | products: [ 15 | .library(name: "PLSwift", targets: [ "PLSwift" ]), 16 | ], 17 | 18 | dependencies: [ 19 | .package(url: "https://github.com/PL-Swift/CPLSwift.git", from: "1.0.2") 20 | ], 21 | 22 | targets: [ 23 | .target(name: "PLSwift", dependencies: [ "CPLSwift" ]) 24 | ] 25 | ) 26 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 |

PL/Swift 2 | 4 |

5 | 6 | ![PostgreSQL](https://img.shields.io/badge/postgresql-10-yellow.svg) 7 | ![Swift3](https://img.shields.io/badge/swift-3-blue.svg) 8 | ![Swift4](https://img.shields.io/badge/swift-4-blue.svg) 9 | ![Swift5](https://img.shields.io/badge/swift-5-blue.svg) 10 | ![macOS](https://img.shields.io/badge/os-macOS-green.svg?style=flat) 11 | ![tuxOS](https://img.shields.io/badge/os-tuxOS-green.svg?style=flat) 12 | 13 | 14 | **PL/Swift** allows you to write custom SQL functions and types 15 | for the 16 | [PostgreSQL](https://www.postgresql.org) database server 17 | in the 18 | [Swift](http://swift.org/) 19 | programming language. 20 | 21 |
Bringing Swift to the Backend of the Backend's Backend
22 | 23 | A small tutorial can be found over here: 24 | [PL/Swift - PostgreSQL Functions in Swift](http://www.alwaysrightinstitute.com/plswift/). 25 | 26 | ### PL/Swift 27 | 28 | Despite the name it is not (currently) a language extension like say 29 | [PL/Python](https://www.postgresql.org/docs/current/static/plpython.html), 30 | which allows you to directly embed Swift code in SQL. 31 | Instead it provides the infrastructure to create PostgreSQL 32 | dynamically loadable objects. 33 | 34 | This project/sourcedir contains the `swift-pl` tool, 35 | Xcode base configurations and module maps for the PostgreSQL server. 36 | 37 | 38 | ### What is a PL/Swift Extension 39 | 40 | A dynamically loadable PostgreSQL extension module consists of those files: 41 | 42 | - the ext.control file, specifies the name and version of the extension 43 | - the ext.sql file, hooks up the C function w/ PostgreSQL 44 | (i.e. does the `CREATE FUNCTION`) 45 | - the actual ext.so shared library 46 | 47 | 48 | ### Using the PL/Swift package 49 | 50 | *NOTE*: This *requires* a PL/Swift installation. W/o it, it will 51 | fail to built CPLSwift! 52 | 53 | If you setup a new module from scratch, use: 54 | 55 | swift pl init 56 | 57 | for example: 58 | 59 | mkdir base36 && cd base36 60 | swift pl init 61 | 62 | Otherwise setup your Package.swift to include PLSwift: 63 | 64 | ```Swift 65 | import PackageDescription 66 | 67 | let package = Package( 68 | name: "MyTool", 69 | 70 | dependencies: [ 71 | .Package(url: "git@github.com:PL-Swift/PLSwift.git", from: "0.5.0"), 72 | ] 73 | ) 74 | ``` 75 | 76 | Note: If you are using Swift older than 4.2, you need to use the `swift3` 77 | branch (`0.3.0` version tag). 78 | 79 | 80 | # Building a PL/Swift module 81 | 82 | Simply invoke 83 | 84 | swift pl build 85 | 86 | This wraps Swift Package Manager to build your package 87 | and then produces a proper module which can be loaded 88 | into PostgreSQL. 89 | 90 | To install the module into the local PostgreSQL, call: 91 | 92 | swift pl install 93 | 94 | 95 | ### Use/load the extension 96 | 97 | That is very simple, just do a: 98 | 99 | ```sql 100 | CREATE EXTENSION helloswift; 101 | ``` 102 | 103 | If you rebuild the extension and need to reload, you probably need to 104 | restart / reconnected 105 | `psql` and do a `DROP EXTENSION xyz` first. 106 | 107 | 108 | ### Status 109 | 110 | Consider this a demo. Though it should work just fine. 111 | 112 | Plans: 113 | 114 | - can we make it a real language module? i.e. embed Swift code in the 115 | SQL and compile it on demand? Why not, might be a bit heavy though. 116 | 117 | ### Links 118 | 119 | - [mod_swift](http://mod-swift.org/), write Apache2 modules in Swift 120 | - [PostgreSQL Server Programming](https://www.postgresql.org/docs/current/static/server-programming.html) 121 | - [PostgreSQL C Language Functions](https://www.postgresql.org/docs/current/static/xfunc-c.html) 122 | 123 | ### Who 124 | 125 | **PL/Swift** is brought to you by 126 | [ZeeZide](http://zeezide.de). 127 | We like feedback, GitHub stars, cool contract work, 128 | presumably any form of praise you can think of. 129 | 130 | 131 | 132 | 138 | 144 | 150 | 151 |
133 | 135 |
136 | ApacheExpress 137 |
139 | 141 |
142 | mod_swift 143 |
145 | 147 |
148 | ZeeQL 149 |
152 | -------------------------------------------------------------------------------- /Sources/PLSwift/PGDatum.swift: -------------------------------------------------------------------------------- 1 | // 2 | // PGDatum.swift 3 | // PL/Swift 4 | // 5 | // Created by Helge Hess on 05.01.18. 6 | // Copyright © 2018-2019 ZeeZide GmbH. All rights reserved. 7 | // 8 | 9 | import CPLSwift 10 | 11 | /* 12 | #define PG_RETURN_TEXT_P(x) PG_RETURN_POINTER(x) 13 | 14 | #define PG_RETURN_POINTER(x) return PointerGetDatum(x) // does a RETURN 15 | #define PointerGetDatum(X) ((Datum) (X)) // cast pointer to datum 16 | */ 17 | 18 | public func PointerGetDatum(_ ptr: UnsafeRawPointer?) -> Datum { 19 | guard let ptr = ptr else { return 0 } 20 | return Datum(bitPattern: ptr) 21 | } 22 | 23 | public let PG_RETURN_POINTER = PointerGetDatum 24 | public let PG_RETURN_TEXT_P = PG_RETURN_POINTER 25 | 26 | 27 | public extension Datum { 28 | 29 | var int64Value : Int64 { 30 | /* 31 | #define DatumGetInt32(X) ((int32) GET_4_BYTES(X)) 32 | #define GET_4_BYTES(datum) (((Datum) (datum)) & 0xffffffff) 33 | */ 34 | return Int64(bitPattern: UInt64(self)) 35 | } 36 | 37 | var intValue : Int { 38 | return Int(int64Value) 39 | } 40 | } 41 | 42 | public protocol PGDatumRepresentable { 43 | var pgDatum : Datum { get } 44 | } 45 | 46 | extension String : PGDatumRepresentable { 47 | public var pgDatum : Datum { 48 | // does this avoid the alloc? maybe. 49 | let txt = withCString { cstr in 50 | return cstring_to_text(cstr) 51 | } 52 | // cast to Datum 53 | return PG_RETURN_TEXT_P(txt) 54 | } 55 | } 56 | 57 | extension Int64 : PGDatumRepresentable { 58 | 59 | public var pgDatum : Datum { 60 | if USE_FLOAT8_BYVAL != 0 { return Datum(UInt64(bitPattern: self)) } 61 | else { fatalError("not supported") } 62 | } 63 | 64 | } 65 | 66 | extension Int : PGDatumRepresentable { 67 | 68 | public var pgDatum : Datum { 69 | // TODO: check size and distinguish between 32&64 bit 70 | return Int64(self).pgDatum 71 | } 72 | 73 | } 74 | -------------------------------------------------------------------------------- /Sources/PLSwift/PGExtension.swift: -------------------------------------------------------------------------------- 1 | // 2 | // PGExtension.swift 3 | // PL/Swift 4 | // 5 | // Created by Helge Hess on 05.01.18. 6 | // Copyright © 2018-2019 ZeeZide GmbH. All rights reserved. 7 | // 8 | 9 | import CPLSwift 10 | 11 | 12 | // MARK: - PG_MAGIC_BLOCK 13 | 14 | public let PG_MAGIC_FUNCTION_NAME_STRING = "Pg_magic_func" 15 | 16 | fileprivate var PGExtensionMagicStructValue = Pg_magic_struct( 17 | len : Int32(MemoryLayout.stride), 18 | version : PG_VERSION_NUM / 100, 19 | funcmaxargs : FUNC_MAX_ARGS, 20 | indexmaxkeys : INDEX_MAX_KEYS, 21 | namedatalen : NAMEDATALEN, 22 | float4byval : FLOAT4PASSBYVAL != 0 ? 1 : 0, 23 | float8byval : FLOAT8PASSBYVAL != 0 ? 1 : 0 24 | ) 25 | 26 | public let PGExtensionMagicStruct = 27 | UnsafeRawPointer(UnsafeMutablePointer(&PGExtensionMagicStructValue)) 28 | 29 | 30 | // MARK: - PG_FUNCTION_INFO_V1 31 | 32 | fileprivate var PG_FUNCTION_INFO_V1_value = Pg_finfo_record(api_version: 1) 33 | public let PG_FUNCTION_INFO_V1 = 34 | UnsafeRawPointer(UnsafeMutablePointer(&PG_FUNCTION_INFO_V1_value)) 35 | -------------------------------------------------------------------------------- /Sources/PLSwift/PGFunction.swift: -------------------------------------------------------------------------------- 1 | // 2 | // PGFunction.swift 3 | // PL/Swift 4 | // 5 | // Created by Helge Hess on 05.01.18. 6 | // Copyright © 2018-2019 ZeeZide GmbH. All rights reserved. 7 | // 8 | 9 | import CPLSwift 10 | 11 | public extension FunctionCallInfoData { 12 | 13 | /// Access PostgreSQL function call arguments as a Datum 14 | subscript(datum idx: Int) -> Datum? { 15 | // convert tuple to index 16 | switch idx { 17 | case 0: return arg.0 18 | case 1: return arg.1 19 | case 2: return arg.2 20 | case 3: return arg.3 21 | case 4: return arg.4 22 | case 5: return arg.5 23 | case 6: return arg.6 24 | case 7: return arg.7 25 | default: return nil 26 | } 27 | } 28 | 29 | /// Access PostgreSQL function call arguments as an Int 30 | subscript(int idx: Int) -> Int { 31 | guard let datum = self[datum: idx] else { return -42 } 32 | return datum.intValue 33 | } 34 | } 35 | -------------------------------------------------------------------------------- /configure: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | 3 | # ******************** variables **************** 4 | 5 | CFG_ARGS="$0 $1 $2 $3 $4 $5 $6 $7 $8 $9" 6 | 7 | ARG_BEQUIET=0 8 | ARG_PREFIX="" 9 | ARG_CFGMAKE="$PWD/config.make" 10 | ARG_WITH_DEBUG=1 11 | ARG_WITH_STRIP=1 12 | ARG_WITH_PGCONFIG=1 13 | ARG_PGCONFIG="NOTSET" 14 | 15 | # ******************** usage ******************** 16 | 17 | function usage() { 18 | cat <<_ACEOF 19 | \`configure' configures PL/Swift. 20 | 21 | Usage: $0 [OPTION]... 22 | 23 | Configuration: 24 | -h, --help display this help and exit 25 | -q, --quiet, --silent do not print \`checking...' messages 26 | 27 | Installation directories: 28 | --prefix=PREFIX install files in PREFIX [/usr/local] 29 | --enable-debug turn on debugging and compile time warnings 30 | --enable-strip turn on stripping of debug symbols 31 | --with-pgconfig=PATH location of pg_config [which pg_config] 32 | 33 | _ACEOF 34 | 35 | exit 0; 36 | } 37 | 38 | # ******************** running ******************** 39 | 40 | function cfgwrite() { 41 | echo "$1" >> $ARG_CFGMAKE 42 | } 43 | 44 | function genConfigMake() { 45 | if [[ $ARG_BEQUIET != 1 ]]; then 46 | echo "creating: $ARG_CFGMAKE" 47 | fi 48 | 49 | echo "# PL/Swift configuration" > $ARG_CFGMAKE 50 | cfgwrite "# created by: '$CFG_ARGS'" 51 | cfgwrite "" 52 | cfgwrite "# Note: you can override any option as a 'make' parameter, eg:" 53 | cfgwrite "# make debug=yes" 54 | cfgwrite "" 55 | 56 | if [[ $ARG_WITH_DEBUG = 1 ]]; then 57 | cfgwrite "# configured to produce debugging code"; 58 | cfgwrite "debug:=yes" 59 | else 60 | cfgwrite "# configured to produce non-debugging code"; 61 | cfgwrite "debug:=no" 62 | fi 63 | cfgwrite "" 64 | 65 | if [[ $ARG_WITH_STRIP = 1 ]]; then 66 | cfgwrite "# configured to produce stripped code"; 67 | cfgwrite "strip:=yes" 68 | else 69 | cfgwrite "# configured not to strip code"; 70 | cfgwrite "strip:=no" 71 | fi 72 | cfgwrite "" 73 | 74 | cfgwrite "# enforce shared libraries"; 75 | cfgwrite "shared:=yes" 76 | cfgwrite "" 77 | 78 | if [ -n "${ARG_PGCONFIG}" ]; then 79 | cfgwrite "PG_CONFIG:=${ARG_PGCONFIG}" 80 | cfgwrite "" 81 | fi 82 | 83 | if [ -n "$ARG_PREFIX" ]; then 84 | cfgwrite "prefix:=${ARG_PREFIX}" 85 | cfgwrite "" 86 | fi 87 | } 88 | 89 | function runIt() { 90 | if [[ "${ARG_PGCONFIG}" = "NOTSET" ]]; then 91 | ARG_PGCONFIG="`which pg_config`"; 92 | fi 93 | if [[ -z "${ARG_PGCONFIG}" ]]; then 94 | # we want to pickup from the users PATH to work "properly" within 95 | # homebrew (which patches the path) 96 | ARG_PGCONFIG="$(bash -l -c "which pg_config")" 97 | fi 98 | if [[ -z "${ARG_PGCONFIG}" ]]; then 99 | if [[ -x "/usr/local/bin/pg_config" ]]; then 100 | ARG_PGCONFIG="/usr/local/bin/pg_config" 101 | echo "Using pg_config found here: ${ARG_PGCONFIG}" 102 | elif [[ -d "/Applications/Postgres.app/Contents/Versions" ]]; then 103 | # this is a little well 104 | LATEST_VER="$(ls /Applications/Postgres.app/Contents/Versions | sort -r | head -n 1)" 105 | if [[ -x "/Applications/Postgres.app/Contents/Versions/${LATEST_VER}/bin/pg_config" ]]; then 106 | ARG_PGCONFIG="/Applications/Postgres.app/Contents/Versions/${LATEST_VER}/bin/pg_config" 107 | echo "Using pg_config from PostgreSQL.app: ${ARG_PGCONFIG}" 108 | fi 109 | fi 110 | fi 111 | 112 | if [ -z "$ARG_PREFIX" ]; then 113 | ARG_PREFIX=/usr/local 114 | fi 115 | 116 | if [[ ! -x "${ARG_PGCONFIG}" ]]; then 117 | echo >&2 "Could not locate pg_config! ${ARG_PGCONFIG}" 118 | exit 42; 119 | fi 120 | 121 | genConfigMake; 122 | } 123 | 124 | # ******************** options ******************** 125 | 126 | function extractFuncValue() { 127 | VALUE="`echo "$1" | sed "s/[^=]*=//g"`" 128 | } 129 | 130 | function processOption() { 131 | case "x$1" in 132 | "x--help"|"x-h") 133 | usage; 134 | ;; 135 | "x--quiet"|"x--silent"|"x-q") ARG_BEQUIET=1; ;; 136 | x--prefix=*) 137 | extractFuncValue $1; 138 | ARG_PREFIX="$VALUE"; 139 | ;; 140 | x--with-pgconfig=*) 141 | extractFuncValue $1; 142 | ARG_PGCONFIG="$VALUE"; 143 | ;; 144 | "x--with-pgconfig") 145 | ARG_PGCONFIG="`which pg_config`"; 146 | ;; 147 | "x--without-pgconfig") 148 | ARG_PGCONFIG=""; 149 | ;; 150 | "x--enable-debug") 151 | ARG_WITH_DEBUG=1 152 | ;; 153 | "x--disable-debug") 154 | ARG_WITH_DEBUG=0 155 | ;; 156 | "x--enable-strip") 157 | ARG_WITH_STRIP=1 158 | ;; 159 | "x--disable-strip") 160 | ARG_WITH_STRIP=0 161 | ;; 162 | 163 | *) echo "error: cannot process argument: $1"; exit 1; ;; 164 | esac 165 | } 166 | 167 | for i in $@; do 168 | processOption $i; 169 | done 170 | 171 | runIt 172 | -------------------------------------------------------------------------------- /shims/PLSwiftShim.h: -------------------------------------------------------------------------------- 1 | #ifndef __PLSwiftShim_H__ 2 | #define __PLSwiftShim_H__ 3 | 4 | #include "postgres.h" 5 | 6 | // for PG_GETARG_XXX, PG_RETURN_XXX 7 | // also: PG_MODULE_MAGIC 8 | #include "fmgr.h" 9 | 10 | // for cstring_to_text 11 | #include "utils/builtins.h" 12 | 13 | #endif /* __PLSwiftShim_H__ */ 14 | -------------------------------------------------------------------------------- /swift-pl/swift-pl: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | # 3 | # swift-pl -- A SwiftPM extension to deal with building 4 | # PostgreSQL loadable modules. 5 | # 6 | # Copyright 2017 ZeeZide GmbH. All rights reserved. 7 | # 8 | 9 | if [ "$DEBUG" = "yes" ]; then 10 | set -x 11 | fi 12 | 13 | export SWIFT_PL_DIR=$(dirname "$0") 14 | 15 | usage() { 16 | echo "usage: swift pl " 17 | echo 18 | echo "Available subcommands are:" 19 | echo " init Setup directory as a Swift PostgreSQL Package." 20 | echo " build Build Swift Package as a PostgreSQL loadable module." 21 | echo " install Install module into PostgreSQL server." 22 | echo " validate Check PostgreSQL build environment." 23 | echo 24 | echo "Try 'swift pl help' for details." 25 | } 26 | 27 | main() { 28 | if [ $# -lt 1 ]; then 29 | usage 30 | exit 1 31 | fi 32 | 33 | # sanity checks 34 | SUBCOMMAND="$1"; shift 35 | 36 | if [[ -x "${SWIFT_PL_DIR}/swift-pl-$SUBCOMMAND" ]]; then 37 | RUNCMD="${SWIFT_PL_DIR}/swift-pl-$SUBCOMMAND" 38 | else 39 | THECMD="`ls ${SWIFT_PL_DIR}/swift-pl-${SUBCOMMAND}* | head -n 1`" 40 | if [[ -x "${THECMD}" ]]; then 41 | RUNCMD="${THECMD}" 42 | else 43 | echo "Unknown subcommand: '$SUBCOMMAND'" 44 | echo 45 | usage 46 | exit 1 47 | fi 48 | fi 49 | 50 | # run command 51 | . "${RUNCMD}" 52 | } 53 | 54 | main "$@" 55 | -------------------------------------------------------------------------------- /swift-pl/swift-pl-build: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | # 3 | # swift-pl -- A SwiftPM extension to deal with building 4 | # PostgreSQL loadable modules 5 | # 6 | # Copyright 2017 ZeeZide GmbH. All rights reserved. 7 | # 8 | 9 | ARGS="$@" 10 | 11 | 12 | # check whether environment is sound, also parse some args 13 | 14 | EMBEDDED_VALIDATE=yes . swift-pl-validate 15 | rc=$?; if [ $rc -ne 0 ]; then exit $rc; fi 16 | 17 | 18 | # TODO: debug vs non-debug 19 | # TODO: derive platform and such 20 | # TODO: select targets using json output 21 | # swift package show-dependencies --format=json 22 | 23 | # TODO: Flags of swift build we want to support: 24 | # -c debug|release [debug] 25 | # --clean build|dist [build] - we need to rm the .so/.so.dSYM 26 | # --color auto|always|never [auto] 27 | # -v or --verbose 28 | 29 | 30 | # usage 31 | 32 | usage() { 33 | echo "usage: swift pl build [mode] [options]" 34 | echo 35 | echo "Modes:" 36 | echo " -c, --configuration debug|release [default: debug]" 37 | echo " --clean build|dist [default: build]" 38 | echo 39 | echo "Options:" 40 | echo " --color auto|always|never [default: auto]" 41 | echo " -v, --verbose" 42 | } 43 | 44 | if [[ "$ARGS" == *"--help"* ]]; then 45 | usage 46 | exit 0 47 | fi 48 | 49 | 50 | # check whether we are in clean mode 51 | 52 | if [[ "$ARGS" == *"--clean"* ]]; then 53 | if [[ "$ARGS" == *"--clean dist"* ]]; then 54 | CLEAN_MODE=dist 55 | elif [[ "$ARGS" == *"--clean build"* ]]; then 56 | CLEAN_MODE=build 57 | else 58 | CLEAN_MODE=build 59 | fi 60 | fi 61 | 62 | if [ -n "${CLEAN_MODE}" ]; then 63 | # invoke SPM clean 64 | if [[ ${SWIFT_MAJOR} -gt 3 || ${SWIFT_MINOR} -gt 0 ]]; then 65 | SWIFT_CLEAN="swift package clean" 66 | else 67 | SWIFT_CLEAN="swift build --clean ${CLEAN_MODE}" 68 | fi 69 | 70 | ${SWIFT_CLEAN} # $ARGS - needs cleanup 71 | rc=$?; if [ $rc -ne 0 ]; then exit $rc; fi 72 | 73 | rm -rf "${BUILD_PRODUCT}" "${BUILD_PRODUCT}.dSYM" 74 | exit 0 75 | fi 76 | 77 | 78 | # invoke SPM build 79 | 80 | swift build $@ 81 | rc=$?; if [ $rc -ne 0 ]; then exit $rc; fi 82 | 83 | 84 | # do our work: config 85 | 86 | if ! test "xBUILD_CONFIG" = "xrelease"; then 87 | CFLAGS="${CFLAGS} -g" 88 | fi 89 | 90 | 91 | 92 | # platform stuff 93 | 94 | if [[ "${UNAME_S}" = "Darwin" ]]; then 95 | SWIFTC=`xcrun --toolchain swift-latest -f swiftc` 96 | 97 | # required on macOS 10.11 w/ Xcode 8.2.1 (else Swift does 10.9?) 98 | TARGET_VERSION="10.10" 99 | DEPLOYMENT_TARGET="x86_64-apple-macosx${TARGET_VERSION}" 100 | if [ -n "${DEPLOYMENT_TARGET}" ]; then 101 | PLATFORM_FLAGS="${PLATFORM_FLAGS} -target ${DEPLOYMENT_TARGET}" 102 | fi 103 | 104 | SDK="`xcrun -sdk macosx --show-sdk-path`" 105 | if [ -n "${SDK}" ]; then 106 | PLATFORM_FLAGS="${PLATFORM_FLAGS} -sdk $SDK" 107 | fi 108 | 109 | PLATFORM_FLAGS="${PLATFORM_FLAGS} -Xlinker -undefined -Xlinker dynamic_lookup" 110 | 111 | # TBD: 112 | # -rpath $(TOOLCHAIN_DIR)/usr/lib/swift/macosx -rpath $(MODSWIFT_TARGET_DIR) 113 | # TBD: -lswiftFoundation -lswiftDarwin -lswiftCore 114 | else 115 | SWIFTC="$(which swiftc)" 116 | fi 117 | 118 | 119 | # Invoke Swift to link the shared object 120 | 121 | FILES_TO_LINK="`find ${CONFIGURATION_BUILD_DIR}/ -name *.o`" 122 | 123 | ${SWIFTC} \ 124 | -emit-library \ 125 | -emit-module -module-name "${MODULE_NAME}" \ 126 | $PLATFORM_FLAGS \ 127 | $CFLAGS \ 128 | -L${CONFIGURATION_BUILD_DIR} \ 129 | `pkg-config --libs plswift` \ 130 | -o "${BUILD_PRODUCT}" \ 131 | ${FILES_TO_LINK} 132 | -------------------------------------------------------------------------------- /swift-pl/swift-pl-clean: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | # 3 | # swift-pl -- A SwiftPM extension to deal with building 4 | # PostgreSQL loadable modules 5 | # 6 | # Copyright 2017 ZeeZide GmbH. All rights reserved. 7 | # 8 | 9 | # `swift pl clean` is just here to mirror the `swift package clean` 10 | # introduced in Swift 3.1 (which deprecated `swift build --clean`) 11 | 12 | # TBD: not sure what flags `swift package clean` supports, the --help doesn't 13 | # say anything :-) 14 | swift-pl-build --clean $@ 15 | -------------------------------------------------------------------------------- /swift-pl/swift-pl-init: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | # 3 | # swift-pl -- A SwiftPM extension to deal with building 4 | # PostgreSQL loadable modules 5 | # 6 | # Copyright 2017 ZeeZide GmbH. All rights reserved. 7 | # 8 | 9 | ARGS="$@" 10 | 11 | EMBEDDED_VALIDATE=yes . swift-pl-validate 12 | rc=$?; if [ $rc -ne 0 ]; then exit $rc; fi 13 | 14 | PACKAGE_VERSION="0.0.1" 15 | 16 | # templates 17 | 18 | if [[ ${SWIFT_MAJOR} -gt 4 || ${SWIFT_MINOR} -gt 2 ]]; then 19 | read -r -d '' PACKAGE_TEMPLATE < String { 83 | return "Hello Schwifty World!" 84 | } 85 | EOF 86 | 87 | 88 | # TBD: can we create this from the Swift sources prior calling `swift pl build` 89 | read -r -d '' SWIFT_BOILERPLATE_FILE < Datum\` 104 | * - add a mandatory ABI function (just returns PG_FUNCTION_INFO_V1) 105 | * - load the function in the %MODULE_NAME%.sql file 106 | * 107 | * The functions need proper "C names", so that PostgreSQL can find them. The 108 | * names are assigned using the \`@_cdecl\` attribute. 109 | */ 110 | 111 | @_cdecl("pg_finfo_%MODULE_NAME%_hello") 112 | public func hello_abi() -> UnsafeRawPointer { 113 | return PG_FUNCTION_INFO_V1 114 | } 115 | 116 | @_cdecl("%MODULE_NAME%_hello") 117 | public func hello(fcinfo: FunctionCallInfo) -> Datum { 118 | return hello().pgDatum 119 | } 120 | 121 | // MARK: - PostgreSQL Extension Marker 122 | 123 | @_cdecl("Pg_magic_func") public func PG_MAGIC_BLOCK() -> UnsafeRawPointer { 124 | return PGExtensionMagicStruct 125 | } 126 | EOF 127 | 128 | read -r -d '' GIT_IGNORE < .gitignore 155 | fi 156 | 157 | if ! test -d Sources/${MODULE_NAME}; then 158 | mkdir -p Sources/${MODULE_NAME} 159 | echo "${SWIFT_SOURCE_FILE}" \ 160 | | sed "s#%MODULE_NAME%#${MODULE_NAME}#g" \ 161 | > "Sources/${MODULE_NAME}/${MODULE_NAME}.swift" 162 | echo "${SWIFT_BOILERPLATE_FILE}" \ 163 | | sed "s#%MODULE_NAME%#${MODULE_NAME}#g" \ 164 | > "Sources/${MODULE_NAME}/${MODULE_NAME}-ext.swift" 165 | else 166 | echo "Sources already setup, not generating." 167 | fi 168 | 169 | if ! test -f Package.swift; then 170 | echo "${PACKAGE_TEMPLATE}" \ 171 | | sed "s#%MODULE_NAME%#${MODULE_NAME}#g" \ 172 | > "Package.swift" 173 | fi 174 | 175 | if ! test -f "${MODULE_NAME}.control"; then 176 | echo "${EXTENSION_CONTROL_FILE}" \ 177 | | sed "s#%MODULE_NAME%#${MODULE_NAME}#g" \ 178 | > "${MODULE_NAME}.control" 179 | fi 180 | if ! test -f "${MODULE_NAME}--${PACKAGE_VERSION}.sql"; then 181 | # Note: the `--` seems to be right/required. 182 | echo "${EXTENSION_LOAD_FILE}" \ 183 | | sed "s#%MODULE_NAME%#${MODULE_NAME}#g" \ 184 | > "${MODULE_NAME}--${PACKAGE_VERSION}.sql" 185 | fi 186 | 187 | 188 | # debug 189 | 190 | echo "The Swift PostgreSQL build environment looks sound." 191 | echo 192 | echo " module: ${MODULE_NAME}" 193 | echo " config: ${CONFIGURATION}" 194 | echo " product: ${BUILD_PRODUCT}" 195 | echo " pg_config: $(which pg_config)" 196 | echo " PL/Swift: ${PL_SWIFT_PREFIX}" 197 | echo 198 | -------------------------------------------------------------------------------- /swift-pl/swift-pl-install: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | # 3 | # swift-pl -- A SwiftPM extension to deal with building 4 | # PostgreSQL loadable modules 5 | # 6 | # Copyright 2017 ZeeZide GmbH. All rights reserved. 7 | # 8 | 9 | ARGS="$@" 10 | 11 | EMBEDDED_VALIDATE=yes . swift-pl-validate 12 | 13 | 14 | # check whether the module has been built, otherwise call build 15 | # TBD: Always rebuild? 16 | 17 | if ! test -x "${BUILD_PRODUCT}"; then 18 | # FIXME: only pass over build flags (just -c/--configuration?) 19 | if [[ "x$CONFIGURATION" = "xrelease" ]]; then 20 | swift pl build -c release 21 | else 22 | swift pl build -c debug 23 | fi 24 | rc=$?; if [ $rc -ne 0 ]; then exit $rc; fi 25 | fi 26 | 27 | if ! test -x "${BUILD_PRODUCT}"; then 28 | echo 1>&2 "ERROR: can't find built product: ${BUILD_PRODUCT}" 29 | exit 10 30 | fi 31 | 32 | 33 | if [[ ! -f "${PG_CONTROL_FILE}" ]]; then 34 | echo 1>&2 "ERROR: Missing extension control file: ${PG_CONTROL_FILE}" 35 | exit 22 36 | fi 37 | if [[ ! -f "${PG_SETUP_FILE}" ]]; then 38 | echo 1>&2 "ERROR: Missing setup file: ${PG_SETUP_FILE}" 39 | exit 23 40 | fi 41 | 42 | 43 | cp "${BUILD_PRODUCT}" "${PG_MODULE_DIR}/" 44 | cp "${PG_CONTROL_FILE}" "${PG_EXTENSION_DIR}" 45 | cp "${PG_SETUP_FILE}" "${PG_EXTENSION_DIR}" 46 | -------------------------------------------------------------------------------- /swift-pl/swift-pl-validate: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | # 3 | # swift-pl -- A SwiftPM extension to deal with building 4 | # PostgreSQL loadable modules 5 | # 6 | # Copyright 2017 ZeeZide GmbH. All rights reserved. 7 | # 8 | 9 | if [[ "x${SWIFT_PL_VALIDATED}" = "x" ]]; then 10 | SWIFT_PL_VALIDATED=yes 11 | 12 | # Check whether environment is sound. Also: setup common variables. 13 | # 14 | # Variables set: 15 | # UNAME_S 16 | # SRCROOT - if not set, $PWD 17 | # MODULE_NAME - e.g. mods_expressdemo 18 | # BUILD_MAIN - e.g. ".build" 19 | # BUILD_ROOT - e.g. ".build/debug" (TODO: diff to Xcode) 20 | # BUILD_CONFIG - release or debug 21 | # BUILD_PRODUCT - e.g. ".build/pgdemo.so" 22 | # SPM_BUILD_CONFIG - like CONFIGURATION, but always lowercase 23 | # SWIFT_VERSION - as emitted, e.g. 3.0.2 or 3.1 24 | # SWIFT_MAJOR - 3 25 | # SWIFT_MINOR - 1 26 | # SWIFT_SUBMINOR_OPT - empty or subminor if given (e.g. "" for 3.1) 27 | # SWIFT_SUBMINOR - subminor if given, else 0 (e.g. 0 for 3.1) 28 | # SWIFT_TOOLS_VERSION - 4.2 29 | # PG_MODULE_DIR - where the binary needs to be installed 30 | # PG_EXTENSION_DIR - where the SQL extensions are installed 31 | # PL_SWIFT_PREFIX - where PL/Swift is installed, e.g. /usr/local 32 | # PG_CONTROL_FILE - the control file of the ext (manifest) 33 | # EXTENSION_VERSION - version of the extension, e.g. 0.0.1 34 | # PG_SETUP_FILE - the SQL setup file of the ext 35 | # Also set if not set (as part of Xcode name migration) 36 | # CONFIGURATION 37 | # TARGET_NAME 38 | # CONFIGURATION_BUILD_DIR 39 | # FULL_PRODUCT_NAME 40 | # BUILT_PRODUCTS_DIR 41 | # 42 | # TODO: rework to match Xcode names 43 | # - BUILD_MAIN => BUILD_ROOT 44 | # - BUILD_ROOT => CONFIGURATION_BUILD_DIR 45 | 46 | UNAME_S="`uname -s`" 47 | 48 | if [[ "x${SRCROOT}" = "x" ]]; then 49 | SRCROOT="${PWD}" 50 | fi 51 | 52 | if ! hash pg_config 2>/dev/null; then 53 | if [[ "${UNAME_S}" = "Darwin" ]]; then 54 | echo 1>&2 "ERROR: Missing PostgreSQL pg_config." 55 | else 56 | echo 1>&2 "ERROR: Missing PostgreSQL pg_config, did you?:" 57 | echo 1>&2 58 | echo 1>&2 " apt-get install postgresql-server-dev ?" 59 | echo 1>&2 60 | fi 61 | exit 1 62 | fi 63 | 64 | # FIXME: all this is a little lame 65 | P="\${exec_prefix}" # a pattern as part of the path 66 | PG_MODULE_DIR="$(pg_config --pkglibdir)" 67 | PG_EXTENSION_DIR="$(pg_config --sharedir)/extension/" 68 | 69 | # check where the script lives, and then whether it has a module laying 70 | # beside it. Note: /usr/local w/ brew has no libexec! 71 | PL_SWIFT_PREFIX="$(dirname $(dirname "${BASH_SOURCE}"))" 72 | 73 | 74 | # detect module name 75 | 76 | if [[ "x${TARGET_NAME}" = "x" ]]; then 77 | TARGET_NAME="`basename $PWD | tr "-" "_"`" 78 | fi 79 | if [[ "x${PRODUCT_NAME}" = "x" ]]; then 80 | # TBD: is this correct? does it include an extension or sth? 81 | PRODUCT_NAME="${TARGET_NAME}" 82 | fi 83 | if [[ "x${MODULE_NAME}" = "x" ]]; then 84 | MODULE_NAME="${TARGET_NAME}" # TBD: use PRODUCT_NAME 85 | fi 86 | 87 | 88 | # Swift version 89 | 90 | SWIFT_VERSION="`swift --version | head -1 | sed 's/^.*[Vv]ersion[\t ]*\([.[:digit:]]*\).*$/\1/g'`" 91 | declare -a SWIFT_VERSION_LIST="(${SWIFT_VERSION//./ })" 92 | SWIFT_MAJOR=${SWIFT_VERSION_LIST[0]} 93 | SWIFT_MINOR=${SWIFT_VERSION_LIST[1]} 94 | SWIFT_SUBMINOR_OPT=${SWIFT_VERSION_LIST[2]} 95 | SWIFT_SUBMINOR=${SWIFT_SUBMINOR_OPT} 96 | if [[ "x${SWIFT_SUBMINOR}" = "x" ]]; then SWIFT_SUBMINOR=0; fi 97 | 98 | SWIFT_TOOLS_VERSION="${SWIFT_MAJOR}.${SWIFT_MINOR}" 99 | 100 | # do our work: parse arguments 101 | # this is a little lame, because we require a single space ... 102 | 103 | if [[ "$ARGS" == *"-c release"* ]]; then 104 | CONFIGURATION="release" 105 | elif [[ "$ARGS" == *"-configuration release"* ]]; then 106 | CONFIGURATION="release" 107 | elif [[ "x${CONFIGURATION}" = "x" ]]; then 108 | CONFIGURATION="debug" 109 | fi 110 | BUILD_CONFIG="${CONFIGURATION}" 111 | SPM_BUILD_CONFIG="`echo ${CONFIGURATION} | tr '[:upper:]' '[:lower:]'`" 112 | 113 | # TODO: different naming to Xcode, we override BUILD_ROOT below 114 | if [[ "x${BUILD_ROOT}" = "x" ]]; then 115 | BUILD_MAIN=${PWD}/.build 116 | else 117 | BUILD_MAIN="${BUILD_ROOT}" 118 | fi 119 | 120 | if [[ "x${CONFIGURATION_BUILD_DIR}" = "x" ]]; then 121 | CONFIGURATION_BUILD_DIR="${BUILD_MAIN}/${BUILD_CONFIG}" 122 | fi 123 | BUILD_ROOT="${CONFIGURATION_BUILD_DIR}" 124 | 125 | if [[ "x${BUILT_PRODUCTS_DIR}" = "x" ]]; then 126 | # Yes, we do not but this in the BUILD_CONFIG. TBD. Makes config easier. 127 | # hh: config is now usually generated 128 | BUILT_PRODUCTS_DIR="${BUILD_MAIN}" 129 | fi 130 | if [[ "x${FULL_PRODUCT_NAME}" = "x" ]]; then 131 | FULL_PRODUCT_NAME="${MODULE_NAME}.so" 132 | fi 133 | BUILD_PRODUCT="${BUILT_PRODUCTS_DIR}/${FULL_PRODUCT_NAME}" 134 | 135 | 136 | PG_CONTROL_FILE="${MODULE_NAME}.control" 137 | 138 | if [[ -f "${PG_CONTROL_FILE}" ]]; then 139 | EXTENSION_VERSION="$(grep default_version "${PG_CONTROL_FILE}" | head -n 1 | sed "s#default_version[ ]*[=][ ]'\([0-9.]*\)'*#\\1#g")" 140 | if [[ "x${EXTENSION_VERSION}" != "x" ]]; then 141 | PG_SETUP_FILE="${MODULE_NAME}--${EXTENSION_VERSION}.sql" 142 | fi 143 | fi 144 | 145 | # Output configuration 146 | 147 | if ! [[ "x${EMBEDDED_VALIDATE}" = "xyes" ]]; then 148 | echo "The Swift PostgreSQL build environment looks sound." 149 | echo 150 | echo " srcroot: ${SRCROOT}" 151 | echo " module: ${MODULE_NAME}" 152 | echo " config: ${BUILD_CONFIG}" 153 | echo " product: ${BUILD_PRODUCT}" 154 | echo " version: ${EXTENSION_VERSION}" 155 | echo " sql-setup: ${PG_SETUP_FILE}" 156 | echo " pg_config: $(which pg_config)" 157 | echo " moddir: ${PG_MODULE_DIR}" 158 | echo " extdir: ${PG_EXTENSION_DIR}" 159 | echo " PL/Swift: ${PL_SWIFT_PREFIX}" 160 | echo " swift: ${SWIFT_MAJOR}.${SWIFT_MINOR}.${SWIFT_SUBMINOR}" 161 | echo " tools: ${SWIFT_TOOLS_VERSION}" 162 | echo 163 | 164 | if [[ ! -f "${PG_CONTROL_FILE}" ]]; then 165 | echo 1>&2 "ERROR: Missing extension control file: ${PG_CONTROL_FILE}" 166 | fi 167 | if [[ ! -f "${PG_SETUP_FILE}" ]]; then 168 | echo 1>&2 "ERROR: Missing setup file: ${PG_SETUP_FILE}" 169 | fi 170 | fi 171 | 172 | fi # SWIFT_PL_VALIDATED 173 | -------------------------------------------------------------------------------- /xcconfig/PGExtSwiftLib.xcconfig: -------------------------------------------------------------------------------- 1 | // 2 | // Copyright (C) 2018 ZeeZide GmbH, All Rights Reserved 3 | // Created by Helge Hess on 2018-01-05. 4 | // 5 | 6 | #include "/usr/local/lib/xcconfig/plswift.xcconfig" 7 | 8 | // Reuse the xcconfig intended for modules. Just override the stuff we need 9 | // to be different. 10 | DYLIB_INSTALL_NAME_BASE = /usr/local/lib/ 11 | EXECUTABLE_EXTENSION = dylib 12 | EXECUTABLE_PREFIX = lib 13 | 14 | // SWIFT_VERSION = 4.0 15 | SWIFT_VERSION = 3.0 16 | -------------------------------------------------------------------------------- /xcconfig/config.make: -------------------------------------------------------------------------------- 1 | # GNUmakefile 2 | 3 | # Common configurations 4 | 5 | ifeq ($(prefix),) 6 | prefix=/usr/local 7 | endif 8 | 9 | SHARED_LIBRARY_PREFIX=lib 10 | 11 | MKDIR_P = mkdir -p 12 | INSTALL_FILE = cp 13 | 14 | UNAME_S := $(shell uname -s) 15 | 16 | # Apache stuff 17 | 18 | ifeq ($(PG_CONFIG),) 19 | PG_CONFIG=$(shell which pg_config) 20 | endif 21 | ifneq ($(PG_CONFIG),) 22 | HAVE_PG_CONFIG=yes 23 | else 24 | HAVE_PG_CONFIG=no 25 | endif 26 | USE_PG_CONFIG=$(HAVE_PG_CONFIG) 27 | 28 | ifeq ($(HAVE_PG_CONFIG),yes) 29 | PG_CONFIG_EXTRA_CFLAGS= 30 | PG_CONFIG_EXTRA_LDFLAGS= 31 | endif 32 | 33 | 34 | # System specific configuration 35 | 36 | USE_BREW=no 37 | 38 | ifeq ($(UNAME_S),Darwin) 39 | SHARED_LIBRARY_SUFFIX=.dylib 40 | PG_MODULE_SUFFIX:=.so # yes 41 | INSTALL_FILE = cp -X 42 | 43 | ifeq ($(USE_PG_CONFIG),yes) 44 | PG_CONFIG_EXTRA_CFLAGS += -Wno-nullability-completeness 45 | 46 | ifneq ($(brew),no) 47 | ifeq ($(BREW),) 48 | BREW=$(shell which brew) 49 | endif 50 | ifneq (,$(BREW)) # use Homebrew locations 51 | USE_BREW=yes 52 | endif 53 | endif 54 | endif 55 | 56 | ifeq ($(prefix),) 57 | prefix = /usr/local # TBD 58 | endif 59 | else # Linux 60 | # e.g.: OS=ubuntu VER=14.04 61 | # OS=$(shell lsb_release -si | tr A-Z a-z) 62 | # VER=$(shell lsb_release -sr) 63 | 64 | SHARED_LIBRARY_SUFFIX=.so 65 | endif 66 | 67 | ifeq ($(PG_MODULE_SUFFIX),) 68 | PG_MODULE_SUFFIX:=$(SHARED_LIBRARY_SUFFIX) 69 | endif 70 | 71 | 72 | # Debug or Release? 73 | 74 | ifeq ($(debug),on) 75 | PG_CONFIG_EXTRA_CFLAGS += -g 76 | PG_CONFIG_EXTRA_LDFLAGS += -g 77 | endif 78 | 79 | 80 | # APR and APU configs 81 | 82 | ifeq ($(USE_PG_CONFIG),yes) 83 | PKGCONFIG_LDFLAGS += 84 | PKGCONFIG_LIB_DIRS += 85 | endif 86 | 87 | 88 | # We have set prefix above, or we got it via ./config.make 89 | # Now we need to derive: 90 | # - BINARY_INSTALL_DIR e.g. /usr/local/bin 91 | # - HEADER_FILES_INSTALL_DIR e.g. /usr/local/include 92 | # - PKGCONFIG_INSTALL_DIR e.g. /usr/local/lib/pkgconfig 93 | # - XCCONFIG_INSTALL_DIR e.g. /usr/local/lib/xcconfig 94 | # - MODMAP_INSTALL_DIR e.g. /usr/local/lib/modmap 95 | # - SWIFT_SHIM_INSTALL_DIR e.g. /usr/local/lib/swift/shims 96 | 97 | ifeq ($(BINARY_INSTALL_DIR),) 98 | BINARY_INSTALL_DIR=$(prefix)/bin 99 | endif 100 | 101 | ifeq ($(HEADER_FILES_INSTALL_DIR),) 102 | HEADER_FILES_INSTALL_DIR=$(prefix)/include 103 | endif 104 | ifeq ($(PKGCONFIG_INSTALL_DIR),) 105 | # on Trusty most live in lib/x86_64-linux-gnu/pkgconfig. TBD 106 | PKGCONFIG_INSTALL_DIR=$(prefix)/lib/pkgconfig 107 | endif 108 | 109 | ifeq ($(XCCONFIG_INSTALL_DIR),) 110 | XCCONFIG_INSTALL_DIR=$(prefix)/lib/xcconfig 111 | endif 112 | ifeq ($(MODMAP_INSTALL_DIR),) 113 | MODMAP_INSTALL_DIR=$(prefix)/lib/modmap 114 | endif 115 | 116 | ifeq ($(SWIFT_SHIM_INSTALL_DIR),) 117 | SWIFT_SHIM_INSTALL_DIR=$(prefix)/lib/swift/shims 118 | endif 119 | -------------------------------------------------------------------------------- /xcconfig/rules-pgconfig.make: -------------------------------------------------------------------------------- 1 | # GNUmakefile 2 | 3 | 4 | ifeq ($(USE_PG_CONFIG),no) 5 | ifeq ($(UNAME_S),Darwin) 6 | $(error missing pg_config) 7 | else 8 | $(error missing pg_config, did you install postgresql-server-dev?) 9 | endif 10 | endif 11 | 12 | 13 | PG_CONFIG_INCLUDE_DIRS = \ 14 | $(shell $(PG_CONFIG) --includedir-server) \ 15 | $(shell $(PG_CONFIG) --pkgincludedir)/internal \ 16 | $(patsubst -I%,%,$(filter -I%,$(shell $(PG_CONFIG) --cppflags))) 17 | 18 | FILTEROUT_PG_CONFIG_LDFLAGS = \ 19 | -L../../src/common \ 20 | -L../../../src/common 21 | 22 | PG_CONFIG_LDFLAGS = \ 23 | $(filter-out $(FILTEROUT_PG_CONFIG_LDFLAGS),$(shell $(PG_CONFIG) --ldflags)) 24 | 25 | #RUNTIME_LIBS=-lswiftFoundation -lswiftDarwin -lswiftCore 26 | RUNTIME_LIBS= 27 | 28 | 29 | HELPER_BUILD_DIR = .build 30 | 31 | PACKAGE_PKGCONFIG = $(HELPER_BUILD_DIR)/$(PACKAGE).pc 32 | PACKAGE_XCCONFIG = $(HELPER_BUILD_DIR)/$(PACKAGE).xcconfig 33 | PACKAGE_MODMAP = $(HELPER_BUILD_DIR)/module.map 34 | PACKAGE_HELPERS = $(PACKAGE_PKGCONFIG) $(PACKAGE_XCCONFIG) $(PACKAGE_MODMAP) 35 | 36 | PACKAGE_MODMAP_INSTALL_DIR = $(MODMAP_INSTALL_DIR)/$(PACKAGE)/ 37 | 38 | HEADER_FILES_INSTALL_PATHES = $(addprefix $(HEADER_FILES_INSTALL_DIR)/,$(HFILES)) 39 | SHIM_FILES_INSTALL_PATHES = $(addprefix $(SWIFT_SHIM_INSTALL_DIR)/,$(notdir $(SWIFT_SHIM_FILES))) 40 | 41 | all : package-helpers 42 | 43 | package-helper-build-dir : 44 | $(MKDIR_P) $(HELPER_BUILD_DIR) 45 | 46 | package-helpers : package-helper-build-dir $(PACKAGE_HELPERS) 47 | 48 | clean : 49 | rm -f $(PACKAGE_HELPERS) 50 | 51 | distclean : clean 52 | rm -rf $(HELPER_BUILD_DIR) 53 | rm -f config.make 54 | 55 | install : all 56 | $(MKDIR_P) $(PKGCONFIG_INSTALL_DIR) \ 57 | $(SWIFT_SHIM_INSTALL_DIR) \ 58 | $(BINARY_INSTALL_DIR) 59 | $(INSTALL_FILE) $(SWIFT_SHIM_FILES) $(SWIFT_SHIM_INSTALL_DIR)/ 60 | $(INSTALL_FILE) $(PACKAGE_PKGCONFIG) $(PKGCONFIG_INSTALL_DIR)/ 61 | if test "$(UNAME_S)" = "Darwin"; then \ 62 | $(MKDIR_P) $(XCCONFIG_INSTALL_DIR) $(PACKAGE_MODMAP_INSTALL_DIR); \ 63 | $(INSTALL_FILE) $(PACKAGE_XCCONFIG) $(XCCONFIG_INSTALL_DIR)/; \ 64 | $(INSTALL_FILE) $(PACKAGE_MODMAP) $(PACKAGE_MODMAP_INSTALL_DIR)/; \ 65 | fi; 66 | $(INSTALL_FILE) $(SCRIPTS) $(BINARY_INSTALL_DIR)/ 67 | 68 | uninstall : 69 | rm -f $(SHIM_FILES_INSTALL_PATHES) \ 70 | $(PKGCONFIG_INSTALL_DIR)/$(PACKAGE).pc \ 71 | $(XCCONFIG_INSTALL_DIR)/$(PACKAGE).xcconfig \ 72 | $(PACKAGE_MODMAP_INSTALL_DIR)/module.map \ 73 | $(addprefix $(BINARY_INSTALL_DIR)/,$(notdir $(SCRIPTS))) \ 74 | 75 | 76 | # config test 77 | 78 | testconfig: 79 | @echo "Brew: $(BREW)" 80 | @echo "Use brew: $(USE_BREW)" 81 | @echo "pg_config: $(PG_CONFIG)" 82 | @echo "Prefix: $(prefix)" 83 | @echo "Install module in: $(APACHE_MODULE_INSTALL_DIR)" 84 | @echo "Install headers in: $(HEADER_FILES_INSTALL_DIR)" 85 | @echo "Install pc in: $(PKGCONFIG_INSTALL_DIR)" 86 | 87 | #testconfig-swift-docker: 88 | # docker run --rm -v $(PWD):/src helje5/swift-pl-dev bash -c "cd /src; make testconfig" 89 | 90 | 91 | # pkg config 92 | 93 | PACKAGE_VERSION_STRING=$(MAJOR).$(MINOR).$(SUBMINOR) 94 | 95 | PKGCONFIG_CFLAGS = \ 96 | "-I\$${includedir}" \ 97 | "-I\$${libdir}/swift/shims" \ 98 | $(addprefix -I,$(PG_CONFIG_INCLUDE_DIRS)) 99 | 100 | PKGCONFIG_LDFLAGS_NO_LIBS = 101 | 102 | # Also: libs. Not served by apxs which doesn't need libs, but we might still 103 | #. want to do those for apr/apu apps? 104 | $(PACKAGE_PKGCONFIG) : $(wildcard config.make) 105 | @echo "prefix=$(prefix)" > "$(PACKAGE_PKGCONFIG)" 106 | @echo "includedir=$(HEADER_FILES_INSTALL_DIR)" >> "$(PACKAGE_PKGCONFIG)" 107 | @echo "libdir=$(prefix)/lib" >> "$(PACKAGE_PKGCONFIG)" 108 | @echo "" >> "$(PACKAGE_PKGCONFIG)" 109 | @echo "Name: $(PACKAGE)" >> "$(PACKAGE_PKGCONFIG)" 110 | @echo "Description: $(PACKAGE_DESCRIPTION)" >> "$(PACKAGE_PKGCONFIG)" 111 | @echo "Version: $(PACKAGE_VERSION_STRING)" >> "$(PACKAGE_PKGCONFIG)" 112 | @echo "Cflags: $(PKGCONFIG_CFLAGS)" >> "$(PACKAGE_PKGCONFIG)" 113 | @echo "Libs: $(PKGCONFIG_LDFLAGS_NO_LIBS)" >> "$(PACKAGE_PKGCONFIG)" 114 | 115 | 116 | # xcconfig 117 | 118 | $(PACKAGE_XCCONFIG) : $(wildcard config.make) 119 | @echo "// Xcode configuration set for PL/Swift" > "$(PACKAGE_XCCONFIG)" 120 | @echo "// generated on $(shell date)" >> "$(PACKAGE_XCCONFIG)" 121 | @echo "" >> "$(PACKAGE_XCCONFIG)" 122 | @echo "DYLIB_INSTALL_NAME_BASE = $(shell $(PG_CONFIG) --pkglibdir)" >> "$(PACKAGE_XCCONFIG)" 123 | @echo "EXECUTABLE_EXTENSION = so" >> "$(PACKAGE_XCCONFIG)" 124 | @echo "EXECUTABLE_PREFIX = " >> "$(PACKAGE_XCCONFIG)" 125 | @echo "" >> "$(PACKAGE_XCCONFIG)" 126 | @echo "HEADER_SEARCH_PATHS = \$$(inherited) $(HEADER_FILES_INSTALL_DIR) $(PG_CONFIG_INCLUDE_DIRS)" >> "$(PACKAGE_XCCONFIG)" 127 | @echo "LIBRARY_SEARCH_PATHS = \$$(inherited) $(PKGCONFIG_LIB_DIRS) \$$(TOOLCHAIN_DIR)/usr/lib/swift/macosx \$$(BUILT_PRODUCTS_DIR)" >> "$(PACKAGE_XCCONFIG)" 128 | @echo "LD_RUNPATH_SEARCH_PATHS = \$$(inherited) \$$(TOOLCHAIN_DIR)/usr/lib/swift/macosx \$$(BUILT_PRODUCTS_DIR)" >> "$(PACKAGE_XCCONFIG)" 129 | @echo "" >> "$(PACKAGE_XCCONFIG)" 130 | @echo "OTHER_CFLAGS = \$$(inherited) $(shell $(PG_CONFIG) --cflags)" >> "$(PACKAGE_XCCONFIG)" 131 | @echo "" >> "$(PACKAGE_XCCONFIG)" 132 | @echo "OTHER_LDFLAGS = \$$(inherited) $(shell $(PG_CONFIG) --cflags) -rpath \$$(TOOLCHAIN_DIR)/usr/lib/swift/macosx -rpath \$$(BUILT_PRODUCTS_DIR) -undefined dynamic_lookup $(PG_CONFIG_LDFLAGS) $(BUNDLE_FLAGS) $(RUNTIME_LIBS)" >> "$(PACKAGE_XCCONFIG)" 133 | @echo "" >> "$(PACKAGE_XCCONFIG)" 134 | @echo "SWIFT_INCLUDE_PATHS = \$$(inherited) $(PACKAGE_MODMAP_INSTALL_DIR) \$$(TOOLCHAIN_DIR)/usr/lib/swift" >> "$(PACKAGE_XCCONFIG)" 135 | 136 | # modmap 137 | 138 | $(PACKAGE_MODMAP) : $(wildcard config.make) 139 | @echo "// PL/Swift module.map" > "$(PACKAGE_MODMAP)" 140 | @echo "// generated on $(shell date)" >> "$(PACKAGE_MODMAP)" 141 | @echo "" >> "$(PACKAGE_MODMAP)" 142 | @echo "module CPLSwift [system] {" >> "$(PACKAGE_MODMAP)" 143 | @echo " header \"$(SWIFT_SHIM_INSTALL_DIR)/PLSwiftShim.h\"" >> "$(PACKAGE_MODMAP)" 144 | @echo " export *" >> "$(PACKAGE_MODMAP)" 145 | @echo "}" >> "$(PACKAGE_MODMAP)" 146 | --------------------------------------------------------------------------------