I'm migrating a project from Cocoapods to SPM, but I'm stuck on an issue where we only need to use certain dependencies in conditional cases.
Cocoapods has an easy solution for this:
if ENV['enabled'].to_i == 1
pod 'Google'
end
As far as I know, conditional dependencies are only partially supported in SPM and it isn't enough for my problem:
https://github.com/apple/swift-evolution/blob/main/proposals/0273-swiftpm-conditional-target-dependencies.md
I was thinking about creating a build phase script to manually include the framework as a target member based on the environmental variable condition.
Looking for a working solution.
"Package.swift" is a regular swift file and you can write any code for your logic and conditions inside. For instance, you can check environment variables with ProcessInfo and assemble needed arrays of dependencies:
import PackageDescription
import Foundation
let useRealm = ProcessInfo.processInfo.environment["realm"] == "1"
let packageDependencies: [Package.Dependency] = useRealm
? [.package(url: "https://github.com/realm/realm-cocoa.git", from: "10.15.1")]
: []
let targetDependencies: [Target.Dependency] = useRealm
? [.product(name: "Realm", package: "realm-cocoa")]
: []
let package = Package(
name: "MyPackage",
platforms: [
.iOS(.v12),
.macOS(.v10_14)
],
products: [
.library(name: "MyPackage", targets: ["MyPackage"]),
],
dependencies: packageDependencies,
targets: [
.target(name: "MyPackage", dependencies: targetDependencies),
.testTarget(name: "MyPackageTests", dependencies: ["MyPackage"]),
]
)
Now you can build your package with no dependencies:
$ xcrun --sdk macosx swift build
Building for debugging...
[2/2] Emitting module MyPackage
Build complete! (0.77s)
And with the Realm dependency by setting realm=1 in the environment variables:
$ export realm=1
$ xcrun --sdk macosx swift build
Fetching https://github.com/realm/realm-cocoa.git from cache
Fetched https://github.com/realm/realm-cocoa.git (2.12s)
Computing version for https://github.com/realm/realm-cocoa.git
Computed https://github.com/realm/realm-cocoa.git at 10.32.0 (0.02s)
Fetching https://github.com/realm/realm-core from cache
Fetched https://github.com/realm/realm-core (1.37s)
Computing version for https://github.com/realm/realm-core
Computed https://github.com/realm/realm-core at 12.9.0 (0.02s)
Creating working copy for https://github.com/realm/realm-cocoa.git
Working copy of https://github.com/realm/realm-cocoa.git resolved at 10.32.0
Creating working copy for https://github.com/realm/realm-core
Working copy of https://github.com/realm/realm-core resolved at 12.9.0
Building for debugging...
[63/63] Compiling MyPackage MyPackage.swift
Build complete! (41.64s)
the error broke during the make period
this is the procedure before the error came out
1.download the source code from github of opencv and opencv_contrib 4.3.0
2.creat a dir under opencv source code dir name opencv_contrib
3.enter the build dir and enter the code
cmake -D CMAKE_INSTALL_PREFIX=/usr/local -D CMAKE_BUILD_TYPE=Release -D OPENCV_EXTRA_MODULES_PATH=../opencv_contrib/modules ..
some of the files to download while cmake didn't download but I manually download those and all of the fail-to-download files are copied to the required route
then begin to make
make -j7
error break while making
Scanning dependencies of target opencv_test_xfeatures2d
[ 90%] Building CXX object modules/xfeatures2d/CMakeFiles/opencv_test_xfeatures2d.dir/test/test_detectors.cpp.o
[ 90%] Building CXX object modules/gapi/CMakeFiles/opencv_test_gapi.dir/test/internal/gapi_transactions_test.cpp.o
[ 90%] Building CXX object modules/gapi/CMakeFiles/opencv_test_gapi.dir/test/own/conc_queue_tests.cpp.o
[ 90%] Building CXX object modules/xfeatures2d/CMakeFiles/opencv_test_xfeatures2d.dir/test/test_features2d.cpp.o
[ 90%] Building CXX object modules/xfeatures2d/CMakeFiles/opencv_perf_xfeatures2d.dir/perf/perf_surf.ocl.cpp.o
/home/wang/Documents/opencv-4.3.0/opencv_contrib/modules/xfeatures2d/test/test_features2d.cpp: In member function ‘virtual void opencv_test::{anonymous}::Features2d_SIFTHomographyTest_regression_Test::Body()’:
/home/wang/Documents/opencv-4.3.0/opencv_contrib/modules/xfeatures2d/test/test_features2d.cpp:366:88: error: ‘SIFT’ has not been declared
TEST(Features2d_SIFTHomographyTest, regression) { CV_DetectPlanarTest test("SIFT", 80, SIFT::create()); test.safe_run(); }
^~~~
/home/wang/Documents/opencv-4.3.0/opencv_contrib/modules/xfeatures2d/test/test_features2d.cpp: In member function ‘virtual void opencv_test::{anonymous}::Features2d_SIFT_using_mask_regression_Test::Body()’:
/home/wang/Documents/opencv-4.3.0/opencv_contrib/modules/xfeatures2d/test/test_features2d.cpp:435:39: error: ‘SIFT’ has not been declared
FeatureDetectorUsingMaskTest test(SIFT::create());
reference websites
https://www.cnblogs.com/fx-blog/p/8213704.html
https://blog.csdn.net/u011736771/article/details/85960300
I had the same problem with the 4.3.0 release, SIFT was moved out of xfeatures2d but I dont think it was inserted in the main branch for the 4.3.0 release. Just download the master (development) branch and the problem is solved
I am trying to package a simple Kivy app in iOS using the instruction in the site:
https://github.com/kivy/kivy-ios
My app is very simple with 1 line:
from firebase import firebase
The app can be packaged successfully in android using linux. However, I am having problem packaging it to iOS. I need to build a recipe named pycrypto but it's giving me the below error. I tried both python2 and python3. I still ended up with the same error. It seems the url link is dead (https://ftp.dlitz.net/pub/dlitz/crypto/pycrypto/pycrypto-2.6.1.tar.gz)
https://kivy.org/doc/stable/guide/packaging-ios.html
hcaos-iMac:kivy-ios hcao$ ./toolchain.py build pycrypto
[INFO ] Building with 4 processes, where supported
[INFO ] Want to build ['pycrypto']
[INFO ] Loaded recipe pycrypto (depends of ['python', 'openssl'], optional are [])
[INFO ] Loaded recipe python (depends of [u'python3'], optional are [])
[INFO ] Loaded recipe openssl (depends of [], optional are [])
[INFO ] Loaded recipe python3 (depends of ['hostpython3', 'libffi', 'openssl'], optional are [])
[INFO ] Loaded recipe hostpython3 (depends of [], optional are ['openssl'])
[INFO ] Loaded recipe libffi (depends of [], optional are [])
[INFO ] Build order is ['libffi', 'openssl', 'hostpython3', u'python3', 'python', 'pycrypto']
[INFO ] Recipe order is ['libffi', 'openssl', 'hostpython3', 'python3', 'pycrypto']
[INFO ] Include dir added: {arch.arch}/ffi
[INFO ] Include dir added: {arch.arch}/openssl
[INFO ] Global: hostpython located at /Users/hcao/Desktop/kivyios-python3/kivy-ios/dist/hostpython3/bin/python
[INFO ] Global: hostpgen located at /Users/hcao/Desktop/kivyios-python3/kivy-ios/dist/hostpython3/bin/pgen
[DEBUG ] Cached result: Download libffi. Ignoring
[DEBUG ] Cached result: Extract libffi. Ignoring
[DEBUG ] Cached result: Build_all libffi. Ignoring
[DEBUG ] Cached result: Download openssl. Ignoring
[DEBUG ] Cached result: Extract openssl. Ignoring
[DEBUG ] Cached result: Build_all openssl. Ignoring
[DEBUG ] Cached result: Download hostpython3. Ignoring
[DEBUG ] Cached result: Extract hostpython3. Ignoring
[DEBUG ] Cached result: Build_all hostpython3. Ignoring
[DEBUG ] Cached result: Download python3. Ignoring
[DEBUG ] Cached result: Extract python3. Ignoring
[DEBUG ] Cached result: Build_all python3. Ignoring
[INFO ] Download pycrypto
[INFO ] Downloading https://ftp.dlitz.net/pub/dlitz/crypto/pycrypto/pycrypto-2.6.1.tar.gz
Traceback (most recent call last):
File "./toolchain.py", line 1569, in <module>
ToolchainCL()
File "./toolchain.py", line 1284, in __init__
getattr(self, args.command)()
File "./toolchain.py", line 1325, in build
build_recipes(args.recipe, ctx)
File "./toolchain.py", line 1161, in build_recipes
recipe.execute()
File "/Users/hcao/Desktop/kivyios-python3/kivy-ios/toolchain.py", line 726, in execute
self.download()
File "/Users/hcao/Desktop/kivyios-python3/kivy-ios/toolchain.py", line 84, in _cache_execution
f(self, *args, **kwargs)
File "/Users/hcao/Desktop/kivyios-python3/kivy-ios/toolchain.py", line 761, in download
self.download_file(self.url.format(version=self.version), fn)
File "/Users/hcao/Desktop/kivyios-python3/kivy-ios/toolchain.py", line 478, in download_file
urlretrieve(url, filename, report_hook)
File "/Library/Python/2.7/site-packages/future/backports/urllib/request.py", line 1731, in retrieve
fp = self.open(url, data)
File "/Library/Python/2.7/site-packages/future/backports/urllib/request.py", line 1703, in open
raise_with_traceback(IOError('socket error', msg))
File "/Library/Python/2.7/site-packages/future/backports/urllib/request.py", line 1697, in open
return getattr(self, name)(url)
File "/Library/Python/2.7/site-packages/future/backports/urllib/request.py", line 1907, in open_https
return self._open_generic_http(self._https_connection, url, data)
File "/Library/Python/2.7/site-packages/future/backports/urllib/request.py", line 1856, in _open_generic_http
http_conn.request("GET", selector, headers=headers)
File "/Library/Python/2.7/site-packages/future/backports/http/client.py", line 1083, in request
self._send_request(method, url, body, headers)
File "/Library/Python/2.7/site-packages/future/backports/http/client.py", line 1121, in _send_request
self.endheaders(body)
File "/Library/Python/2.7/site-packages/future/backports/http/client.py", line 1079, in endheaders
self._send_output(message_body)
File "/Library/Python/2.7/site-packages/future/backports/http/client.py", line 924, in _send_output
self.send(msg)
File "/Library/Python/2.7/site-packages/future/backports/http/client.py", line 860, in send
self.connect()
File "/Library/Python/2.7/site-packages/future/backports/http/client.py", line 1221, in connect
self.timeout, self.source_address)
File "/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/socket.py", line 575, in create_connection
raise err
IOError: [Errno socket error] [Errno 61] Connection refused
Answer can be found at https://github.com/kivy/kivy-ios/issues/384
Pycrypto can be built but it won't run properly. The workaround is to avoid firebase (which requires pycrypto) altogether. Use requests and json instead for simple get and post methods.
I'm trying to install SDK for ESP8266 for working with kaa.
I'm use this guide
https://docs.kaaproject.org/display/KAA/ESP8266
but during stage
./ct-ng xtensa-lx106-elf
./ct-ng build
I got error
[INFO ] Performing some trivial sanity checks
[INFO ] Build started 20180406.213426
[INFO ] Building environment variables
[INFO ] =================================================================
[INFO ] Retrieving needed toolchain components' tarballs
[ERROR]
[ERROR] >>
[ERROR] >> Build failed in step 'Retrieving needed toolchain components' tarballs'
[ERROR] >> called in step '(top-level)'
[ERROR] >>
[ERROR] >> Error happened in: do_mpc_get[scripts/build/companion_libs/140-mpc.sh#741]
[ERROR] >> called from: do_companion_libs_get[scripts/build/companion_libs.sh#15]
[ERROR] >> called from: main[scripts/crosstool-NG.sh#583]
[ERROR] >>
[ERROR] >> For more info on this error, look at the file: 'build.log'
[ERROR] >> There is a list of known issues, some with workarounds, in:
[ERROR] >> 'share/doc/crosstool-ng/ct-ng.1.20.0/B - Known issues.txt'
[ERROR]
[ERROR] (elapsed: 0:07.12)
[00:08] / make: *** [build] Помилка 1
What should I do? How can I live on?
Thanks in advance for your answers.
The function do_mpc_get() is trying to download the MPC tarball from a unavailable resource. You can try to edit this function on the script
scripts/build/companion_libs/140-mpc.sh
and use the following lines instead:
do_mpc_get() {
CT_GetFile "mpc-${CT_MPC_VERSION}" .tar.gz \
https://ftp.gnu.org/gnu/mpc
}
If the error persist and the required tarballs still missing, you can manually download it and put them on the tarball directory, and proceed the build.
/crosstool-NG/.build/tarballs
I have added poison library to rebar.config file:
{
deps, [
poison
]
}.
But when I run rebar3 compile, it shows me an error:
===> Package <<"poison">> not found. Fetching registry updates and trying again...
...
===> Package not found in registry: <<"poison">>.
How do I make it work?