Skip to content
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

Fixes #19046: Add windows support to http client build #3548

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
38 changes: 31 additions & 7 deletions agent/sources/client/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ CFLAGS ?= -std=c99 -Wall -Wextra -Wpedantic \
-Wredundant-decls -Wnested-externs -Wmissing-include-dirs \
-D_FORTIFY_SOURCE=2 -fstack-protector-strong -fPIE
BUILD_CFLAGS=$(CFLAGS)
LDFLAGS ?= -Wl,-z,now -Wl,-z,relro -pie
LDFLAGS ?= -Wl,-z,now -Wl,-z,relro -pie -fstack-protector-strong
BUILD_LDFLAGS=$(LDFLAGS)
# Debug flags
CFLAGS_DEBUG := -O -g3 -DDEBUG -fsanitize=address,undefined
Expand All @@ -42,15 +42,28 @@ endif
CFLAGS_RELEASE := -O2
BUILD_LDFLAGS += -lcurl -lm

BUILD_DEP:=

# to use static tomlc use: make STATIC_TOML=1
# in this case you need to put its sources in ./tomlc99/
ifdef STATIC_TOML
BUILD_CFLAGS += -I./tomlc99
BUILD_LDFLAGS += ./tomlc99/libtoml.a
BUILD_DEP += toml
else
BUILD_LDFLAGS += -ltoml
endif

# Cross compilation
# you need the mingw-w64 package for this
ifeq (windows,$(TARGET))
CC := x86_64-w64-mingw32-gcc
BUILD_DEP += curl
BUILD_CFLAGS += -I./curl/include/
BUILD_LDFLAGS += -L./curl/lib/
EXEC := rudder_client.exe
endif

# build is debug
b : build
build: BUILD_CFLAGS += $(CFLAGS_DEBUG)
Expand All @@ -63,12 +76,23 @@ $(BUILD_DIR):
install -d $(BUILD_DIR)

# No separate dirs for debug and release, we clean at every run
bin-target: clean $(BUILD_DIR) toml $(BUILD_DIR)/$(EXEC)

toml:
ifdef STATIC_TOML
cd tomlc99 && $(MAKE) "CFLAGS=$(BUILD_CFLAGS) -std=c99 -fPIC"
endif
bin-target: clean $(BUILD_DIR) $(BUILD_DEP) $(BUILD_DIR)/$(EXEC)

curl:
wget -nv http://repository.rudder.io/build-dependencies/curl/curl-7.69.1_1-win64-mingw.zip
unzip curl-7.69.1_1-win64-mingw.zip
mv curl-7.69.1-win64-mingw/ curl
rm curl-7.69.1_1-win64-mingw.zip

tomlc99:
wget -nv http://repository.rudder.io/build-dependencies/tomlc99/tomlc99-c5d2e37.tar.gz
tar xf tomlc99-c5d2e37.tar.gz
mv tomlc99-master tomlc99
rm tomlc99-c5d2e37.tar.gz
patch -p1 < toml.patch

toml: tomlc99
cd tomlc99 && $(MAKE) CC=$(CC) "CFLAGS=$(CFLAGS) -std=c99 -fPIC" LDFLAGS="$(LDFLAGS)"

$(BUILD_DIR)/%.o: $(SRC_DIR)/%.c
$(CC) $(BUILD_CFLAGS) $(BUILD_CPPFLAGS) -c -o $@ $<
Expand Down
11 changes: 11 additions & 0 deletions agent/sources/client/toml.patch
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
--- a/tomlc99/Makefile 2021-01-28 03:53:31.000000000 +0100
+++ b/tomlc99/Makefile 2021-03-18 17:24:24.440455804 +0100
@@ -24,7 +24,7 @@
ar -rcs $@ $^

libtoml.so: toml.o
- $(CC) -shared -o $@ $^
+ $(CC) $(LDFLAGS) -shared -o $@ $^

toml_json: toml_json.c $(LIB)