How to build Swift project on NixOS? - swift

I'm trying to build a simple Swift project on NixOS. Here are the steps to reproduce:
git clone https://github.com/PerfectlySoft/PerfectTemplate.git
cd PerfectTemplate
touch shell.nix
Add shell.nix with following contents:
with import <nixpkgs> {};
stdenv.mkDerivation {
name = "swift-env";
buildInputs = [
openssl
stdenv
binutils
cmake
pkgconfig
curl
glibc
icu
libblocksruntime
libbsd
libedit
libuuid
libxml2
ncurses
sqlite
swig
];
}
Running nix-shell --pure shell.nix and from there swift build, gives me:
gcc: error: x86_64-unknown-linux: No such file or directory
gcc: error: unrecognized command line option ‘-target’
gcc: error: unrecognized command line option ‘-fblocks’
gcc: error: x86_64-unknown-linux: No such file or directory
gcc: error: unrecognized command line option ‘-fmodules’; did you mean ‘-fmudflap’?
gcc: error: x86_64-unknown-linux: No such file or directory
gcc: error: x86_64-unknown-linux: No such file or directory
gcc: error: x86_64-unknown-linux: No such file or directory
gcc: error: x86_64-unknown-linux: No such file or directory
gcc: error: unrecognized command line option ‘-target’
gcc: error: x86_64-unknown-linux: No such file or directory
gcc: error: unrecognized command line option ‘-fblocks’
gcc: error: unrecognized command line option ‘-target’
gcc: error: unrecognized command line option ‘-target’
gcc: error: unrecognized command line option ‘-target’
gcc: error: unrecognized command line option ‘-fblocks’
gcc: error: unrecognized command line option ‘-fmodules’; did you mean ‘-fmudflap’?
gcc: error: unrecognized command line option ‘-fblocks’
gcc: error: unrecognized command line option ‘-fblocks’
gcc: error: unrecognized command line option ‘-fmodules’; did you mean ‘-fmudflap’?
gcc: error: unrecognized command line option ‘-target’
gcc: error: unrecognized command line option ‘-fmodules’; did you mean ‘-fmudflap’?
gcc: error: unrecognized command line option ‘-fmodules’; did you mean ‘-fmudflap’?
gcc: error: unrecognized command line option ‘-fblocks’
gcc: error: unrecognized command line option ‘-target’
gcc: error: unrecognized command line option ‘-fmodule-name=PerfectCZlib’
gcc: error: unrecognized command line option ‘-fmodules’; did you mean ‘-fmudflap’?
gcc: error: unrecognized command line option ‘-fmodules-cache-path=/home/dmi3y/Dev/Swift/PerfectTemplate/.build/x86_64-unknown-linux/debug/ModuleCache’
gcc: error: unrecognized command line option ‘-fblocks’
I'd appreciate any help with this as I'm pretty much new to nix-shell and NixOS.
EDIT:
I changed my shell.nix to this:
{ pkgs ? import <nixpkgs> {} }:
pkgs.mkShell {
name = "swift-env";
buildInputs = with pkgs; [
openssl
clang
swift
];
shellHook = ''
CC=clang
'';
}
However, when I run nix-shell followed by swift build, I'm now getting:
[1/25] Compiling PerfectCZlib zutil.c
[2/25] Compiling PerfectCZlib uncompr.c
[3/25] Compiling PerfectCZlib inftrees.c
[4/25] Compiling PerfectCZlib inflate.c
[5/25] Compiling PerfectCZlib trees.c
[6/25] Compiling PerfectCZlib inffast.c
[7/25] Compiling PerfectCZlib infback.c
[8/25] Compiling PerfectCZlib gzwrite.c
/nix/store/iz6k7x3l14ykr56crz3dizas1rrkcyzr-clang-wrapper-7.1.0/resource-root/include/module.modulemap:24:8: error: redefinition of module '_Builtin_intrinsics'
# warning _FORTIFY_SOURCE requires compiling with optimization (-O)
^
1 warning and 3 errors generated.
1 warning and 3 errors generated.
Full log can be found here.
This is now looks like a missing library dependency or a version conflict.
For the record, here's additional information about my setup that might shed more light:
$ nix-channel --list
home-manager https://github.com/rycee/home-manager/archive/master.tar.gz
nixos https://nixos.org/channels/nixos-19.09
$ nix-shell --run 'swift -version'
Swift version 5.0.2 (swift-5.0.2-RELEASE)
Target: x86_64-unknown-linux-gnub
After searching the web I found a Jira issue for Swift compiler and this specific comment. I decided to exclude clang from dependencies and only include swift, since this combination seem to be conflicting:
{ pkgs ? import <nixpkgs> {} }:
pkgs.mkShell {
name = "swift-env";
buildInputs = with pkgs; [
openssl
swift
];
shellHook = ''
CC=clang
'';
}
And that worked! I was finally able to build the project!

Since your using the --pure option, nothing from your previous environment will be imported into the shell. This includes the swift binary itself. So first I would add swift to the buildInputs.
The error your getting indicates that gcc doesn't even understand the command line options being passed. I don't know anything about Swift, but after seeing that I assumed that it needs a different compiler. Sure enough, after a quick search it looks like it is llvm based. You will thus need to also add clang to your build inputs. In addition, you'll need to use mkShell instead of mkDerivation to setup the proper environment.
The former is a wrapper to the latter that is specifically designed to set up a nix-shell, and ensures the environment is handled correctly. You'll need to pass in the shellHook attribute to override the default c compiler to clang using the CC envvar. The shellHook is a way of running arbitrary commands at the start of the shell.
As a final note, the nix-shell command searches for shell.nix by default so you don't have to pass it as an argument. If shell.nix does not exist, then it will try default.nix. If neither exist, then you'll have to explicitly specify the nix expressions location.
TLDR
to put it all together:
# a more idiomatic way to import nixpkgs, overridable from the cmdline
{ pkgs ? import <nixpkgs> {} }:
pkgs.mkShell {
name = "swift-env";
buildInputs = with pkgs; [
# your other inputs
clang
swift
];
shellHook = ''
CC=clang
'';
}
Just to be sure my logic was correct I downloaded the repo and gave it go. Everything compiles and runs successfully.

Related

android aosp unrecognized module type "hidl_package_root"

I am trying to build the AOSP automotive car emulator, I am receiving the following error
============================================
PLATFORM_VERSION_CODENAME=REL
PLATFORM_VERSION=9
TARGET_PRODUCT=aosp_car_x86_64
TARGET_BUILD_VARIANT=userdebug
TARGET_BUILD_TYPE=release
TARGET_ARCH=x86_64
TARGET_ARCH_VARIANT=x86_64
TARGET_2ND_ARCH=x86
TARGET_2ND_ARCH_VARIANT=x86_64
HOST_ARCH=x86_64
HOST_2ND_ARCH=x86
HOST_OS=darwin
HOST_OS_EXTRA=Darwin-18.6.0-x86_64-10.14.5
HOST_BUILD_TYPE=release
BUILD_ID=PD2A.190115.032
OUT_DIR=out
============================================
ninja: no work to do.
[1/1] out/soong/.bootstrap/bin/soong_build out/soong/build.ninja
FAILED: out/soong/build.ninja
out/soong/.bootstrap/bin/soong_build -t -l out/.module_paths/Android.bp.list -b out/soong -n out -d out/soong/build.ninja.d -o out/soong/build.ninja Android.bp
error: frameworks/hardware/interfaces/Android.bp:1:1: unrecognized module type "hidl_package_root"
error: hardware/nxp/nfc/extns/intf/nxpnfc/1.0/Android.bp:3:1: unrecognized module type "hidl_package_root"
error: hardware/nxp/nfc/extns/intf/nxpnfc/1.0/Android.bp:8:1: unrecognized module type "hidl_interface"
error: frameworks/hardware/interfaces/displayservice/1.0/Android.bp:3:1: unrecognized module type "hidl_interface"
error: frameworks/hardware/interfaces/schedulerservice/1.0/Android.bp:3:1: unrecognized module type "hidl_interface"
error: frameworks/hardware/interfaces/vr/composer/1.0/Android.bp:3:1: unrecognized module type "hidl_interface"
error: hardware/nxp/secure_element/extns/intf/nxpese/1.0/Android.bp:3:1: unrecognized module type "hidl_package_root"
error: hardware/nxp/secure_element/extns/intf/nxpese/1.0/Android.bp:8:1: unrecognized module type "hidl_interface"
error: frameworks/hardware/interfaces/sensorservice/1.0/Android.bp:3:1: unrecognized module type "hidl_interface"
error: hardware/google/interfaces/Android.bp:4:1: unrecognized module type "hidl_package_root"
error: hardware/interfaces/Android.bp:1:1: unrecognized module type "hidl_package_root"
ninja: build stopped: subcommand failed.
14:09:59 soong bootstrap failed with: exit status 1
#### failed to build some targets (17 seconds) ####
I have am executing the command make -j32 after which I am receiving this error. I have created a separate disk image as mentioned in the documentation to build the environment for aosp. I am using the Mac Mojave OS.
I encountered the same problem building AOSP, in my case for the Pixel 2 XL with build number PQ3A.190801.002.
I started from scratch, doing the same as before, but more carefully this time. It worked. I didn't take the time to confirm what exactly went wrong, but I strongly suspect I accidentally downloaded the wrong proprietary drivers from here. Since this is also not a common issue at all, it might be the same cause for you

How to generate a map file wth platformio

How do I generate a Map file from platformio ?
Framework is mbed for stm32
I've tried passing linker flags in various ways but I get various errors
1. build_flags= -Wl, -Map=mapfile.map
2. build_flags= -Wl, Map=mapfile.map
For 1. I get the error message arm-none-eabi-gcc: error: unrecognized command line option '-Map=mapfile.map'
For 2. I get the linker error message ld.exe: error: 'Map=mapfile.map' not found
Your syntax of passing the build flags is not correct. Here is how to do it:
build_flags = -Wl,-Map,output.map
Reference: https://gcc.gnu.org/onlinedocs/gcc/Link-Options.html

Error in ./configure step in installation of libpqxx

this is a bit of a long shot but:
I'm following this guide: https://www.tutorialspoint.com/postgresql/postgresql_c_cpp.htm
But when running ./configure I get the following error:
(previous checking lines omitted for brevity)
checking for main in -lpq... yes
checking for PQexec in -lpq... yes
checking for correct C++ linkage of basic libpq functions...
sed: character class syntax is [[:space:]], not [:space:]
configure: error:
Linking a call to libpq failed in C++, even though it succeeded in C. If your
C and C++ compilers are very different beasts, this may mean that we do not have
the right options for linking with it after all.
Read the config.log file for more detailed information. Look for the last error
message, which may be several pages up from the end of the file.
And the configure.log file looks like this:
This file contains any messages produced by compilers while
running configure, to aid debugging if configure makes a mistake.
It was created by libpqxx configure 4.0, which was
generated by GNU Autoconf 2.68. Invocation command line was
$ ./configure
## --------- ##
## Platform. ##
## --------- ##
(some lines omitted)
configure:3039: g++ -V >&5
g++: error: unrecognized command line option '-V'
g++: fatal error: no input files
compilation terminated.
configure:3050: $? = 1
configure:3039: g++ -qversion >&5
g++: error: unrecognized command line option '-qversion'; did you mean '--version'?
g++: fatal error: no input files
compilation terminated.
(some lines omitted)
configure:7629: gcc -E conftest.c
conftest.c:11:10: fatal error: ac_nonexistent.h: No such file or directory
#include <ac_nonexistent.h>
^~~~~~~~~~~~~~~~~~
compilation terminated.
(some lines omitted)
configure:8319: gcc -c -g -O2 -fno-rtti -fno-exceptions conftest.c >&5
cc1: warning: command line option '-fno-rtti' is valid for C++/ObjC++ but not for C
(some lines omitted)
configure:16424: g++ -o conftest -g -O2 -L/usr/lib/x86_64-linux-gnu conftest.cpp >&5
/tmp/ccfFBf4K.o: In function `main':
/home/peter/libpqxx-4.0/conftest.cpp:44: undefined reference to `PQexec'
collect2: error: ld returned 1 exit status
(some liens omitted)
I don't believe I have any packages missing. I have the newest version of g++, psql and libpqxx installed.
I have updated and upgraded all packages on my system.
I have crawled the web for solutions to this error, but I have no clue what is wrong.
Do you have an idea where I can go from here?
There hasn't been a tarball release of libpqxx at the old spot in a long time, so the tutorial you used with its wget command to download the tarball is very outdated.
The issue you encountered looks related to this issue and appears to have been fixed in this commit:
commit 85e9336740475be25ed19924cca0961f7d844c4b
Author: Jeroen Vermeulen <jtvjtv#gmail.com>
Date: Thu Jun 1 11:39:08 2017 +0700
Fix #13: not linking to libpq.
This was that annoying interaction between autoconf, m4, GNU sed syntax,
and the shell which broke the "remove redundant -lpq options" code in
the configure script.
Solution: forget about GNU sed's "[[:space:]]" syntax, and just look for
a literal space. There aren't going to be any tabs, newlines,
non-breaking spaces, etc. there in even a moderately sane world.

Makefile command line arguments confused with MinGW directory paths

I'm trying to run a make all command but I get a very confusing error, it seems as if the arguments from 'cl' are mistaken as directory paths in MinGW. The output I'm getting:
cl /EHsc /MD /nologo /D_SILENCE_STDEXT_HASH_DEPRECATION_WARNINGS -nologo /O2 -DN
DEBUG -DUSE_CBC -DUSE_CLP /D__WIN32__ /Iinclude\\src\\windows /DGFLAGS_DLL_DECL=
/DGFLAGS_DLL_DECLARE_FLAG= /DGFLAGS_DLL_DEFINE_FLAG= /Iinclude /I. -DUSE_GLOP -
DUSE_BOP -c examples\\cpp\\costas_array.cc /Foobjs\\costas_array.obj
That's the cl command, not the warnings and errors (note that cl /EHsc actually gets mistaken for 'C:/MinGW/MSYS/1.0/EHsc', etc...):
cl : Command line warning D9024 : unrecognized source file type 'C:/MinGW/MSYS/1
.0/EHsc', object file assumed
cl : Command line warning D9027 : source file 'C:/MinGW/MSYS/1.0/EHsc' ignored
cl : Command line warning D9024 : unrecognized source file type 'C:/MinGW/MSYS/1
.0/MD', object file assumed
cl : Command line warning D9027 : source file 'C:/MinGW/MSYS/1.0/MD' ignored
cl : Command line warning D9024 : unrecognized source file type 'C:/MinGW/MSYS/1
.0/nologo', object file assumed
cl : Command line warning D9027 : source file 'C:/MinGW/MSYS/1.0/nologo' ignored
... etc ... Until there's the fatal error at the end
cl : Command line warning D9024 : unrecognized source file type 'C:/MinGW/MSYS/1
.0/I.', object file assumed
cl : Command line warning D9027 : source file 'C:/MinGW/MSYS/1.0/I.' ignored
cl : Command line warning D9027 : source file 'C:/MinGW/MSYS/1.0/Foobjs/costas_a
rray.obj' ignored
costas_array.cc
examples\cpp\costas_array.cc(27): fatal error C1083: Cannot open include file: '
ortools/base/callback.h': No such file or directory
make: *** [objs\\costas_array.obj] Error 2
Any help about why is this happening would be highly appreciated, I am not very experienced in this matter.
It's the MSYS shell doing these translations for you in an attempt of being helpful.
With the tools typically used in this shell, it's no problem because arguments/options start with a - or -- (the Unix and/or GNU convention). It starts getting into your way as soon as you need command-line tools following the Microsoft convention for options and flags, using /.
Unfortunately, for the original MSYS, I'm not aware of a way to disable this translation. But there is one for MSYS2, see the question I asked about it: You just need to set an environment variable, e.g.
export MSYS2_ARG_CONV_EXCL=\*
So, my suggestion would be you upgrade your tools to MSYS2 and use this.

FIWARE- Orion Context Broker

I tried to install Orion context Broker on Ubuntu 14.04 with Alien but when I do contextBroker start it says:
contextBroker: error while loading shared libraries: libboost_thread-mt.so.5: cannot open shared object file: No such file or directory
I couldn't find where is the error then I tried to install with all the dependencies from the instructions in Git, but when I try to do the make it makes an error:
[ 26%] Building CXX object src/lib/serviceRoutines/CMakeFiles/serviceRoutines.dir/exitTreat.cpp.o
In file included from /home/sistemas/fiware-orion-develop/src/lib/serviceRoutines/exitTreat.cpp:32:0:
/home/sistemas/fiware-orion-develop/src/lib/mongoBackend/MongoGlobal.h:30:35: fatal error: mongo/client/dbclient.h: No existe el archivo o el directorio
#include "mongo/client/dbclient.h"
I have the mongo's driver installed, how can I solve this?
Finally I compile a new driver from https://github.com/mongodb/mongo-cxx-driver/releases and it continues compiling until:
*
/home/sistemas/fiware-orion/src/lib/mongoBackend/MongoGlobal.cpp: In function ‘void recoverOnTimeIntervalThread(std::string, mongo::BSONObj&)’:
/home/sistemas/fiware-orion/src/lib/mongoBackend/MongoGlobal.cpp:532:40: error: ‘class mongo::OID’ has no member named ‘str’
std::string subId = idField.OID().str();
^
/home/sistemas/fiware-orion/src/lib/mongoBackend/MongoGlobal.cpp: In function ‘void destroyOnTimeIntervalThread(std::string, mongo::BSONObj&)’:
/home/sistemas/fiware-orion/src/lib/mongoBackend/MongoGlobal.cpp:583:40: error: ‘class mongo::OID’ has no member named ‘str’
std::string subId = idField.OID().str();
^
/home/sistemas/fiware-orion/src/lib/mongoBackend/MongoGlobal.cpp: In function ‘void releaseTriggeredSubscriptions(std::map<std::basic_string<char>, TriggeredSubscription*>&)’:
/home/sistemas/fiware-orion/src/lib/mongoBackend/MongoGlobal.cpp:1911:17: error: ‘string’ was not declared in this scope
for (std::map<string, TriggeredSubscription*>::iterator it = subs.begin(); it != subs.end(); ++it)
^
/home/sistemas/fiware-orion/src/lib/mongoBackend/MongoGlobal.cpp:1911:17: note: suggested alternative:
In file included from /usr/include/c++/4.9/iosfwd:39:0,
from /usr/include/boost/smart_ptr/shared_ptr.hpp:49,
from /usr/include/boost/shared_ptr.hpp:17,
from /usr/include/mongo/client/dbclient_rs.h:20,
from /usr/include/mongo/client/dbclient.h:59,
from /home/sistemas/fiware-orion/src/lib/mongoBackend/MongoGlobal.cpp:27:
/usr/include/c++/4.9/bits/stringfwd.h:62:33: note: ‘std::string’
typedef basic_string<char> string;
^
/home/sistemas/fiware-orion/src/lib/mongoBackend/MongoGlobal.cpp:1911:47: error: template argument 1 is invalid
for (std::map<string, TriggeredSubscription*>::iterator it = subs.begin(); it != subs.end(); ++it)
^
/home/sistemas/fiware-orion/src/lib/mongoBackend/MongoGlobal.cpp:1911:47: error: template argument 3 is invalid
/home/sistemas/fiware-orion/src/lib/mongoBackend/MongoGlobal.cpp:1911:47: error: template argument 4 is invalid
/home/sistemas/fiware-orion/src/lib/mongoBackend/MongoGlobal.cpp:1911:59: error: invalid type in declaration before ‘it’
for (std::map<string, TriggeredSubscription*>::iterator it = subs.begin(); it != subs.end(); ++it)
^
/home/sistemas/fiware-orion/src/lib/mongoBackend/MongoGlobal.cpp:1911:59: error: expected ‘;’ before ‘it’
/home/sistemas/fiware-orion/src/lib/mongoBackend/MongoGlobal.cpp:1911:59: error: ‘it’ was not declared in this scope
/home/sistemas/fiware-orion/src/lib/mongoBackend/MongoGlobal.cpp:1911:94: error: expected ‘)’ before ‘;’ token
for (std::map<string, TriggeredSubscription*>::iterator it = subs.begin(); it != subs.end(); ++it)
/home/sistemas/fiware-orion/src/lib/mongoBackend/MongoGlobal.cpp:1911:50: error: unused variable ‘iterator’ [-Werror=unused-variable]
for (std::map<string, TriggeredSubscription*>::iterator it = subs.begin(); it != subs.end(); ++it)
^
/home/sistemas/fiware-orion/src/lib/mongoBackend/MongoGlobal.cpp:1911:98: error: ‘it’ was not declared in this scope
for (std::map<string, TriggeredSubscription*>::iterator it = subs.begin(); it != subs.end(); ++it)
^
cc1plus: all warnings being treated as errors
make[3]: *** [src/lib/mongoBackend/CMakeFiles/mongoBackend.dir/MongoGlobal.cpp.o] Error 1
make[3]: se sale del directorio «/home/sistemas/fiware-orion/BUILD_RELEASE»
make[2]: *** [src/lib/mongoBackend/CMakeFiles/mongoBackend.dir/all] Error 2
make[2]: *** Se espera a que terminen otras tareas....
[ 88%] Building CXX object src/lib/xmlParse/CMakeFiles/xmlParse.dir/xmlRegisterProviderRequest.cpp.o
*
Is a problem in a file of Orion Context Broker?
I think that it could be a problem with de mongo's driver again but I try to install another one older and it doesn't work. I also think it can be a problem with de -mt libraries that doesn't exist in boost anymore, but nothing that I try until now works.
I've installed Orion CB using Ubuntu 14.04 LTS as host. I've also found some problems with libboost_thread-mt.so libraries. Solved this way:
Get & install packages
boost-thread-1.41.0-25.el6.x86_64.rpm
boost-system-1.41.0-25.el6.x86_64.rpm
boost-filesystem-1.41.0-25.el6.x86_64.rpm
and install them using alien. Then, the libraries were installed in “/usr/lib64” folder. To correct this (and CB is able to locate them): create a .conf file within “/etc/ld.so.conf.d/”, add a line (“/usr/lib64”) within and save it and quit and reload your configuration by calling (“sudo ldconfig”)
Hope this helps
So, here we have two questions in one. Let's start with the first one, about shared library not found:
Ask the broker where the library should be, using "ldd $(which contextBroker) | grep boost_thread).
After running this command, make sure the library is there. If it is not, but you have it elsewhere, you should be able to use the env var LD_LIBRARY_PATH to point to the directory where the library is found.
Now, for the second question, the mongo driver includes are not found. In my machine, I have them in /usr/local/include/mongo => I'm ok with the -I/usr/local/include directive to the compiler.
If you have your mongo driver installed elsewhere, you might need to add another 'include-directory' for the compilation. This would be done in the top-level CMakeLists.txt (I guess using 'include_directories' - I'm far from a cmake expert :-)).
When building, to see detailed information, compile like this:
% CPU_COUNT=1 VERBOSE=1 make install
Post the info again here unless you manage to solve your problems.