diff mbox series

[RFC,1/4] package/go: fixing crosscompilation settings

Message ID 1507207260-26734-1-git-send-email-angelo.compagnucci@gmail.com
State Superseded
Headers show
Series [RFC,1/4] package/go: fixing crosscompilation settings | expand

Commit Message

Angelo Compagnucci Oct. 5, 2017, 12:40 p.m. UTC
This patch fixes a bug with the BR2_TOOLCHAIN_HAS_THREADS variable
handling which causes CGO_ENABLED to be always 0.

Furthermore, it fixes the cross compilation options for the go compiler:
setting CGO_ENABLED should be done only for the target compiler not the
host one.

Signed-off-by: Angelo Compagnucci <angelo.compagnucci@gmail.com>
---
 package/go/go.mk | 14 ++++++++------
 1 file changed, 8 insertions(+), 6 deletions(-)

Comments

Yann E. MORIN Oct. 16, 2017, 4:56 p.m. UTC | #1
Angelo, All,

On 2017-10-05 14:40 +0200, Angelo Compagnucci spake thusly:
> This patch fixes a bug with the BR2_TOOLCHAIN_HAS_THREADS variable
> handling which causes CGO_ENABLED to be always 0.
> 
> Furthermore, it fixes the cross compilation options for the go compiler:
> setting CGO_ENABLED should be done only for the target compiler not the
> host one.
> 
> Signed-off-by: Angelo Compagnucci <angelo.compagnucci@gmail.com>
> ---
>  package/go/go.mk | 14 ++++++++------
>  1 file changed, 8 insertions(+), 6 deletions(-)
> 
> diff --git a/package/go/go.mk b/package/go/go.mk
> index 0781dff..8e510e7 100644
> --- a/package/go/go.mk
> +++ b/package/go/go.mk
> @@ -52,7 +52,7 @@ HOST_GO_TARGET_ENV = \
>  # set, build in cgo support for any go programs that may need it.  Note that
>  # any target package needing cgo support must include
>  # 'depends on BR2_TOOLCHAIN_HAS_THREADS' in its config file.
> -ifeq (BR2_TOOLCHAIN_HAS_THREADS,y)
> +ifeq ($(BR2_TOOLCHAIN_HAS_THREADS),y)

Indeed... Wonderfull that it passed through the cracks and stayed
unnoticed so far...

>  HOST_GO_CGO_ENABLED = 1
>  else
>  HOST_GO_CGO_ENABLED = 0
> @@ -74,8 +74,8 @@ HOST_GO_MAKE_ENV = \
>  	GOARCH=$(GO_GOARCH) \
>  	$(if $(GO_GOARM),GOARM=$(GO_GOARM)) \
>  	GOOS=linux \
> -	CGO_ENABLED=$(HOST_GO_CGO_ENABLED) \
> -	CC=$(HOSTCC_NOCCACHE)
> +	CC=$(HOSTCC_NOCCACHE) \
> +	CXX=$(HOSTCXX_NOCCACHE)
>  
>  HOST_GO_TARGET_CC = \
>  	CC_FOR_TARGET="$(TARGET_CC)" \
> @@ -83,16 +83,18 @@ HOST_GO_TARGET_CC = \
>  
>  HOST_GO_HOST_CC = \
>  	CC_FOR_TARGET=$(HOSTCC_NOCCACHE) \
> -	CXX_FOR_TARGET=$(HOSTCC_NOCCACHE)
> +	CXX_FOR_TARGET=$(HOSTCXX_NOCCACHE)
>  
>  HOST_GO_TMP = $(@D)/host-go-tmp
>  
>  define HOST_GO_BUILD_CMDS
> -	cd $(@D)/src && $(HOST_GO_MAKE_ENV) $(HOST_GO_HOST_CC) ./make.bash
> +	cd $(@D)/src && $(HOST_GO_MAKE_ENV) $(HOST_GO_HOST_CC) \
> +		CGO_ENABLED=0 ./make.bash

Can we use a more logical location to split the line (I don't care if
the second line is indented or not, but usually we do indent it):

    cd $(@D)/src && \
    $(HOST_GO_MAKE_ENV) $(HOST_GO_HOST_CC) CGO_ENABLED=0 ./make.bash

>  	mkdir -p $(HOST_GO_TMP)
>  	mv $(@D)/pkg/tool $(HOST_GO_TMP)/
>  	mv $(@D)/bin/ $(HOST_GO_TMP)/
> -	cd $(@D)/src && $(HOST_GO_MAKE_ENV) $(HOST_GO_TARGET_CC) ./make.bash
> +	cd $(@D)/src && $(HOST_GO_MAKE_ENV) $(HOST_GO_TARGET_CC) \
> +		CGO_ENABLED=$(HOST_GO_CGO_ENABLED) ./make.bash

Ditto?

Otherwise looks good:

Reviewed-by: "Yann E. MORIN" <yann.morin.1998@free.fr>

Can go in, even without the rest of the series, I think, no?

Regards,
Yann E. MORIN.

>  endef
>  
>  define HOST_GO_INSTALL_CMDS
> -- 
> 2.7.4
> 
> _______________________________________________
> buildroot mailing list
> buildroot@busybox.net
> http://lists.busybox.net/mailman/listinfo/buildroot
Angelo Compagnucci Oct. 16, 2017, 5:01 p.m. UTC | #2
Dear Yann,

2017-10-16 18:56 GMT+02:00 Yann E. MORIN <yann.morin.1998@free.fr>:
> Angelo, All,
>
> On 2017-10-05 14:40 +0200, Angelo Compagnucci spake thusly:
>> This patch fixes a bug with the BR2_TOOLCHAIN_HAS_THREADS variable
>> handling which causes CGO_ENABLED to be always 0.
>>
>> Furthermore, it fixes the cross compilation options for the go compiler:
>> setting CGO_ENABLED should be done only for the target compiler not the
>> host one.
>>
>> Signed-off-by: Angelo Compagnucci <angelo.compagnucci@gmail.com>
>> ---
>>  package/go/go.mk | 14 ++++++++------
>>  1 file changed, 8 insertions(+), 6 deletions(-)
>>
>> diff --git a/package/go/go.mk b/package/go/go.mk
>> index 0781dff..8e510e7 100644
>> --- a/package/go/go.mk
>> +++ b/package/go/go.mk
>> @@ -52,7 +52,7 @@ HOST_GO_TARGET_ENV = \
>>  # set, build in cgo support for any go programs that may need it.  Note that
>>  # any target package needing cgo support must include
>>  # 'depends on BR2_TOOLCHAIN_HAS_THREADS' in its config file.
>> -ifeq (BR2_TOOLCHAIN_HAS_THREADS,y)
>> +ifeq ($(BR2_TOOLCHAIN_HAS_THREADS),y)
>
> Indeed... Wonderfull that it passed through the cracks and stayed
> unnoticed so far...

We haven't right now in buildroot a software that really needs cgo. I'm
working with mender and noticed this bug straight.

>
>>  HOST_GO_CGO_ENABLED = 1
>>  else
>>  HOST_GO_CGO_ENABLED = 0
>> @@ -74,8 +74,8 @@ HOST_GO_MAKE_ENV = \
>>       GOARCH=$(GO_GOARCH) \
>>       $(if $(GO_GOARM),GOARM=$(GO_GOARM)) \
>>       GOOS=linux \
>> -     CGO_ENABLED=$(HOST_GO_CGO_ENABLED) \
>> -     CC=$(HOSTCC_NOCCACHE)
>> +     CC=$(HOSTCC_NOCCACHE) \
>> +     CXX=$(HOSTCXX_NOCCACHE)
>>
>>  HOST_GO_TARGET_CC = \
>>       CC_FOR_TARGET="$(TARGET_CC)" \
>> @@ -83,16 +83,18 @@ HOST_GO_TARGET_CC = \
>>
>>  HOST_GO_HOST_CC = \
>>       CC_FOR_TARGET=$(HOSTCC_NOCCACHE) \
>> -     CXX_FOR_TARGET=$(HOSTCC_NOCCACHE)
>> +     CXX_FOR_TARGET=$(HOSTCXX_NOCCACHE)
>>
>>  HOST_GO_TMP = $(@D)/host-go-tmp
>>
>>  define HOST_GO_BUILD_CMDS
>> -     cd $(@D)/src && $(HOST_GO_MAKE_ENV) $(HOST_GO_HOST_CC) ./make.bash
>> +     cd $(@D)/src && $(HOST_GO_MAKE_ENV) $(HOST_GO_HOST_CC) \
>> +             CGO_ENABLED=0 ./make.bash
>
> Can we use a more logical location to split the line (I don't care if
> the second line is indented or not, but usually we do indent it):

Will do

>
>     cd $(@D)/src && \
>     $(HOST_GO_MAKE_ENV) $(HOST_GO_HOST_CC) CGO_ENABLED=0 ./make.bash
>
>>       mkdir -p $(HOST_GO_TMP)
>>       mv $(@D)/pkg/tool $(HOST_GO_TMP)/
>>       mv $(@D)/bin/ $(HOST_GO_TMP)/
>> -     cd $(@D)/src && $(HOST_GO_MAKE_ENV) $(HOST_GO_TARGET_CC) ./make.bash
>> +     cd $(@D)/src && $(HOST_GO_MAKE_ENV) $(HOST_GO_TARGET_CC) \
>> +             CGO_ENABLED=$(HOST_GO_CGO_ENABLED) ./make.bash
>
> Ditto?

Will do.

>
> Otherwise looks good:
>
> Reviewed-by: "Yann E. MORIN" <yann.morin.1998@free.fr>
>
> Can go in, even without the rest of the series, I think, no?

Yes, no problem. For packages without cgo enabled don't change anything.

>
> Regards,
> Yann E. MORIN.
>
>>  endef
>>
>>  define HOST_GO_INSTALL_CMDS
>> --
>> 2.7.4
>>
>> _______________________________________________
>> buildroot mailing list
>> buildroot@busybox.net
>> http://lists.busybox.net/mailman/listinfo/buildroot
>
> --
> .-----------------.--------------------.------------------.--------------------.
> |  Yann E. MORIN  | Real-Time Embedded | /"\ ASCII RIBBON | Erics' conspiracy: |
> | +33 662 376 056 | Software  Designer | \ / CAMPAIGN     |  ___               |
> | +33 223 225 172 `------------.-------:  X  AGAINST      |  \e/  There is no  |
> | http://ymorin.is-a-geek.org/ | _/*\_ | / \ HTML MAIL    |   v   conspiracy.  |
> '------------------------------^-------^------------------^--------------------'
diff mbox series

Patch

diff --git a/package/go/go.mk b/package/go/go.mk
index 0781dff..8e510e7 100644
--- a/package/go/go.mk
+++ b/package/go/go.mk
@@ -52,7 +52,7 @@  HOST_GO_TARGET_ENV = \
 # set, build in cgo support for any go programs that may need it.  Note that
 # any target package needing cgo support must include
 # 'depends on BR2_TOOLCHAIN_HAS_THREADS' in its config file.
-ifeq (BR2_TOOLCHAIN_HAS_THREADS,y)
+ifeq ($(BR2_TOOLCHAIN_HAS_THREADS),y)
 HOST_GO_CGO_ENABLED = 1
 else
 HOST_GO_CGO_ENABLED = 0
@@ -74,8 +74,8 @@  HOST_GO_MAKE_ENV = \
 	GOARCH=$(GO_GOARCH) \
 	$(if $(GO_GOARM),GOARM=$(GO_GOARM)) \
 	GOOS=linux \
-	CGO_ENABLED=$(HOST_GO_CGO_ENABLED) \
-	CC=$(HOSTCC_NOCCACHE)
+	CC=$(HOSTCC_NOCCACHE) \
+	CXX=$(HOSTCXX_NOCCACHE)
 
 HOST_GO_TARGET_CC = \
 	CC_FOR_TARGET="$(TARGET_CC)" \
@@ -83,16 +83,18 @@  HOST_GO_TARGET_CC = \
 
 HOST_GO_HOST_CC = \
 	CC_FOR_TARGET=$(HOSTCC_NOCCACHE) \
-	CXX_FOR_TARGET=$(HOSTCC_NOCCACHE)
+	CXX_FOR_TARGET=$(HOSTCXX_NOCCACHE)
 
 HOST_GO_TMP = $(@D)/host-go-tmp
 
 define HOST_GO_BUILD_CMDS
-	cd $(@D)/src && $(HOST_GO_MAKE_ENV) $(HOST_GO_HOST_CC) ./make.bash
+	cd $(@D)/src && $(HOST_GO_MAKE_ENV) $(HOST_GO_HOST_CC) \
+		CGO_ENABLED=0 ./make.bash
 	mkdir -p $(HOST_GO_TMP)
 	mv $(@D)/pkg/tool $(HOST_GO_TMP)/
 	mv $(@D)/bin/ $(HOST_GO_TMP)/
-	cd $(@D)/src && $(HOST_GO_MAKE_ENV) $(HOST_GO_TARGET_CC) ./make.bash
+	cd $(@D)/src && $(HOST_GO_MAKE_ENV) $(HOST_GO_TARGET_CC) \
+		CGO_ENABLED=$(HOST_GO_CGO_ENABLED) ./make.bash
 endef
 
 define HOST_GO_INSTALL_CMDS