-
Notifications
You must be signed in to change notification settings - Fork 34
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
feat: support cross compiling libcartesi as a static library #156
Conversation
f1fdde4
to
bb4158b
Compare
bb4158b
to
9274b3b
Compare
01eb512
to
ddc940e
Compare
ddc940e
to
6274ec0
Compare
src/Makefile
Outdated
@@ -248,7 +248,7 @@ EMPTY:= | |||
SPACE:=$(EMPTY) $(EMPTY) | |||
CLANG_TIDY_HEADER_FILTER=$(PWD)/($(subst $(SPACE),|,$(LINTER_HEADERS))) | |||
|
|||
CXXFLAGS+=$(OPTFLAGS) -std=c++17 -fvisibility=hidden -fPIC -MMD $(CC_MARCH) $(INCS) $(GCFLAGS) $(UBFLAGS) $(DEFS) $(WARNS) | |||
CXXFLAGS+=$(OPTFLAGS) -std=gnu++17 -fvisibility=hidden -fPIC -MMD $(CC_MARCH) $(INCS) $(GCFLAGS) $(UBFLAGS) $(DEFS) $(WARNS) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
What "crazyness" required this?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Some systems that I cross compiled (such as DOS), did't have all POSIX functions available when using -std=c++17
, it didn't enable non standard C APIs, such as gettimeofday
, mkdir
, and others, because they are not in standard C. I think some systems are free to disable POSIX APIs with -std=c++17
.
So having -std=gnu++17
is more friendly for cross compilation, another option could be removing -std=
and let use the default one.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
In an ideal world, we would change this flag only on os.cpp, right?
Included changes:
TARGET_OS
make parameter, to allow cross compiling to other OSestermios.h
non-mandatory to compile libcartesi.a when definingNO_TERMIOS
, because WASI SDK target has no support for itlibcartesi.a
static librarystd::filesystem
fromlibcartesi.a
, because WASI SDK target has no support for itlibcartesi_jsonrpc.so
andlibcartesi_jsonrpc.a
, the code was there, but it was not being compiled or installedrpath
andpatchelf
, now all executables and shared libraries are statically linkedlibcartesi.so
still is being built, but is not being linked by anyone, people will be able to choose to link tolibcartesi.so
orlibcartesi.a
make install
to install and strip properly the binaries and librariesmmap
os.cpp
file with automatic detection of supported functions when targeting WASI or Windows-DNO_TTY
for example, in case the target doesn't have an OS supporting that API-std=c++17 -pedantic
was replaced with-std=gnu++17 -Wpedantic
. Because the old flags actually disabled some POSIX functions (such asmkdir
andgettimeofday
) in some toolchains (such as Cosmopolitan or DJGPP for DOSBox).privileged
andPAGE_SIZE
keywords is a define in some toolchains and gave compile errors, so I renamed themmake bundle-boost
, for making easy cross compiling libcartesi with other toolchainslibcartesi.a
in standalone without need to have GRPC or Lua installed in the system, added instructions to README, this important when only wanting to cross compile with other toolchains:=
, to invoke some shell commands which depends on system having protobuf, grpc, lua etc only when really needed by a jobCM_API
frommachine-c-api-internal.h
functions because those APIs should not be exposed in the public C APImake nothreads=yes
After this PR, it is possible to compile a
libcartesi.a
for WASM using two different toolchains (as long you domake bundle-boost
before):With WASI SDK toolchain:
make -C src -j8 release=yes \ TARGET_OS=Linux \ CC=/opt/wasi-sdk/bin/clang \ CXX=/opt/wasi-sdk/bin/clang++ \ AR="/opt/wasi-sdk/bin/llvm-ar rcs" \ libcartesi.a
With Emscripten toolchain:
make -C src -j8 release=yes \ TARGET_OS=Linux \ CC=emcc \ CXX=em++ \ AR="emar rcs" \ libcartesi.a
With GCC RISC-V toolchain (for running a cartesi machine inside itself, yay):
make -C src -j8 release=yes \ TARGET_OS=Linux \ CC=riscv64-linux-gnu-gcc \ CXX=riscv64-linux-gnu-g++ \ AR="riscv64-linux-gnu-ar rcs" \ libcartesi.a
With mingw-w64 toolchain (for Windows build):
NOTE:
TARGET_OS=Linux
andcartesi.so
seem suspicious, but is the correct way to cross compile to Windows build for now.I also tested libcartesi of this PR to compile with the following platforms/toolchains: