static: use pkg-config exclusively when using it #445

Merged
rmg merged 1 commits from exclusive-pkg-config into master 2019-01-04 06:18:20 -06:00
rmg commented 2018-06-28 12:26:21 -05:00 (Migrated from github.com)

When using the static linking option on platforms that use pkg-config,
use ONLY pkg-config to get the CFLAGS and LDFLAGS. This prevents pulling
in dependencies and flags for any non-vendored version that may be
present on the host.

The main practical effect of this is that if someone doesn't need/want
any sort of remote access support at all they can completely disable
libcurl, libssh2, libssl, etc and produce a smaller/simpler binary and
greatly simplify their build-time dependencies. When done properly, the
generated pkg-config file will tell cgo everything it needs to know.

This also prevents confusion if there is a system copy of libgit2 that
is being given priority over the vendored build.

When using the static linking option on platforms that use pkg-config, use ONLY pkg-config to get the CFLAGS and LDFLAGS. This prevents pulling in dependencies and flags for any non-vendored version that may be present on the host. The main practical effect of this is that if someone doesn't need/want any sort of remote access support at all they can completely disable libcurl, libssh2, libssl, etc and produce a smaller/simpler binary and greatly simplify their build-time dependencies. When done properly, the generated pkg-config file will tell cgo everything it needs to know. This also prevents confusion if there is a system copy of libgit2 that is being given priority over the vendored build.
rmg commented 2018-06-28 12:36:22 -05:00 (Migrated from github.com)

This patch was required to be able to do the following in my builds:

LIBGIT2 := vendor/gopkg.in/libgit2/git2go.v27/vendor/libgit2
LIBGIT2PC := $(LIBGIT2)/build/libgit2.pc

my_cmd: cmd/my_cmd/*.go $(LIBGIT2PC)
	go build -o $@ --tags "static" ./cmd/my_cmd

$(LIBGIT2)/CMakeLists.txt:
	git submodule update --init $(@D)

$(LIBGIT2PC): $(LIBGIT2)/CMakeLists.txt
	mkdir -p $(@D) $(LIBGIT2)/install/lib
	cd $(@D) && \
		cmake -DTHREADSAFE=ON \
			-DBUILD_CLAR=OFF \
			-DUSE_SSH=OFF \
			-DUSE_HTTPS=OFF \
			-DCURL=OFF \
			-DBUILD_SHARED_LIBS=OFF \
			-DCMAKE_C_FLAGS=-fPIC \
			-DCMAKE_INSTALL_PREFIX=../install \
			-DCMAKE_BUILD_TYPE="MinSizeRel" \
		.. && \
	  cmake --build . && \
	  make install
This patch was required to be able to do the following in my builds: ``` LIBGIT2 := vendor/gopkg.in/libgit2/git2go.v27/vendor/libgit2 LIBGIT2PC := $(LIBGIT2)/build/libgit2.pc my_cmd: cmd/my_cmd/*.go $(LIBGIT2PC) go build -o $@ --tags "static" ./cmd/my_cmd $(LIBGIT2)/CMakeLists.txt: git submodule update --init $(@D) $(LIBGIT2PC): $(LIBGIT2)/CMakeLists.txt mkdir -p $(@D) $(LIBGIT2)/install/lib cd $(@D) && \ cmake -DTHREADSAFE=ON \ -DBUILD_CLAR=OFF \ -DUSE_SSH=OFF \ -DUSE_HTTPS=OFF \ -DCURL=OFF \ -DBUILD_SHARED_LIBS=OFF \ -DCMAKE_C_FLAGS=-fPIC \ -DCMAKE_INSTALL_PREFIX=../install \ -DCMAKE_BUILD_TYPE="MinSizeRel" \ .. && \ cmake --build . && \ make install ```
lhchavez (Migrated from github.com) reviewed 2018-07-07 18:12:11 -05:00
lhchavez (Migrated from github.com) commented 2018-07-07 18:12:10 -05:00

You can use cmake --build . --target install as in f463379110/script/cibuild.sh (L27)

You can use `cmake --build . --target install` as in https://github.com/libgit2/libgit2/blob/f4633791104fa5be75115fd4c7fab0c097da345e/script/cibuild.sh#L27
rmg commented 2018-08-23 12:53:09 -05:00 (Migrated from github.com)

@lhchavez thanks for the tip. I've incorporated it in to the PR.

@lhchavez thanks for the tip. I've incorporated it in to the PR.
carlosmn commented 2019-01-04 06:18:16 -06:00 (Migrated from github.com)

The builds keep working, so it doesn't look like it breaks the existing linking types. Ta.

The builds keep working, so it doesn't look like it breaks the existing linking types. Ta.
Sign in to join this conversation.
No reviewers
No Milestone
No project
No Assignees
1 Participants
Notifications
Due Date
The due date is invalid or out of range. Please use the format 'yyyy-mm-dd'.

No due date set.

Dependencies

No dependencies set.

Reference: jcarr/git2go#445
No description provided.