Blob Blame History Raw
# Generated by go2rpm
%bcond_without check

%global __brp_strip_static_archive %{nil}

# https://github.com/tinygo-org/tinygo
%global goipath         github.com/tinygo-org/tinygo
Version:                0.6.0

%global CMSIS_commit        9fe411cef1cef5de58e5957b89760759de44e393
%global avr_commit          6624554c02b237b23dc17d53e992bf54033fc228
%global clang_version       8.0.0
%global cmsis_svd_commit    b6f0a65ac37760f52d6ade23dd3205424d6c91fa
%global compiler_rt_version 8.0.0
%global nrfx_commit         3ab39a9d457bfe627473ed0e03a7f1161d9e4f27

# To match regular Go's /usr/share/gocode
%global tinygoroot %{_prefix}/share/tinygo

%gometa

%global common_description %{expand:
Go compiler for small places. Microcontrollers, WebAssembly, and command-line
tools. Based on LLVM.}

#global godocs CHANGELOG.md BUILDING.md CONTRIBUTING.md README.md
#global golicenses LICENSE LICENSE.TXT
#global gosupfiles lib/CMSIS/CMSIS/Include/*.h lib/compiler-rt/lib/builtins/*/*.S lib/nrfx/mdk/*.{ld,S} src/examples/wasm/*/*.js targets/*.{js,json,ld,S}

Name:           tinygo
Release:        1%{?dist}
Summary:        Go compiler for small places

# Main files: BSD
# CMSIS: BSD (subsetted)
# avr-mcu: ASL 2.0 (packs) and MIT (Rust code, unused by this package)
# cmsis-svd: ASL 2.0 (subsetted)
# compiler-rt: NCSA or MIT
# nrfx: BSD and ASL 2.0
License:        BSD and MIT and (NCSA or MIT) and ASL 2.0
URL:            %{gourl}
Source0:        %{gosource}
Source1:        clean_tarballs.sh
Source2:        cmsis-%{CMSIS_commit}-clean.tar.xz
Source3:        https://github.com/avr-rust/avr-mcu/archive/%{avr_commit}/avr-%{avr_commit}.tar.gz
Source4:        cmsis_svd-%{cmsis_svd_commit}-clean.tar.xz
Source5:        https://releases.llvm.org/%{compiler_rt_version}/compiler-rt-%{compiler_rt_version}.src.tar.xz
Source6:        https://github.com/NordicSemiconductor/nrfx/archive/%{nrfx_commit}/nrfx-%{nrfx_commit}.tar.gz
# Fedora-specific.
Patch0001:      0001-Use-system-path-for-TINYGOROOT-default.patch
Patch0002:      0002-Use-Fedora-command-names.patch
# We don't have ARM glibc to build these.
Patch0003:      0003-Skip-ARM-Linux-tests.patch
# We can't include STM32 .svd files because of their weird license.
Patch0004:      0004-Skip-STM32-tests.patch

# Not supported upstream yet.
ExcludeArch:    %{ix86} armv7hl ppc64le s390x

BuildRequires:  clang-devel = %{clang_version}
BuildRequires:  golang(github.com/blakesmith/ar)
BuildRequires:  golang(github.com/marcinbor85/gohex)
BuildRequires:  golang(golang.org/x/tools/go/ast/astutil)
BuildRequires:  golang(golang.org/x/tools/go/ssa)
BuildRequires:  golang(tinygo.org/x/go-llvm)

# We don't have glibc for arm, so skip these.
#BuildRequires:  gcc-arm-linux-gnu
#BuildRequires:  gcc-aarch64-linux-gnu
BuildRequires:  lld
BuildRequires:  nodejs
BuildRequires:  qemu-system-arm-core

Requires:       clang-libs%{?isa} = %{clang_version}
Requires:       golang
Requires:       lld
Recommends:     clang
Recommends:     qemu-system-arm-core

%description
%{common_description}

#gopkg


%prep
%goprep
%patch0001 -p1
%patch0002 -p1
%patch0003 -p1
%patch0004 -p1

tar -C lib -xf %{SOURCE2}
rmdir lib/CMSIS
mv lib/CMSIS-%{CMSIS_commit} lib/CMSIS

tar -C lib -xf %{SOURCE3}
rmdir lib/avr
mv lib/avr-mcu-%{avr_commit} lib/avr

tar -C lib -xf %{SOURCE4}
rmdir lib/cmsis-svd
mv lib/cmsis-svd-%{cmsis_svd_commit} lib/cmsis-svd

tar -C lib -xf %{SOURCE5}
rmdir lib/compiler-rt
mv lib/compiler-rt-%{compiler_rt_version}.src lib/compiler-rt

tar -C lib -xf %{SOURCE6}
rmdir lib/nrfx
mv lib/nrfx-%{nrfx_commit} lib/nrfx
rm lib/nrfx/.gitignore
chmod -x lib/nrfx/doc/generate_html_doc.sh

mkdir lib/clang
ln -s /usr/lib64/clang/%{clang_version}/include lib/clang/include


%build
%gobuild -o %{gobuilddir}/bin/tinygo %{goipath}
GO111MODULE=off make gen-device
for target in armv6m-none-eabi armv7m-none-eabi armv7em-none-eabi; do
    TINYGOROOT=$PWD \
        %{gobuilddir}/bin/tinygo \
            build-builtins -target=$target -o ${target}-compiler-rt.a
done


%install
#gopkginstall
install -vdm 0755                     %{buildroot}%{_bindir}
install -vpm 0755 %{gobuilddir}/bin/* %{buildroot}%{_bindir}/

install -vdm 0755 %{buildroot}%{tinygoroot}
install -vdm 0755 %{buildroot}%{tinygoroot}/lib
install -vdm 0755 %{buildroot}%{tinygoroot}/lib/CMSIS
install -vpm 0644 lib/CMSIS/README.md %{buildroot}%{tinygoroot}/lib/CMSIS/
install -vdm 0755 %{buildroot}%{tinygoroot}/lib/CMSIS/CMSIS/Include
install -vpm 0644 lib/CMSIS/CMSIS/Include/* %{buildroot}%{tinygoroot}/lib/CMSIS/CMSIS/Include/
install -vdm 0755 %{buildroot}%{tinygoroot}/lib/clang
cp -pP lib/clang/include %{buildroot}%{tinygoroot}/lib/clang/
install -vdm 0755 %{buildroot}%{tinygoroot}/lib/compiler-rt
install -vpm 0644 lib/compiler-rt/README.txt %{buildroot}%{tinygoroot}/lib/compiler-rt/
install -vpm 0644 lib/compiler-rt/LICENSE.TXT %{buildroot}%{tinygoroot}/lib/compiler-rt/
install -vdm 0755 %{buildroot}%{tinygoroot}/lib/compiler-rt/lib
cp -rp lib/compiler-rt/lib/builtins %{buildroot}%{tinygoroot}/lib/compiler-rt/lib/
cp -rp lib/nrfx %{buildroot}%{tinygoroot}/lib/
install -vdm 0755 %{buildroot}%{tinygoroot}/pkg
for target in armv6m-none-eabi armv7m-none-eabi armv7em-none-eabi; do
    install -vdm 0755 %{buildroot}%{tinygoroot}/pkg/${target}
    install -vpm 0644 ${target}-compiler-rt.a %{buildroot}%{tinygoroot}/pkg/${target}/compiler-rt.a
done
cp -rp src %{buildroot}%{tinygoroot}/
rm %{buildroot}%{tinygoroot}/src/examples/wasm/.gitignore
cp -rp targets %{buildroot}%{tinygoroot}/


%if %{with check}
%check
export TINYGOROOT=%{buildroot}%{tinygoroot}
export GOPATH=%{buildroot}%{tinygoroot}
# Fedora LLVM doesn't support AVR yet, so don't run full suite.
# https://bugzilla.redhat.com/show_bug.cgi?id=1718492
PATH=%{buildroot}%{_bindir}:$PATH make smoketest-no-avr
%gocheck -v
%endif


%files
%doc README.md CHANGELOG.md CONTRIBUTING.md
%license LICENSE
%{_bindir}/tinygo
%{tinygoroot}
%doc %{tinygoroot}/lib/CMSIS/README.md
%license %{tinygoroot}/lib/compiler-rt/LICENSE.TXT
%doc %{tinygoroot}/lib/compiler-rt/README.txt
%license %{tinygoroot}/lib/nrfx/LICENSE
%doc %{tinygoroot}/lib/nrfx/README.md

#gopkgfiles


%changelog
* Tue Jun 11 01:26:10 EDT 2019 Elliott Sales de Andrade <quantum.analyst@gmail.com> - 0.6.0-1
- Initial package