Discussion:
[Buildroot] [Patch v6 0/7] Add support for the Rust programming language
Eric Le Bihan
2017-06-25 20:56:07 UTC
Permalink
This series adds support for the Rust programming language by adding the
following packages:

- rustc: a virtual package for the Rust compiler.
- rust-bin: provides a pre-built version of rustc.
- rust: builds rustc from source.

Both providers are able to cross-compile code for ARM, MIPS, PowerPC and
x86_64 architectures. Only the host variants are provided.

The rustc virtual package is inspired by the mysql one.

As the Rust compiler is written in Rust and uses Cargo, the Rust package
manager, as build system, two additional packages are provided: rust-bootstrap
and cargo-bootstrap.

v5 -> v6:

- bump rust to 1.18.0
- bump rust-bootstrap to 1.17.0
- bump rust-bin to 1.18.0

v4 -> v5:

- add rustc virtual package
- add rust-bin, provider for rustc
- rework rust to be a provider for rustc
- rework some commit messages

v3 -> v4:

- bump rust to 1.16.0
- bump rust-bootstrap to 1.15.1
- add cargo-bootstrap
- use built-in target specifications
- drop external Python script to generate target specifications
- enable support for PowerPC
- expose host variant in menuconfig

v2 -> v3:

- bump rust to 1.10.0
- rework and bump rust-bootstrap to 1.9.0
- host-rust requires at least GCC 4.7 because of LLVM (suggested by R. Naour)
- rust requires a glibc-based cross-compiler
- rust requires GCC 5.x or above for Aarch64

v1 -> v2:

- bump rust to version 1.9.0.
- drop patch for bzip2 support in host-python.
- add package for jemalloc.
- add dependency on host being a x86 machine.
- add dependency on toolchain.
- use dedicated package to provide bootstrapping binary: rust-bootstrap.
- let ./configure find out host/build on its own.
- remove entry from configuration menu.
- clarify some comments.
Eric Le Bihan (7):
pkg-virtual: fix host dependencies handling
rustc: new virtual package
rust-bin: new package
rustc: expose host variant in menuconfig
rust-bootstrap: new package
cargo-bootstrap: new package
rust: new package

DEVELOPERS | 4 ++
package/Config.in.host | 1 +
package/cargo-bootstrap/cargo-bootstrap.hash | 3 ++
package/cargo-bootstrap/cargo-bootstrap.mk | 14 +++++
package/pkg-virtual.mk | 4 ++
package/rust-bin/rust-bin.hash | 30 +++++++++++
package/rust-bin/rust-bin.mk | 41 +++++++++++++++
package/rust-bootstrap/rust-bootstrap.hash | 8 +++
package/rust-bootstrap/rust-bootstrap.mk | 27 ++++++++++
package/rust/rust.hash | 2 +
package/rust/rust.mk | 77 ++++++++++++++++++++++++++++
package/rustc/Config.in.host | 61 ++++++++++++++++++++++
package/rustc/rustc.mk | 21 ++++++++
13 files changed, 293 insertions(+)
create mode 100644 package/cargo-bootstrap/cargo-bootstrap.hash
create mode 100644 package/cargo-bootstrap/cargo-bootstrap.mk
create mode 100644 package/rust-bin/rust-bin.hash
create mode 100644 package/rust-bin/rust-bin.mk
create mode 100644 package/rust-bootstrap/rust-bootstrap.hash
create mode 100644 package/rust-bootstrap/rust-bootstrap.mk
create mode 100644 package/rust/rust.hash
create mode 100644 package/rust/rust.mk
create mode 100644 package/rustc/Config.in.host
create mode 100644 package/rustc/rustc.mk
--
2.9.4
Eric Le Bihan
2017-06-25 20:56:08 UTC
Permalink
If $(BR2_PACKAGE_HAS_HOST_FOO) is defined, then the pkg-virtual
infrastructure will check if $(BR2_PACKAGE_PROVIDES_HOST_FOO) is not
empty.

But later, $(BR2_PACKAGE_HOST_FOO_DEPENDENCIES) will be set from
$(BR2_PACKAGE_PROVIDES_FOO), ignoring $(BR2_PACKAGE_PROVIDES_HOST_FOO).

So fix this discrepancy by setting $(BR2_PACKAGE_HOST_FOO_DEPENDENCIES)
from $(BR2_PACKAGE_PROVIDES_FOO) only if $(BR2_PACKAGE_PROVIDES_HOST_FOO)
is empty.

Signed-off-by: Eric Le Bihan <***@free.fr>
---
package/pkg-virtual.mk | 4 ++++
1 file changed, 4 insertions(+)

diff --git a/package/pkg-virtual.mk b/package/pkg-virtual.mk
index 2e83e07..b8878ad 100644
--- a/package/pkg-virtual.mk
+++ b/package/pkg-virtual.mk
@@ -49,7 +49,11 @@ $(2)_IS_VIRTUAL = YES
ifeq ($(4),target)
$(2)_DEPENDENCIES += $$(call qstrip,$$(BR2_PACKAGE_PROVIDES_$(2)))
else
+ifeq ($$(call qstrip,$$(BR2_PACKAGE_PROVIDES_$(2))),)
$(2)_DEPENDENCIES += host-$$(call qstrip,$$(BR2_PACKAGE_PROVIDES_$(3)))
+else
+$(2)_DEPENDENCIES += $$(call qstrip,$$(BR2_PACKAGE_PROVIDES_$(2)))
+endif
endif

# Call the generic package infrastructure to generate the necessary
--
2.9.4
Arnout Vandecappelle
2017-07-01 13:07:23 UTC
Permalink
Post by Eric Le Bihan
If $(BR2_PACKAGE_HAS_HOST_FOO) is defined, then the pkg-virtual
infrastructure will check if $(BR2_PACKAGE_PROVIDES_HOST_FOO) is not
empty.
But later, $(BR2_PACKAGE_HOST_FOO_DEPENDENCIES) will be set from
$(BR2_PACKAGE_PROVIDES_FOO), ignoring $(BR2_PACKAGE_PROVIDES_HOST_FOO).
So fix this discrepancy by setting $(BR2_PACKAGE_HOST_FOO_DEPENDENCIES)
from $(BR2_PACKAGE_PROVIDES_FOO) only if $(BR2_PACKAGE_PROVIDES_HOST_FOO)
is empty.
---
package/pkg-virtual.mk | 4 ++++
1 file changed, 4 insertions(+)
diff --git a/package/pkg-virtual.mk b/package/pkg-virtual.mk
index 2e83e07..b8878ad 100644
--- a/package/pkg-virtual.mk
+++ b/package/pkg-virtual.mk
@@ -49,7 +49,11 @@ $(2)_IS_VIRTUAL = YES
ifeq ($(4),target)
$(2)_DEPENDENCIES += $$(call qstrip,$$(BR2_PACKAGE_PROVIDES_$(2)))
else
+ifeq ($$(call qstrip,$$(BR2_PACKAGE_PROVIDES_$(2))),)
This is a bit difficult to grok, so perhaps add

# Inherit from target package BR2_PACKAGE_PROVIDES_FOO
Post by Eric Le Bihan
$(2)_DEPENDENCIES += host-$$(call qstrip,$$(BR2_PACKAGE_PROVIDES_$(3)))
+else
# BR2_PACKAGE_PROVIDES_HOST_FOO is explicitly defined


Regards,
Arnout
Post by Eric Le Bihan
+$(2)_DEPENDENCIES += $$(call qstrip,$$(BR2_PACKAGE_PROVIDES_$(2)))
+endif
endif
# Call the generic package infrastructure to generate the necessary
--
Arnout Vandecappelle arnout at mind be
Senior Embedded Software Architect +32-16-286500
Essensium/Mind http://www.mind.be
G.Geenslaan 9, 3001 Leuven, Belgium BE 872 984 063 RPR Leuven
LinkedIn profile: http://www.linkedin.com/in/arnoutvandecappelle
GPG fingerprint: 7493 020B C7E3 8618 8DEC 222C 82EB F404 F9AC 0DDF
Thomas Petazzoni
2017-07-02 21:40:31 UTC
Permalink
Hello,
Post by Eric Le Bihan
If $(BR2_PACKAGE_HAS_HOST_FOO) is defined, then the pkg-virtual
infrastructure will check if $(BR2_PACKAGE_PROVIDES_HOST_FOO) is not
empty.
But later, $(BR2_PACKAGE_HOST_FOO_DEPENDENCIES) will be set from
$(BR2_PACKAGE_PROVIDES_FOO), ignoring $(BR2_PACKAGE_PROVIDES_HOST_FOO).
So fix this discrepancy by setting $(BR2_PACKAGE_HOST_FOO_DEPENDENCIES)
from $(BR2_PACKAGE_PROVIDES_FOO) only if $(BR2_PACKAGE_PROVIDES_HOST_FOO)
is empty.
---
package/pkg-virtual.mk | 4 ++++
1 file changed, 4 insertions(+)
Applied to master, after adding the comments suggested by Arnout.

Best regards,

Thomas
--
Thomas Petazzoni, CTO, Free Electrons
Embedded Linux, Kernel and Android engineering
http://free-electrons.com
Eric Le Bihan
2017-06-25 20:56:09 UTC
Permalink
The compiler for the Rust programming language is called rustc.

There is only one reference implementation for it, based on LLVM, from
the Rust project [1]. It can generate code for various architectures so
it can be labeled as a cross-compiler. But, as for GCC, building it
from source takes time.

So it would be sensible to have at least one package which provides it
as a pre-built version, fetched from the upstream project. Later another
package can be added, to build it from source code.

In addition to the compiler, the standard library for the host and/or
the target should also be fetched/built.

So, add a virtual package named rustc to enable support for multiple
providers.

Currently, only the host variant will be available to allow the user to
cross-compile Rust programs for the target.

[1] http://rust-lang.org

Signed-off-by: Eric Le Bihan <***@free.fr>
---
package/rustc/Config.in.host | 5 +++++
package/rustc/rustc.mk | 21 +++++++++++++++++++++
2 files changed, 26 insertions(+)
create mode 100644 package/rustc/Config.in.host
create mode 100644 package/rustc/rustc.mk

diff --git a/package/rustc/Config.in.host b/package/rustc/Config.in.host
new file mode 100644
index 0000000..fef78a7
--- /dev/null
+++ b/package/rustc/Config.in.host
@@ -0,0 +1,5 @@
+config BR2_PACKAGE_HAS_HOST_RUSTC
+ bool
+
+config BR2_PACKAGE_PROVIDES_HOST_RUSTC
+ string
diff --git a/package/rustc/rustc.mk b/package/rustc/rustc.mk
new file mode 100644
index 0000000..fc743fa
--- /dev/null
+++ b/package/rustc/rustc.mk
@@ -0,0 +1,21 @@
+################################################################################
+#
+# rustc
+#
+################################################################################
+
+RUST_TARGET_NAME := $(subst buildroot,unknown,$(GNU_TARGET_NAME))
+
+ifeq ($(BR2_ARM_CPU_ARMV7A),y)
+RUST_TARGET_NAME := $(subst arm-,armv7-,$(RUST_TARGET_NAME))
+endif
+
+ifeq ($(HOSTARCH),x86_64)
+RUST_HOST_ARCH = x86_64
+else ifeq ($(HOSTARCH),x86)
+RUST_HOST_ARCH = i686
+endif
+
+RUST_HOST_NAME = $(RUST_HOST_ARCH)-unknown-linux-gnu
+
+$(eval $(host-virtual-package))
--
2.9.4
Eric Le Bihan
2017-06-25 20:56:10 UTC
Permalink
This package provides a pre-built version of rustc, the compiler for the
Rust programming language, fetched from the upstream project.

A pre-built version of the standard library for the host as well as one
for the chosen target are also fetched and installed.

Only the host variant is provided to allow the user to cross-compile
Rust programs and run them on the target.

The menuconfig entry for rustc is also updated to expose this provider.

Signed-off-by: Eric Le Bihan <***@free.fr>
---
DEVELOPERS | 1 +
package/rust-bin/rust-bin.hash | 30 ++++++++++++++++++++++++++++++
package/rust-bin/rust-bin.mk | 41 +++++++++++++++++++++++++++++++++++++++++
package/rustc/Config.in.host | 41 +++++++++++++++++++++++++++++++++++++++++
4 files changed, 113 insertions(+)
create mode 100644 package/rust-bin/rust-bin.hash
create mode 100644 package/rust-bin/rust-bin.mk

diff --git a/DEVELOPERS b/DEVELOPERS
index 9e421f4..6ab48ba 100644
--- a/DEVELOPERS
+++ b/DEVELOPERS
@@ -483,6 +483,7 @@ F: package/execline/
F: package/hicolor-icon-theme/
F: package/jemalloc/
F: package/ninja/
+F: package/rust-bin/
F: package/s6/
F: package/s6-dns/
F: package/s6-linux-init/
diff --git a/package/rust-bin/rust-bin.hash b/package/rust-bin/rust-bin.hash
new file mode 100644
index 0000000..6a56e99
--- /dev/null
+++ b/package/rust-bin/rust-bin.hash
@@ -0,0 +1,30 @@
+# From https://static.rust-lang.org/dist/rustc-1.18.0-i686-unknown-linux-gnu.tar.gz.sha256
+sha256 0cb9bb95373cee8ba26e8f517c46f8c58a29e22f2c7c08a4d152306c6ffc7115 rustc-1.18.0-i686-unknown-linux-gnu.tar.gz
+# From https://static.rust-lang.org/dist/rustc-1.18.0-x86_64-unknown-linux-gnu.tar.gz.sha256
+sha256 f2a34e20166ccf6eda4de46a9efb02821df5c3f34667e2988284a8eaee408113 rustc-1.18.0-x86_64-unknown-linux-gnu.tar.gz
+# From https://static.rust-lang.org/dist/rust-std-1.18.0-aarch64-unknown-linux-gnu.tar.gz.sha256
+sha256 1a6b33f8bce7637fe038667cd82dda60a69fe319adf3820f621670ef9d75af2b rust-std-1.18.0-aarch64-unknown-linux-gnu.tar.gz
+# From https://static.rust-lang.org/dist/rust-std-1.18.0-arm-unknown-linux-gnueabi.tar.gz.sha256
+sha256 8da327ff42cf895ff341bca862f8a235c1bd78e473464183bff85ceccdfa3a91 rust-std-1.18.0-arm-unknown-linux-gnueabi.tar.gz
+# From https://static.rust-lang.org/dist/rust-std-1.18.0-arm-unknown-linux-gnueabihf.tar.gz.sha256
+sha256 8cf92d8a4f6c04f66edafbbfd1ad12839bcc0ee1477b2ccdaeb43fb81788c4fc rust-std-1.18.0-arm-unknown-linux-gnueabihf.tar.gz
+# From https://static.rust-lang.org/dist/rust-std-1.18.0-armv7-unknown-linux-gnueabihf.tar.gz.sha256
+sha256 bafef1cc817fc0b6fcc06d19fc9a28638d7a85dd6c2345a803c4c89d3ed89a9f rust-std-1.18.0-armv7-unknown-linux-gnueabihf.tar.gz
+# From https://static.rust-lang.org/dist/rust-std-1.18.0-i686-unknown-linux-gnu.tar.gz.sha256
+sha256 3b93c7b856b98f61ec0f640bc96373f4762484ab3340866902c8c96933bcf10b rust-std-1.18.0-i686-unknown-linux-gnu.tar.gz
+# From https://static.rust-lang.org/dist/rust-std-1.18.0-mips-unknown-linux-gnu.tar.gz.sha256
+sha256 312bc9444d3b43a78fc82755f84ccf6b692778233983546c4616e08419a06bb0 rust-std-1.18.0-mips-unknown-linux-gnu.tar.gz
+# From https://static.rust-lang.org/dist/rust-std-1.18.0-mips64-unknown-linux-gnuabi64.tar.gz.sha256
+sha256 86bd6c2a364359b8c749b31f4ec9a2de0d6d4af72582c4edab80e443b59f06f6 rust-std-1.18.0-mips64-unknown-linux-gnuabi64.tar.gz
+# From https://static.rust-lang.org/dist/rust-std-1.18.0-mips64el-unknown-linux-gnuabi64.tar.gz.sha256
+sha256 d3af657644a6e4a4d2285a522f5189f5722c78f59fc17f36f2b0487e374cf829 rust-std-1.18.0-mips64el-unknown-linux-gnuabi64.tar.gz
+# From https://static.rust-lang.org/dist/rust-std-1.18.0-mipsel-unknown-linux-gnu.tar.gz.sha256
+sha256 76b14be2770bff9945a16f95e23f6bf0bbd921b9529b9cfdb5c7569f312746c8 rust-std-1.18.0-mipsel-unknown-linux-gnu.tar.gz
+# From https://static.rust-lang.org/dist/rust-std-1.18.0-powerpc-unknown-linux-gnu.tar.gz.sha256
+sha256 8716a44ee1be60500e9cc1460f12f211e1ae84ddf50dd6f05faafe13478962c0 rust-std-1.18.0-powerpc-unknown-linux-gnu.tar.gz
+# From https://static.rust-lang.org/dist/rust-std-1.18.0-powerpc64-unknown-linux-gnu.tar.gz.sha256
+sha256 3572c3477271c61e816ac030277eb1aa7a948e34af00b8a2d6eb73a367220e66 rust-std-1.18.0-powerpc64-unknown-linux-gnu.tar.gz
+# From https://static.rust-lang.org/dist/rust-std-1.18.0-powerpc64le-unknown-linux-gnu.tar.gz.sha256
+sha256 60deedd6f61c7460231067bf1e0fbf5aff1666e6be581f8ab73df9016e84e47d rust-std-1.18.0-powerpc64le-unknown-linux-gnu.tar.gz
+# From https://static.rust-lang.org/dist/rust-std-1.18.0-x86_64-unknown-linux-gnu.tar.gz.sha256
+sha256 4a66150781e224412ebd9dd6d643ad65ecc5668a7754e4a12e115be6ce7bf527 rust-std-1.18.0-x86_64-unknown-linux-gnu.tar.gz
diff --git a/package/rust-bin/rust-bin.mk b/package/rust-bin/rust-bin.mk
new file mode 100644
index 0000000..2f4bdff
--- /dev/null
+++ b/package/rust-bin/rust-bin.mk
@@ -0,0 +1,41 @@
+################################################################################
+#
+# rust-bin
+#
+################################################################################
+
+RUST_BIN_VERSION = 1.18.0
+RUST_BIN_SITE = https://static.rust-lang.org/dist
+RUST_BIN_LICENSE = Apache-2.0 or MIT
+RUST_BIN_LICENSE_FILES = LICENSE-APACHE LICENSE-MIT
+
+HOST_RUST_BIN_PROVIDES = host-rustc
+
+HOST_RUST_BIN_SOURCE = rustc-$(RUST_BIN_VERSION)-$(RUST_HOST_NAME).tar.gz
+HOST_RUST_BIN_LIBSTD_SOURCES = \
+ rust-std-$(RUST_BIN_VERSION)-$(RUST_HOST_NAME).tar.gz \
+ rust-std-$(RUST_BIN_VERSION)-$(RUST_TARGET_NAME).tar.gz
+
+HOST_RUST_BIN_EXTRA_DOWNLOADS = $(HOST_RUST_BIN_LIBSTD_SOURCES)
+
+define HOST_RUST_BIN_LIBSTD_EXTRACT
+ mkdir -p $(@D)/std
+ for file in $(addprefix $(DL_DIR)/,$(HOST_RUST_BIN_LIBSTD_SOURCES)); do \
+ $(TAR) -C $(@D)/std -xzf $${file}; \
+ done
+endef
+
+HOST_RUST_BIN_POST_EXTRACT_HOOKS += HOST_RUST_BIN_LIBSTD_EXTRACT
+
+define HOST_RUST_BIN_INSTALL_CMDS
+ for exe in $$(find $(@D) -name install.sh -executable); do \
+ $${exe} \
+ --prefix=$(HOST_DIR)/usr \
+ --docdir=$(HOST_DIR)/usr/share/doc/rust \
+ --libdir=$(HOST_DIR)/usr/lib \
+ --mandir=$(HOST_DIR)/usr/share/man \
+ --disable-ldconfig; \
+ done
+endef
+
+$(eval $(host-generic-package))
diff --git a/package/rustc/Config.in.host b/package/rustc/Config.in.host
index fef78a7..7f2c276 100644
--- a/package/rustc/Config.in.host
+++ b/package/rustc/Config.in.host
@@ -1,5 +1,46 @@
+config BR2_PACKAGE_HOST_RUSTC_ARCH_SUPPORTS
+ bool
+ default y
+ depends on BR2_HOSTARCH = "x86_64" || BR2_HOSTARCH = "x86"
+ depends on BR2_i386 || BR2_x86_64 \
+ || BR2_arm || BR2_aarch64 \
+ || BR2_powerpc || BR2_powerpc64 \
+ || BR2_mips || BR2_mipsel || BR2_mips64 || BR2_mips64el
+ depends on !BR2_ARM_CPU_ARMV4 && !BR2_ARM_CPU_ARMV5
+ depends on !BR2_MIPS_NABI32
+ depends on BR2_TOOLCHAIN_USES_GLIBC
+
+config BR2_PACKAGE_HOST_RUSTC
+ bool "host rustc"
+ depends on BR2_PACKAGE_HOST_RUSTC_ARCH_SUPPORTS
+ help
+ Select the desired provider for the Rust compiler.
+
+ http://www.rust-lang.org
+
+if BR2_PACKAGE_HOST_RUSTC
+
+choice
+ prompt "Rust compiler variant"
+ default BR2_PACKAGE_HOST_RUST_BIN
+ help
+ Choose a provider for the Rust compiler.
+
+config BR2_PACKAGE_HOST_RUST_BIN
+ bool "host rust (pre-built)"
+ select BR2_PACKAGE_HAS_HOST_RUSTC
+ help
+ This package will install pre-built versions of the compiler
+ for the host and the Rust standard library for the target.
+
+endchoice
+
config BR2_PACKAGE_HAS_HOST_RUSTC
bool

config BR2_PACKAGE_PROVIDES_HOST_RUSTC
string
+ default "host-rust-bin" if BR2_PACKAGE_HOST_RUST_BIN
+
+endif
+
--
2.9.4
Eric Le Bihan
2017-06-25 20:56:11 UTC
Permalink
Now that one provider is available for rustc, expose the host variant in
menuconfig.

Signed-off-by: Eric Le Bihan <***@free.fr>
---
package/Config.in.host | 1 +
1 file changed, 1 insertion(+)

diff --git a/package/Config.in.host b/package/Config.in.host
index 38f919a..49fcdb0 100644
--- a/package/Config.in.host
+++ b/package/Config.in.host
@@ -39,6 +39,7 @@ menu "Host utilities"
source "package/python-lxml/Config.in.host"
source "package/qemu/Config.in.host"
source "package/raspberrypi-usbboot/Config.in.host"
+ source "package/rustc/Config.in.host"
source "package/s6-rc/Config.in.host"
source "package/sam-ba/Config.in.host"
source "package/squashfs/Config.in.host"
--
2.9.4
Eric Le Bihan
2017-06-25 20:56:12 UTC
Permalink
This new package fetches a binary snapshot of the Rust compiler,
suitable to bootstrap the host variant of the Rust compiler.

To bootstrap rustc version N, rustc N-1 is used.

Signed-off-by: Eric Le Bihan <***@free.fr>
---
DEVELOPERS | 1 +
package/rust-bootstrap/rust-bootstrap.hash | 8 ++++++++
package/rust-bootstrap/rust-bootstrap.mk | 27 +++++++++++++++++++++++++++
3 files changed, 36 insertions(+)
create mode 100644 package/rust-bootstrap/rust-bootstrap.hash
create mode 100644 package/rust-bootstrap/rust-bootstrap.mk

diff --git a/DEVELOPERS b/DEVELOPERS
index 6ab48ba..ddcaadd 100644
--- a/DEVELOPERS
+++ b/DEVELOPERS
@@ -484,6 +484,7 @@ F: package/hicolor-icon-theme/
F: package/jemalloc/
F: package/ninja/
F: package/rust-bin/
+F: package/rust-bootstrap/
F: package/s6/
F: package/s6-dns/
F: package/s6-linux-init/
diff --git a/package/rust-bootstrap/rust-bootstrap.hash b/package/rust-bootstrap/rust-bootstrap.hash
new file mode 100644
index 0000000..8533019
--- /dev/null
+++ b/package/rust-bootstrap/rust-bootstrap.hash
@@ -0,0 +1,8 @@
+# From https://static.rust-lang.org/dist/rustc-1.17.0-i686-unknown-linux-gnu.tar.gz.sha256
+sha256 9d3e3ff343f22b5288676b40d6749ebeabea863fa9e6009fbc5a018ede83c57c rustc-1.17.0-i686-unknown-linux-gnu.tar.gz
+# From https://static.rust-lang.org/dist/rustc-1.17.0-x86_64-unknown-linux-gnu.tar.gz.sha256
+sha256 3eebd92512040baf3c0974c3ce61859646d8cf422cc515d724d857577da0dbd5 rustc-1.17.0-x86_64-unknown-linux-gnu.tar.gz
+# From https://static.rust-lang.org/dist/rust-std-1.17.0-x86_64-unknown-linux-gnu.tar.gz.sha256
+sha256 2902bb0da78208f441f1d983aeafcad01ea653d2e062a8192892868e2b41130d rust-std-1.17.0-x86_64-unknown-linux-gnu.tar.gz
+# From https://static.rust-lang.org/dist/rust-std-1.17.0-i686-unknown-linux-gnu.tar.gz.sha256
+sha256 3dbaa44a07b14e5af05633c5f1a7d6b0538c6f8fa404ee6d3f85714d4f2bf39b rust-std-1.17.0-i686-unknown-linux-gnu.tar.gz
diff --git a/package/rust-bootstrap/rust-bootstrap.mk b/package/rust-bootstrap/rust-bootstrap.mk
new file mode 100644
index 0000000..930f32c
--- /dev/null
+++ b/package/rust-bootstrap/rust-bootstrap.mk
@@ -0,0 +1,27 @@
+################################################################################
+#
+# rust-bootstrap
+#
+################################################################################
+
+RUST_BOOTSTRAP_VERSION = 1.17.0
+RUST_BOOTSTRAP_SITE = https://static.rust-lang.org/dist
+
+RUST_BOOTSTRAP_SOURCE = rustc-$(RUST_BOOTSTRAP_VERSION)-$(RUST_HOST_NAME).tar.gz
+RUST_BOOTSTRAP_LICENSE = Apache-2.0 or MIT
+RUST_BOOTSTRAP_LICENSE_FILES = LICENSE-APACHE LICENSE-MIT
+RUST_BOOTSTRAP_LIBSTD_SOURCE= rust-std-$(RUST_BOOTSTRAP_VERSION)-$(RUST_HOST_NAME).tar.gz
+RUST_BOOTSTRAP_LIBSTD_ROOT = rust-std-$(RUST_BOOTSTRAP_VERSION)-$(RUST_HOST_NAME)/rust-std-$(RUST_HOST_NAME)
+RUST_BOOTSTRAP_EXTRA_DOWNLOADS = $(RUST_BOOTSTRAP_SITE)/$(RUST_BOOTSTRAP_LIBSTD_SOURCE)
+
+define RUST_BOOTSTRAP_LIBSTD_EXTRACT
+ $(call suitable-extractor,$(RUST_BOOTSTRAP_LIBSTD_SOURCE)) \
+ $(DL_DIR)/$(RUST_BOOTSTRAP_LIBSTD_SOURCE) | \
+ $(TAR) --strip-components=2 -C $(@D)/rustc $(TAR_OPTIONS) - \
+ $(RUST_BOOTSTRAP_LIBSTD_ROOT)/lib
+endef
+
+HOST_RUST_BOOTSTRAP_EXTRA_DOWNLOADS = $(RUST_BOOTSTRAP_EXTRA_DOWNLOADS)
+HOST_RUST_BOOTSTRAP_POST_EXTRACT_HOOKS += RUST_BOOTSTRAP_LIBSTD_EXTRACT
+
+$(eval $(host-generic-package))
--
2.9.4
Eric Le Bihan
2017-06-25 20:56:14 UTC
Permalink
This new package provides rustc, the compiler for the Rust programming
language, built from source.

Currently, only the host variant is built.

The Rust compiler uses LLVM as its backend: a copy of LLVM source code
is provided and CMake is used to build it. It is possible to use a
pre-built external copy. When LLVM/clang will be available in Buildroot,
it would be possible to benefit from this feature and thus decrease
build time.

LLVM is configured to generate code for x86, ARM, PowerPC and MIPS
architectures.

The Rust compiler uses Cargo as its build system and is written in Rust.
Therefore this package depends on cargo-bootstrap and rust-bootstrap.

The internal build process is as follows:

1. rustc-stage0, provided by rust-bootstrap, is used to build
rustc-stage1.
2. rust-stage1 builds the final Rust compiler (rust-stage2)
and the standard library for the host architecture.
3. the standard library for the target architecture is built.

The target architecture to support is given by the GNU/LLVM target
triple. Rust supports some predefined targets [1]. As the build system
expects the triple to be in the form of <arch>-unknown-<system> and
Buildroot toolchain wrapper uses <arch>-buildroot-<system>, the package
Makefile uses $(RUST_TARGET_NAME) defined in the rustc package and uses
it instead of $(GNU_TARGET_NAME).

When compiling Rust code with this compiler, the generated program only
depends on the target C library, as it is statically linked to the Rust
standard library and any other code from Rust packages (a.k.a.
"crates").

If the jemalloc package is selected, support for this memory allocator
will be enabled in the target standard library.

The menuconfig entry for rustc is also updated to expose this provider.

[1] https://forge.rust-lang.org/platform-support.html

Signed-off-by: Eric Le Bihan <***@free.fr>
---
DEVELOPERS | 1 +
package/rust/rust.hash | 2 ++
package/rust/rust.mk | 77 ++++++++++++++++++++++++++++++++++++++++++++
package/rustc/Config.in.host | 15 +++++++++
4 files changed, 95 insertions(+)
create mode 100644 package/rust/rust.hash
create mode 100644 package/rust/rust.mk

diff --git a/DEVELOPERS b/DEVELOPERS
index 1ba7ff0..038493b 100644
--- a/DEVELOPERS
+++ b/DEVELOPERS
@@ -486,6 +486,7 @@ F: package/jemalloc/
F: package/ninja/
F: package/rust-bin/
F: package/rust-bootstrap/
+F: package/rust/
F: package/s6/
F: package/s6-dns/
F: package/s6-linux-init/
diff --git a/package/rust/rust.hash b/package/rust/rust.hash
new file mode 100644
index 0000000..18467f5
--- /dev/null
+++ b/package/rust/rust.hash
@@ -0,0 +1,2 @@
+# Locally generated
+sha256 d2dc36e99b9e2269488b2bcddde43c234e6bde03edf70cba82a027ff49c36111 rustc-1.18.0-src.tar.gz
diff --git a/package/rust/rust.mk b/package/rust/rust.mk
new file mode 100644
index 0000000..207919c
--- /dev/null
+++ b/package/rust/rust.mk
@@ -0,0 +1,77 @@
+################################################################################
+#
+# rust
+#
+################################################################################
+
+RUST_VERSION = 1.18.0
+RUST_SOURCE = rustc-$(RUST_VERSION)-src.tar.gz
+RUST_SITE = https://static.rust-lang.org/dist
+RUST_LICENSE = Apache-2.0 or MIT
+RUST_LICENSE_FILES = LICENSE-APACHE LICENSE-MIT
+
+HOST_RUST_PROVIDES = host-rustc
+
+HOST_RUST_DEPENDENCIES = \
+ toolchain \
+ host-rust-bootstrap \
+ host-cargo-bootstrap \
+ host-python \
+ host-cmake
+
+ifeq ($(BR2_PACKAGE_JEMALLOC),y)
+HOST_RUST_DEPENDENCIES += jemalloc
+HOST_RUST_JEMALLOC_ENABLED = true
+HOST_RUST_JEMALLOC_CONF = 'jemalloc = "$(STAGING_DIR)/usr/lib/libjemalloc_pic.a"'
+else
+HOST_RUST_JEMALLOC_ENABLED = false
+endif
+
+HOST_RUST_BUILD_OPTS = $(if $(VERBOSE),--verbose)
+
+define HOST_RUST_CONFIGURE_CMDS
+ (cd $(@D); \
+ echo '[build]' > config.toml; \
+ echo 'target = ["$(RUST_TARGET_NAME)"]' >> config.toml; \
+ echo 'cargo = "$(HOST_CARGO_BOOTSTRAP_DIR)/cargo/bin/cargo"' >> config.toml; \
+ echo 'rustc = "$(HOST_RUST_BOOTSTRAP_DIR)/rustc/bin/rustc"' >> config.toml; \
+ echo 'python = "$(HOST_DIR)/usr/bin/python2"' >> config.toml; \
+ echo 'submodules = false' >> config.toml; \
+ echo 'vendor = true' >> config.toml; \
+ echo 'compiler-docs = false' >> config.toml; \
+ echo 'docs = false' >> config.toml; \
+ echo '[install]' >> config.toml; \
+ echo 'prefix = "$(HOST_DIR)/usr"' >> config.toml; \
+ echo '[rust]' >> config.toml; \
+ echo 'use-jemalloc = $(HOST_RUST_JEMALLOC_ENABLED)' >> config.toml; \
+ echo '[target.$(RUST_TARGET_NAME)]' >> config.toml; \
+ echo 'cc = "$(TARGET_CROSS)gcc"' >> config.toml; \
+ echo 'cxx = "$(TARGET_CROSS)g++"' >> config.toml; \
+ echo $(HOST_RUST_JEMALLOC_CONF) >> config.toml; \
+ )
+endef
+
+define HOST_RUST_BUILD_CMDS
+ (cd $(@D); $(HOST_MAKE_ENV) $(HOST_RUST_MAKE_ENV) python2 x.py \
+ build $(HOST_RUST_BUILD_OPTS))
+endef
+
+define HOST_RUST_INSTALL_LIBSTD_TARGET
+ (cd $(@D)/build/tmp/dist/rust-std-$(RUST_VERSION)-dev-$(RUST_TARGET_NAME); \
+ ./install.sh \
+ --prefix=$(HOST_DIR)/usr \
+ --docdir=$(HOST_DIR)/usr/share/doc/rust \
+ --libdir=$(HOST_DIR)/usr/lib \
+ --mandir=$(HOST_DIR)/usr/share/man \
+ --disable-ldconfig)
+endef
+
+define HOST_RUST_INSTALL_CMDS
+ (cd $(@D); $(HOST_MAKE_ENV) $(HOST_RUST_MAKE_ENV) python2 x.py \
+ dist $(HOST_RUST_BUILD_OPTS))
+ (cd $(@D); $(HOST_MAKE_ENV) $(HOST_RUST_MAKE_ENV) python2 x.py \
+ dist --install $(HOST_RUST_BUILD_OPTS))
+ $(HOST_RUST_INSTALL_LIBSTD_TARGET)
+endef
+
+$(eval $(host-generic-package))
diff --git a/package/rustc/Config.in.host b/package/rustc/Config.in.host
index 7f2c276..30bab8f 100644
--- a/package/rustc/Config.in.host
+++ b/package/rustc/Config.in.host
@@ -26,6 +26,20 @@ choice
help
Choose a provider for the Rust compiler.

+config BR2_PACKAGE_HOST_RUST
+ bool "host rust"
+ depends on BR2_HOST_GCC_AT_LEAST_4_7 # required by LLVM
+ # triggers ICE on trunc_int_for_mode, at explow.c:56
+ depends on BR2_TOOLCHAIN_GCC_AT_LEAST_5 || !BR2_aarch64
+ select BR2_PACKAGE_HAS_HOST_RUSTC
+ help
+ This package will build the compiler for the host as well as
+ a cross-compiled version of the Rust standard library for the
+ target.
+
+comment "host-rust needs a toolchain w/ gcc >= 5"
+ depends on !BR2_TOOLCHAIN_GCC_AT_LEAST_5 && BR2_aarch64
+
config BR2_PACKAGE_HOST_RUST_BIN
bool "host rust (pre-built)"
select BR2_PACKAGE_HAS_HOST_RUSTC
@@ -40,6 +54,7 @@ config BR2_PACKAGE_HAS_HOST_RUSTC

config BR2_PACKAGE_PROVIDES_HOST_RUSTC
string
+ default "host-rust" if BR2_PACKAGE_HOST_RUST
default "host-rust-bin" if BR2_PACKAGE_HOST_RUST_BIN

endif
--
2.9.4
Eric Le Bihan
2017-06-25 20:56:13 UTC
Permalink
This new package fetches a binary snapshot of Cargo, suitable to
bootstrap the host variants of the Rust compiler and Cargo, the package
manager.

Note that, contrary to rust-bootstrap which fetches version N-1 of the
rustc binary, this package fetches a nightly version of the cargo
binary, as upstream does not provide binaries for stable releases.

Signed-off-by: Eric Le Bihan <***@free.fr>
---
DEVELOPERS | 1 +
package/cargo-bootstrap/cargo-bootstrap.hash | 3 +++
package/cargo-bootstrap/cargo-bootstrap.mk | 14 ++++++++++++++
3 files changed, 18 insertions(+)
create mode 100644 package/cargo-bootstrap/cargo-bootstrap.hash
create mode 100644 package/cargo-bootstrap/cargo-bootstrap.mk

diff --git a/DEVELOPERS b/DEVELOPERS
index ddcaadd..1ba7ff0 100644
--- a/DEVELOPERS
+++ b/DEVELOPERS
@@ -477,6 +477,7 @@ F: package/xxhash/

N: Eric Le Bihan <***@free.fr>
F: package/adwaita-icon-theme/
+F: package/cargo-bootstrap/
F: package/darkhttpd/
F: package/eudev/
F: package/execline/
diff --git a/package/cargo-bootstrap/cargo-bootstrap.hash b/package/cargo-bootstrap/cargo-bootstrap.hash
new file mode 100644
index 0000000..b193c6f
--- /dev/null
+++ b/package/cargo-bootstrap/cargo-bootstrap.hash
@@ -0,0 +1,3 @@
+# Locally generated
+sha256 0655713cacab054e8e5a33e742081eebec8531a8c77d28a4294e6496123e8ab1 cargo-nightly-x86_64-unknown-linux-gnu.tar.gz
+sha256 f20adfdcd6fb61c1252034e998998ec349c8a6b05c0320e47a539b0f6d1c76fa cargo-nightly-i686-unknown-linux-gnu.tar.gz
diff --git a/package/cargo-bootstrap/cargo-bootstrap.mk b/package/cargo-bootstrap/cargo-bootstrap.mk
new file mode 100644
index 0000000..1962534
--- /dev/null
+++ b/package/cargo-bootstrap/cargo-bootstrap.mk
@@ -0,0 +1,14 @@
+################################################################################
+#
+# cargo-bootstrap
+#
+################################################################################
+
+CARGO_BOOTSTRAP_VERSION = 6e0c18cccc8b0c06fba8a8d76486f81a792fb420
+CARGO_BOOTSTRAP_SITE = https://s3.amazonaws.com/rust-lang-ci/cargo-builds/$(CARGO_BOOTSTRAP_VERSION)
+CARGO_BOOTSTRAP_SOURCE = cargo-nightly-$(RUST_HOST_NAME).tar.gz
+CARGO_BOOTSTRAP_LICENSE = Apache-2.0 or MIT
+CARGO_BOOTSTRAP_LICENSE_FILES = LICENSE-APACHE LICENSE-MIT
+CARGO_BOOTSTRAP_STRIP_COMPONENTS = 1
+
+$(eval $(host-generic-package))
--
2.9.4
Adrian Perez de Castro
2017-06-28 09:20:35 UTC
Permalink
Hello Eric (and everybody else :D),

I think it's great that there is work being done to bring Rust support to
Buildroot, because the languge has been gaining a lot of traction, and people
are now writing very interesting programs in it (I am a fan of RipGrep myself!
If you don't know it, take a look at: https://github.com/BurntSushi/ripgrep)

Recently I submitted v2 of a patch to add a LLVM package, and it would be
interesting to coordinate to make your Rust patchset use it, instead of the
Rust packaging providing its own copy of LLVM. You can see the patch in
Patchwork:

https://patchwork.ozlabs.org/patch/777949/

I am addin some comments inline below, please keep reading...
Post by Eric Le Bihan
This series adds support for the Rust programming language by adding the
- rustc: a virtual package for the Rust compiler.
- rust-bin: provides a pre-built version of rustc.
- rust: builds rustc from source.
Both providers are able to cross-compile code for ARM, MIPS, PowerPC and
x86_64 architectures. Only the host variants are provided.
This means that the “llvm” package should also provide a host variant of the
package. I did a quick try adding “$(eval $(host-cmake-package))” plus a few
minor changs locally and LLVM built just fine.

Regarding the architecture backends to enable, I imagine we would want host
variant to have enabled *both* the host-native backend, and the target
backend. Example: When building for ARM in x86_64, we would enable the “ARM”
and “X86” LLVM backends for “host-llvm”, and only “ARM” for “llvm” (the target
package). Would this be correct? Do you foresee any situation in which other
backends should be enabled for either the host or target variants? Should we
allow selecting from menuconfig which backends are compiled for the target
“llvm” package?

Last but not least: Right now my patch for adding LLVM only builds the main
libraries and binaries. Is this enough for Rust?

Rgeards,

--
Adrián 🎩
Eric Le Bihan
2017-07-01 11:28:55 UTC
Permalink
Hi!
Post by Adrian Perez de Castro
Hello Eric (and everybody else :D),
I think it's great that there is work being done to bring Rust support to
Buildroot, because the languge has been gaining a lot of traction, and people
are now writing very interesting programs in it (I am a fan of RipGrep myself!
If you don't know it, take a look at: https://github.com/BurntSushi/ripgrep)
Recently I submitted v2 of a patch to add a LLVM package, and it would be
interesting to coordinate to make your Rust patchset use it, instead of the
Rust packaging providing its own copy of LLVM. You can see the patch in
https://patchwork.ozlabs.org/patch/777949/
I am addin some comments inline below, please keep reading...
Post by Eric Le Bihan
This series adds support for the Rust programming language by adding the
- rustc: a virtual package for the Rust compiler.
- rust-bin: provides a pre-built version of rustc.
- rust: builds rustc from source.
Both providers are able to cross-compile code for ARM, MIPS, PowerPC and
x86_64 architectures. Only the host variants are provided.
This means that the “llvm” package should also provide a host variant of the
package. I did a quick try adding “$(eval $(host-cmake-package))” plus a few
minor changs locally and LLVM built just fine.
Yes. To build host-rust, the libraries from host-llvm would be required.
If you could provide a patch adding host-llvm, I'll happily test it.
Post by Adrian Perez de Castro
Regarding the architecture backends to enable, I imagine we would want host
variant to have enabled *both* the host-native backend, and the target
backend. Example: When building for ARM in x86_64, we would enable the “ARM”
and “X86” LLVM backends for “host-llvm”, and only “ARM” for “llvm” (the target
package). Would this be correct? Do you foresee any situation in which other
backends should be enabled for either the host or target variants? Should we
allow selecting from menuconfig which backends are compiled for the target
“llvm” package?
IMHO, it is best to keep it simple with only the host and the target archs.
Post by Adrian Perez de Castro
Last but not least: Right now my patch for adding LLVM only builds the main
libraries and binaries. Is this enough for Rust?
Yes.

BR,

--
ELB
Arnout Vandecappelle
2017-07-01 13:01:01 UTC
Permalink
Post by Eric Le Bihan
Post by Adrian Perez de Castro
Regarding the architecture backends to enable, I imagine we would want host
variant to have enabled *both* the host-native backend, and the target
backend. Example: When building for ARM in x86_64, we would enable the “ARM”
and “X86” LLVM backends for “host-llvm”, and only “ARM” for “llvm” (the target
package). Would this be correct? Do you foresee any situation in which other
backends should be enabled for either the host or target variants? Should we
allow selecting from menuconfig which backends are compiled for the target
“llvm” package?
IMHO, it is best to keep it simple with only the host and the target archs.
+1 to that.

Regards,
Arnout
--
Arnout Vandecappelle arnout at mind be
Senior Embedded Software Architect +32-16-286500
Essensium/Mind http://www.mind.be
G.Geenslaan 9, 3001 Leuven, Belgium BE 872 984 063 RPR Leuven
LinkedIn profile: http://www.linkedin.com/in/arnoutvandecappelle
GPG fingerprint: 7493 020B C7E3 8618 8DEC 222C 82EB F404 F9AC 0DDF
Continue reading on narkive:
Loading...