devsisters / goquic

QUIC support for Go
http://devsisters.github.io/goquic/
BSD 3-Clause "New" or "Revised" License
943 stars 100 forks source link

FreeBSD #13

Closed l2dy closed 8 years ago

l2dy commented 8 years ago
pkg install clang37 gmake cmake ninja

setenv GOPATH `pwd`
setenv CC /usr/local/bin/clang37
setenv CXX /usr/local/bin/clang++37

go get github.com/devsisters/goquic
cd src/github.com/devsisters/goquic
git clone https://github.com/devsisters/libquic.git
cd libquic

patch <p1.diff # see below
cd src/base/threading
vi platform_thread_freebsd.cc # from https://chromium.googlesource.com/chromium/src/base/+/ba87700/threading/platform_thread_freebsd.cc
patch <p2.diff # see below
cd ../../..

mkdir -p build
cd build
cmake -GNinja ..
ninja
cd ../..

patch <p3.diff # see below
patch <p4.diff # see below
gmake

mkdir -p lib/freebsd_amd64
cp libquic/build/boringssl/crypto/libcrypto.a libquic/build/boringssl/ssl/libssl.a libquic/build/libquic.a libquic/build/protobuf/libprotobuf.a libgoquic.a lib/freebsd_amd64/
setenv CGO_CFLAGS "-I$GOPATH/src/github.com/devsisters/goquic/libquic/boringssl/include"
setenv CGO_LDFLAGS "-L$GOPATH/src/github.com/devsisters/goquic/lib/freebsd_amd64"
go build $GOPATH/src/github.com/devsisters/goquic/example/reverse_proxy.go
strip reverse_proxy

Patches (GitHub turned TAB into spaces): p1.diff

--- CMakeLists.txt.orig
+++ CMakeLists.txt
@@ -186,6 +186,15 @@

        src/base/threading/platform_thread_linux.cc
    )
+elseif (${CMAKE_SYSTEM_NAME} MATCHES "FreeBSD")
+        set(
+                BASE_ARCH_LIBRARIES
+        )
+        set(
+                BASE_ARCH_SOURCES
+
+                src/base/threading/platform_thread_freebsd.cc
+        )
 elseif (${CMAKE_SYSTEM_NAME} MATCHES "Darwin")
    FIND_LIBRARY(COREFOUNDATION_LIBRARY CoreFoundation)
    FIND_LIBRARY(COCOA_LIBRARY Cocoa)

p2.diff

--- platform_thread_freebsd.cc.orig
+++ platform_thread_freebsd.cc
@@ -10,13 +10,15 @@

 #include "base/lazy_instance.h"
 #include "base/logging.h"
+#include "base/threading/platform_thread_internal_posix.h"
 #include "base/threading/thread_id_name_manager.h"
+#if 0
 #include "base/tracked_objects.h"
+#endif
 #include "build/build_config.h"

 #if !defined(OS_NACL)
 #include <pthread.h>
-#include <sys/prctl.h>
 #include <sys/types.h>
 #include <unistd.h>
 #endif
@@ -36,7 +38,7 @@
     {ThreadPriority::NORMAL, 0},
     {ThreadPriority::DISPLAY, -6},
     {ThreadPriority::REALTIME_AUDIO, -10},
-}
+};

 bool SetCurrentThreadPriorityForPlatform(ThreadPriority priority) {
 #if !defined(OS_NACL)
@@ -67,7 +69,9 @@
 // static
 void PlatformThread::SetName(const std::string& name) {
   ThreadIdNameManager::GetInstance()->SetName(CurrentId(), name);
+#if 0
   tracked_objects::ThreadData::InitializeThreadContext(name);
+#endif

 #if !defined(OS_NACL)
   // On FreeBSD we can get the thread names to show up in the debugger by

p3.diff

--- Makefile.orig
+++ Makefile
@@ -1,7 +1,7 @@
-#CC=g++-4.8
+#CXX=g++-4.8
 #AR=ar
-#C=gcc-4.8
-CFLAGS=-Wall -Ilibquic/src -Ilibquic/src/third_party/protobuf/src  -DUSE_OPENSSL=1 -Iboringssl/include -g -gdwarf-4
+#CC=gcc-4.8
+CFLAGS=-Wall -I. -Ilibquic/src -Ilibquic/src/third_party/protobuf/src  -DUSE_OPENSSL=1 -Iboringssl/include -g -gdwarf-4
 CPPFLAGS=--std=gnu++11
 CPP_FILES:=$(wildcard src/*.cc)
 CPP_BASE_FILES:=$(CPP_FILES:src/%=%)
@@ -18,11 +18,11 @@

 #build/%.o: src/%.c
 #  mkdir -p $(dir $@)
-#  $(C) $(CFLAGS) -c -o $@ $<
+#  $(CC) $(CFLAGS) -c -o $@ $<

 build/%.o: src/%.cc
    mkdir -p $(dir $@)
-   $(CC) $(CFLAGS) $(CPPFLAGS) -c -o $@ $<
+   $(CXX) $(CFLAGS) $(CPPFLAGS) -c -o $@ $<

 clean:
    rm -f build/*

p4.diff

--- go_functions.c.orig
+++ go_functions.c
@@ -18,7 +18,7 @@
     return CreateGoSession(go_quic_dispatcher, quic_server_session);
 }

-void* DeleteGoSession_C(void* go_quic_dispatcher, void* go_quic_server_session) {
+void DeleteGoSession_C(void* go_quic_dispatcher, void* go_quic_server_session) {
     DeleteGoSession(go_quic_dispatcher, go_quic_server_session);
 }

--- go_functions.h.orig
+++ go_functions.h
@@ -8,7 +8,7 @@
 void WriteToUDP_C(void* go_writer, void* peer_ip, size_t peer_ip_sz, uint16_t peer_port, void* buffer, size_t buf_len);
 void WriteToUDPClient_C(void* go_writer, void* peer_ip, size_t peer_ip_sz, uint16_t peer_port, void* buffer, size_t buf_len);
 void* CreateGoSession_C(void* go_quic_dispatcher, void* quic_server_session);
-void* DeleteGoSession_C(void* go_quic_dispatcher, void* go_quic_server_session);
+void DeleteGoSession_C(void* go_quic_dispatcher, void* go_quic_server_session);
 int GetProof_C(void* go_quic_dispatcher, void* server_ip, size_t server_ip_sz, char* hostname, size_t hostname_sz, char* server_config, size_t server_config_sz, int ecdsa_ok, char ***out_certs, int *out_certs_sz, size_t **out_certs_item_sz, char **out_signature, size_t *out_signature_sz);
 void* CreateIncomingDynamicStream_C(void* go_quic_server_session, uint32_t id, void* go_quic_spdy_server_stream_go_wrapper);
 void UnregisterQuicServerStreamFromSession_C(void* go_stream);
hodduc commented 8 years ago

:+1: Thank you for the patch. I updated libquic and goquic.

CC=/usr/local/bin/clang37 CXX=/usr/local/bin/clang++37 ./build_libs.sh

and

CGO_LDFLAGS="-L$GOPATH/src/github.com/devsisters/goquic/lib/freebsd_amd64" CGO_CFLAGS="-I$GOPATH/src/github.com/devsisters/goquic/libquic/boringssl/include" go build -a example/server.go

will works from now!

l2dy commented 8 years ago

By default, there is no bash in FreeBSD, so set -e won't work and env: bash: No such file or directory. A #!/bin/sh script would be better. If not so, the gmake if would be redundant and should be removed. Also, FreeBSD won't take those command, CC=/usr/local/bin/clang37: Command not found.. Why not use HTTPS clone by default?

hodduc commented 8 years ago

Replaced shebang to #!/bin/sh. /bin/sh in FreeBSD also has -e flag, according to http://man.freebsd.org/sh/ .

Replaced SSH clone to HTTPS clone.

$ CC=/usr/local/bin/clang37 CXX=/usr/local/bin/clang++37 ./build_libs.sh (should be executed in one line) works on my FreeBSD machine. Hmm.. Am I still missing something?

Anyway,

setenv CC /usr/local/bin/clang37
setenv CCX /usr/local/bin/clang++37
./build_libs.sh

will work as an alternative.

l2dy commented 8 years ago

I was using csh. Maybe that's the difference. Solved anyway.