lys
August 1, 2021, 6:56am
1
Hi folks,
I'm seeking to wrap a C library using the SPM - however this isn't a library available via distribution channels like homebrew and apt, I'm wrapping .h
header files (and .c
files if this is possible) directly.
Is this currently possible?
If so, should I be manually creating module maps for every header? There's about 20 headers in the src folder for this library.
Many guides I've found are for wrapping system libraries available via distribution channels mentioned, so it's unclear if the SPM supports what I'm trying to do.
Fallback: should I just compile the library and work with the static lib (.a
file) instead? It'd be ace to use the SPM for this and make it portable (and shareable!) if possible :D
just put all the codes into a package and it will done.
MyCLib
├── Sources
│ └── MyCLib
│ ├── include
│ │ └── public.h
│ ├── private.h
│ └── source.c
└── Package.swift
also, you can change the folder layout but you have to tell SwiftPM where the sources located.
here examples:
// swift-tools-version:5.1
//
// Package.swift
//
// The MIT License
// Copyright (c) 2015 - 2022 Susan Cheng. All rights reserved.
//
// Permission is hereby granted, free of charge, to any person obtaining a copy
// of this software and associated documentation files (the "Software"), to deal
// in the Software without restriction, including without limitation the rights
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
// copies of the Software, and to permit persons to whom the Software is
// furnished to do so, subject to the following conditions:
//
// The above copyright notice and this permission notice shall be included in
// all copies or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
This file has been truncated. show original
// swift-tools-version:5.1
//
// Package.swift
//
// The MIT License
// Copyright (c) 2015 - 2022 Susan Cheng. All rights reserved.
//
// Permission is hereby granted, free of charge, to any person obtaining a copy
// of this software and associated documentation files (the "Software"), to deal
// in the Software without restriction, including without limitation the rights
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
// copies of the Software, and to permit persons to whom the Software is
// furnished to do so, subject to the following conditions:
//
// The above copyright notice and this permission notice shall be included in
// all copies or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
This file has been truncated. show original
// swift-tools-version:5.1
//
// Package.swift
//
// The MIT License
// Copyright (c) 2015 - 2022 Susan Cheng. All rights reserved.
//
// Permission is hereby granted, free of charge, to any person obtaining a copy
// of this software and associated documentation files (the "Software"), to deal
// in the Software without restriction, including without limitation the rights
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
// copies of the Software, and to permit persons to whom the Software is
// furnished to do so, subject to the following conditions:
//
// The above copyright notice and this permission notice shall be included in
// all copies or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
This file has been truncated. show original
2 Likes
lys
August 1, 2021, 9:45am
3
Woo! That's wonderful - nice and clear. Thanks for the links too.
Now I can try to build the package for my target - looks like this lib isn't supported for iOS
'CoreAudio/HostTime.h' file not found
edit: think I'm finding a workaround! Technical Q&A QA1643: Audio Host Time On iOS