Skip to contentSkip to conversation

Add support for the Rust programming language

PATCH Superseded Eric Le Bihan 3 participants 12 messages Jun 24, 2016 – Jul 9, 2016 1 message not in the archive

v2 of 10 Superseded Latest is v10 →

lore
Share & tools
lore
#0 lore raw

v2 cover Add support for the Rust programming language

This series adds support for the Rust programming language by providing a package for the host variant of the Rust compiler, able to cross-compile code for ARM, MIPS and x86_64 architectures.

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 (3):
jemalloc: new package
rust-bootstrap: new package
rust: new package

 package/Config.in                                  |   1 +
 package/Config.in.host                             |   1 +
 package/jemalloc/Config.in                         |   7 +
 package/jemalloc/jemalloc.hash                     |   2 +
 package/jemalloc/jemalloc.mk                       |  15 +
 package/rust-bootstrap/rust-bootstrap.hash         |   3 +
 package/rust-bootstrap/rust-bootstrap.mk           |  24 ++
 ...monize-use-of-CROSS_PREFIX_-in-mk-cfg-.mk.patch |  53 ++++
 .../0002-Expand-CC-to-gcc-in-x86-mk-cfg-.cfg.patch |  71 +++++
 ...eclaration-in-mipsel-unknown-linux-gnu.mk.patch |  26 ++
 package/rust/Config.in.host                        |   7 +
 package/rust/rust-target-gen                       | 315 +++++++++++++++++++++
 package/rust/rust.hash                             |   2 +
 package/rust/rust.mk                               |  67 +++++
 14 files changed, 594 insertions(+)
 create mode 100644 package/jemalloc/Config.in
 create mode 100644 package/jemalloc/jemalloc.hash
 create mode 100644 package/jemalloc/jemalloc.mk
 create mode 100644 package/rust-bootstrap/rust-bootstrap.hash
 create mode 100644 package/rust-bootstrap/rust-bootstrap.mk
 create mode 100644 package/rust/0001-Harmonize-use-of-CROSS_PREFIX_-in-mk-cfg-.mk.patch
 create mode 100644 package/rust/0002-Expand-CC-to-gcc-in-x86-mk-cfg-.cfg.patch
 create mode 100644 package/rust/0003-Fix-CPP-declaration-in-mipsel-unknown-linux-gnu.mk.patch
 create mode 100644 package/rust/Config.in.host
 create mode 100755 package/rust/rust-target-gen
 create mode 100644 package/rust/rust.hash
 create mode 100644 package/rust/rust.mk

--
2.4.11

#1 lore raw

PATCH v2 1/3 jemalloc: new package

This new package provides jemalloc, a malloc(3) implementation that emphasizes fragmentation avoidance and scalable concurrency support.

---
 package/Config.in              |  1 +
 package/jemalloc/Config.in     |  7 +++++++
 package/jemalloc/jemalloc.hash |  2 ++
 package/jemalloc/jemalloc.mk   | 15 +++++++++++++++
 4 files changed, 25 insertions(+)
 create mode 100644 package/jemalloc/Config.in
 create mode 100644 package/jemalloc/jemalloc.hash
 create mode 100644 package/jemalloc/jemalloc.mk
package/Config.in +1 -0
index a2a02a8..38734f3 100644
@@ -1242,6 +1242,7 @@ menu "Other"
 	source "package/gmp/Config.in"
 	source "package/gsl/Config.in"
 	source "package/gtest/Config.in"
+	source "package/jemalloc/Config.in"
 	source "package/libargtable2/Config.in"
 	source "package/libatomic_ops/Config.in"
 	source "package/libbsd/Config.in"
package/jemalloc/Config.in new file +7 -0
new file mode 100644
index 0000000..86bafbf
@@ -0,0 +1,7 @@
+config BR2_PACKAGE_JEMALLOC
+	bool "jemalloc"
+	help
+	 This library providing a malloc(3) implementation that emphasizes
+	 fragmentation avoidance and scalable concurrency support.
+
+	 http://www.canonware.com/jemalloc/
package/jemalloc/jemalloc.hash new file +2 -0
new file mode 100644
index 0000000..c24a273
@@ -0,0 +1,2 @@
+# Locally calculated
+sha256 b216ddaeb901697fe38bd30ea02d7505a4b60e8979092009f95cfda860d46acb jemalloc-4.2.0.tar.bz2
package/jemalloc/jemalloc.mk new file +15 -0
new file mode 100644
index 0000000..4c76a21
@@ -0,0 +1,15 @@
+################################################################################
+#
+# jemalloc
+#
+################################################################################
+
+JEMALLOC_VERSION = 4.2.0
+JEMALLOC_SOURCE = jemalloc-$(JEMALLOC_VERSION).tar.bz2
+JEMALLOC_SITE = http://www.canonware.com/download/jemalloc/
+JEMALLOC_LICENSE = BSD-2c
+JEMALLOC_LICENSE_FILES = COPYING
+JEMALLOC_INSTALL_STAGING = YES
+
+$(eval $(autotools-package))
+$(eval $(host-autotools-package))
Signature · 1 line
2.4.11
#2 lore raw

PATCH v2 1/3 jemalloc: new package

Hi Eric,

Le 24/06/2016 ? 21:46, Eric Le Bihan a ?crit :

Quoted 32 lines

This new package provides jemalloc, a malloc(3) implementation that emphasizes fragmentation avoidance and scalable concurrency support.

---
 package/Config.in              |  1 +
 package/jemalloc/Config.in     |  7 +++++++
 package/jemalloc/jemalloc.hash |  2 ++
 package/jemalloc/jemalloc.mk   | 15 +++++++++++++++
 4 files changed, 25 insertions(+)
 create mode 100644 package/jemalloc/Config.in
 create mode 100644 package/jemalloc/jemalloc.hash
 create mode 100644 package/jemalloc/jemalloc.mk
package/Config.in +1 -0
index a2a02a8..38734f3 100644
@@ -1242,6 +1242,7 @@ menu "Other"
 	source "package/gmp/Config.in"
 	source "package/gsl/Config.in"
 	source "package/gtest/Config.in"
+	source "package/jemalloc/Config.in"
 	source "package/libargtable2/Config.in"
 	source "package/libatomic_ops/Config.in"
 	source "package/libbsd/Config.in"
package/jemalloc/Config.in new file +0 -0
new file mode 100644
index 0000000..86bafbf

package/jemalloc/Config.in line 2

Quoted 2 lines
package/jemalloc/Config.in new file +2 -0
@@ -0,0 +1,7 @@
+config BR2_PACKAGE_JEMALLOC
+	bool "jemalloc"

Can you check the jemalloc dependency ?

Since it try to build libjemalloc.so.2, jmalloc should be disabled for static only build.

jemalloc build fine with uclibc-ng and musl.

Quoted 19 lines
package/jemalloc/Config.in new file +5 -0
+	help
+	 This library providing a malloc(3) implementation that emphasizes
+	 fragmentation avoidance and scalable concurrency support.
+
+	 http://www.canonware.com/jemalloc/
package/jemalloc/jemalloc.hash new file +2 -0
new file mode 100644
index 0000000..c24a273
@@ -0,0 +1,2 @@
+# Locally calculated
+sha256 b216ddaeb901697fe38bd30ea02d7505a4b60e8979092009f95cfda860d46acb jemalloc-4.2.0.tar.bz2
package/jemalloc/jemalloc.mk new file +0 -0
new file mode 100644
index 0000000..4c76a21

package/jemalloc/jemalloc.mk line 9

Quoted 9 lines
package/jemalloc/jemalloc.mk new file +9 -0
@@ -0,0 +1,15 @@
+################################################################################
+#
+# jemalloc
+#
+################################################################################
+
+JEMALLOC_VERSION = 4.2.0
+JEMALLOC_SOURCE = jemalloc-$(JEMALLOC_VERSION).tar.bz2
+JEMALLOC_SITE = http://www.canonware.com/download/jemalloc/

Remove the trailing stash:
package/jemalloc/jemalloc.mk:14: *** JEMALLOC_SITE
(http://www.canonware.com/download/jemalloc/) cannot have a trailing slash. Stop.

Otherwise:

Best regards,
Romain

Quoted 7 lines
package/jemalloc/jemalloc.mk new file +6 -0
+JEMALLOC_LICENSE = BSD-2c
+JEMALLOC_LICENSE_FILES = COPYING
+JEMALLOC_INSTALL_STAGING = YES
+
+$(eval $(autotools-package))
+$(eval $(host-autotools-package))
#3 lore raw

PATCH v2 1/3 jemalloc: new package

In reply to Eric Le Bihan

Hello,

Quoted 4 lines · Eric Le Bihan

This new package provides jemalloc, a malloc(3) implementation that emphasizes fragmentation avoidance and scalable concurrency support.

Quoted 9 lines
---
 package/Config.in              |  1 +
 package/jemalloc/Config.in     |  7 +++++++
 package/jemalloc/jemalloc.hash |  2 ++
 package/jemalloc/jemalloc.mk   | 15 +++++++++++++++
 4 files changed, 25 insertions(+)
 create mode 100644 package/jemalloc/Config.in
 create mode 100644 package/jemalloc/jemalloc.hash
 create mode 100644 package/jemalloc/jemalloc.mk

I've applied, after making the fixes suggested by Romain Naour:

[Thomas:
- remove trailing slash (noticed by Romain Naour)
- add !BR2_STATIC_LIBS dependency (noticed by Romain Naour).]

Thanks,

Thomas

Signature · 3 lines
Thomas Petazzoni, CTO, Free Electrons
Embedded Linux, Kernel and Android engineering
http://free-electrons.com
#4 lore raw

PATCH v2 1/3 jemalloc: new package

In reply to Eric Le Bihan

Hello,

Quoted 4 lines · Eric Le Bihan

This new package provides jemalloc, a malloc(3) implementation that emphasizes fragmentation avoidance and scalable concurrency support.

Quoted 9 lines
---
 package/Config.in              |  1 +
 package/jemalloc/Config.in     |  7 +++++++
 package/jemalloc/jemalloc.hash |  2 ++
 package/jemalloc/jemalloc.mk   | 15 +++++++++++++++
 4 files changed, 25 insertions(+)
 create mode 100644 package/jemalloc/Config.in
 create mode 100644 package/jemalloc/jemalloc.hash
 create mode 100644 package/jemalloc/jemalloc.mk

This package fails to build on NIOS2:

http://autobuild.buildroot.net/results/674/674b6022f9a403528a758c0785656d2bda79e0a9/build-end.log

Could you have a look ?

Thomas

Signature · 3 lines
Thomas Petazzoni, CTO, Free Electrons
Embedded Linux, Kernel and Android engineering
http://free-electrons.com
#5 lore raw

PATCH v2 2/3 rust-bootstrap: new package

In reply to Eric Le Bihan

This new package fetches a binary snapshot of the Rust compiler, suitable for the host, in order to bootstrap the Rust compiler.

---
 package/rust-bootstrap/rust-bootstrap.hash |  3 +++
 package/rust-bootstrap/rust-bootstrap.mk   | 24 ++++++++++++++++++++++++
 2 files changed, 27 insertions(+)
 create mode 100644 package/rust-bootstrap/rust-bootstrap.hash
 create mode 100644 package/rust-bootstrap/rust-bootstrap.mk
package/rust-bootstrap/rust-bootstrap.hash new file +3 -0
new file mode 100644
index 0000000..00f686b
@@ -0,0 +1,3 @@
+# Locally calculated
+sha256 a8ca657d78162a9f0a69a1ec8b0460e97259cdf2e6353ee256ae206876c9637e rust-stage0-2016-03-18-235d774-linux-x86_64-1273b6b6aed421c9e40c59f366d0df6092ec0397.tar.bz2
+sha256 36958fcd55387d7b1b86618111fa8660c1d488fe191e85ad9659c6470874322b rust-stage0-2016-03-18-235d774-linux-i386-0e0e4448b80d0a12b75485795244bb3857a0a7ef.tar.bz2
package/rust-bootstrap/rust-bootstrap.mk new file +24 -0
new file mode 100644
index 0000000..9a74c3b
@@ -0,0 +1,24 @@
+################################################################################
+#
+# rust-bootstrap
+#
+################################################################################
+
+# Taken from src/snapshots.txt
+RUST_BOOTSTRAP_DATE = 2016-03-18
+RUST_BOOTSTRAP_REV = 235d774
+
+ifeq ($(HOSTARCH),x86_64)
+RUST_BOOTSTRAP_HASH = 1273b6b6aed421c9e40c59f366d0df6092ec0397
+else
+RUST_BOOTSTRAP_HASH = 0e0e4448b80d0a12b75485795244bb3857a0a7ef
+endif
+
+RUST_BOOTSTRAP_VERSION = $(RUST_BOOTSTRAP_DATE)-$(RUST_BOOTSTRAP_REV)-linux-$(HOSTARCH)-$(RUST_BOOTSTRAP_HASH)
+RUST_BOOTSTRAP_SITE = https://static.rust-lang.org/stage0-snapshots
+
+RUST_BOOTSTRAP_SOURCE = rust-stage0-$(RUST_BOOTSTRAP_VERSION).tar.bz2
+RUST_BOOTSTRAP_LICENSE = Apache-2.0, MIT
+RUST_BOOTSTRAP_LICENSE_FILES = LICENSE-APACHE LICENSE-MIT
+
+$(eval $(host-generic-package))
Signature · 1 line
2.4.11
#6 lore raw

PATCH v2 2/3 rust-bootstrap: new package

Hi Eric,

Le 24/06/2016 ? 21:46, Eric Le Bihan a ?crit :

Quoted 2 lines

This new package fetches a binary snapshot of the Rust compiler, suitable for the host, in order to bootstrap the Rust compiler.

There is a way to not use the binary snapshot of the Rust compiler ?

Quoted 35 lines
---
 package/rust-bootstrap/rust-bootstrap.hash |  3 +++
 package/rust-bootstrap/rust-bootstrap.mk   | 24 ++++++++++++++++++++++++
 2 files changed, 27 insertions(+)
 create mode 100644 package/rust-bootstrap/rust-bootstrap.hash
 create mode 100644 package/rust-bootstrap/rust-bootstrap.mk
package/rust-bootstrap/rust-bootstrap.hash new file +3 -0
new file mode 100644
index 0000000..00f686b
@@ -0,0 +1,3 @@
+# Locally calculated
+sha256 a8ca657d78162a9f0a69a1ec8b0460e97259cdf2e6353ee256ae206876c9637e rust-stage0-2016-03-18-235d774-linux-x86_64-1273b6b6aed421c9e40c59f366d0df6092ec0397.tar.bz2
+sha256 36958fcd55387d7b1b86618111fa8660c1d488fe191e85ad9659c6470874322b rust-stage0-2016-03-18-235d774-linux-i386-0e0e4448b80d0a12b75485795244bb3857a0a7ef.tar.bz2
package/rust-bootstrap/rust-bootstrap.mk new file +11 -0
new file mode 100644
index 0000000..9a74c3b
@@ -0,0 +1,24 @@
+################################################################################
+#
+# rust-bootstrap
+#
+################################################################################
+
+# Taken from src/snapshots.txt
+RUST_BOOTSTRAP_DATE = 2016-03-18
+RUST_BOOTSTRAP_REV = 235d774
+
+ifeq ($(HOSTARCH),x86_64)

package/rust-bootstrap/rust-bootstrap.mk line 21

Quoted 10 lines
package/rust-bootstrap/rust-bootstrap.mk new file +10 -0
+RUST_BOOTSTRAP_HASH = 1273b6b6aed421c9e40c59f366d0df6092ec0397
+else
+RUST_BOOTSTRAP_HASH = 0e0e4448b80d0a12b75485795244bb3857a0a7ef
+endif
+
+RUST_BOOTSTRAP_VERSION = $(RUST_BOOTSTRAP_DATE)-$(RUST_BOOTSTRAP_REV)-linux-$(HOSTARCH)-$(RUST_BOOTSTRAP_HASH)
+RUST_BOOTSTRAP_SITE = https://static.rust-lang.org/stage0-snapshots
+
+RUST_BOOTSTRAP_SOURCE = rust-stage0-$(RUST_BOOTSTRAP_VERSION).tar.bz2
+RUST_BOOTSTRAP_LICENSE = Apache-2.0, MIT

I guess that is the same license as for the rust package.

package/rust-bootstrap/rust-bootstrap.mk line 22

Quoted 1 line
package/rust-bootstrap/rust-bootstrap.mk new file +1 -0
+RUST_BOOTSTRAP_LICENSE_FILES = LICENSE-APACHE LICENSE-MIT

There is not license files extracted from the archive, so make legal-info doesn't work.

Best regards,
Romain

Quoted 3 lines
package/rust-bootstrap/rust-bootstrap.mk new file +2 -0
+
+$(eval $(host-generic-package))

A message that is not in the archive (sent off-list or not yet received): 20160709143638.778d7964@itchy

#8 lore raw

PATCH v2 2/3 rust-bootstrap: new package

Hi Eric,

Adding the list in Cc

Le 09/07/2016 ? 14:36, Eric Le Bihan a ?crit :

Quoted 5 lines

Hi!

Le Tue, 5 Jul 2016 11:47:02 +0200,
Romain Naour <[email protected]> a ?crit :

Quoted 8 lines
Quoted 5 lines

Le 24/06/2016 ? 21:46, Eric Le Bihan a ?crit :

Quoted 2 lines

This new package fetches a binary snapshot of the Rust compiler, suitable for the host, in order to bootstrap the Rust compiler.

There is a way to not use the binary snapshot of the Rust compiler ?

I do not understand your question. As the Rust compiler is written in Rust, a Rust compiler is needed for bootstrapping.

I meant adding a Rust compiler in Buildroot prerequisites.
It make sens to download the Rust compiler in his binary format since it not available yet in all GNU/Linux distribution.
I don't know mush rust. Actually this is the first time I look at it ;-)

Quoted 5 lines

I'll post a respin of the series bumping Rust to version 1.10.0. In this version, bootstrapping is not performed using an "anonymous" version of rustc anymore, but with the previous official version (i.e. 1.9.0).

ok

Quoted 49 lines
Quoted 40 lines
Quoted 40 lines
---
 package/rust-bootstrap/rust-bootstrap.hash |  3 +++
 package/rust-bootstrap/rust-bootstrap.mk   | 24
++++++++++++++++++++++++ 2 files changed, 27 insertions(+)
 create mode 100644 package/rust-bootstrap/rust-bootstrap.hash
 create mode 100644 package/rust-bootstrap/rust-bootstrap.mk
(quoted diff) +0 -0

b/package/rust-bootstrap/rust-bootstrap.hash new file mode 100644 index 0000000..00f686b

package/rust-bootstrap/rust-bootstrap.hash new file +2 -0
@@ -0,0 +1,3 @@
+# Locally calculated
+sha256

a8ca657d78162a9f0a69a1ec8b0460e97259cdf2e6353ee256ae206876c9637e rust-stage0-2016-03-18-235d774-linux-x86_64-1273b6b6aed421c9e40c59f366d0df6092ec0397.tar.bz2 +sha256
36958fcd55387d7b1b86618111fa8660c1d488fe191e85ad9659c6470874322b rust-stage0-2016-03-18-235d774-linux-i386-0e0e4448b80d0a12b75485795244bb3857a0a7ef.tar.bz2

(quoted diff) +0 -0

b/package/rust-bootstrap/rust-bootstrap.mk new file mode 100644 index 0000000..9a74c3b --- /dev/null +++ b/package/rust-bootstrap/rust-bootstrap.mk @@ -0,0 +1,24 @@

package/rust-bootstrap/rust-bootstrap.hash new file +14 -0
+################################################################################
+# +# rust-bootstrap +#
+################################################################################
+
+# Taken from src/snapshots.txt
+RUST_BOOTSTRAP_DATE = 2016-03-18
+RUST_BOOTSTRAP_REV = 235d774
+
+ifeq ($(HOSTARCH),x86_64)
+RUST_BOOTSTRAP_HASH = 1273b6b6aed421c9e40c59f366d0df6092ec0397
+else
+RUST_BOOTSTRAP_HASH = 0e0e4448b80d0a12b75485795244bb3857a0a7ef
+endif
+
Quoted 8 lines
Quoted 7 lines

+RUST_BOOTSTRAP_VERSION = $(RUST_BOOTSTRAP_DATE)-$(RUST_BOOTSTRAP_REV)-linux-$(HOSTARCH)-$(RUST_BOOTSTRAP_HASH) +RUST_BOOTSTRAP_SITE =
https://static.rust-lang.org/stage0-snapshots +
+RUST_BOOTSTRAP_SOURCE =
rust-stage0-$(RUST_BOOTSTRAP_VERSION).tar.bz2
+RUST_BOOTSTRAP_LICENSE = Apache-2.0, MIT

I guess that is the same license as for the rust package.

Quoted 8 lines

Indeed it is.

Quoted 3 lines
Quoted 1 line

+RUST_BOOTSTRAP_LICENSE_FILES = LICENSE-APACHE LICENSE-MIT

There is not license files extracted from the archive, so make legal-info doesn't work.

This should be solved in the respin, where host-rust-bootstrap has been reworkded.

Great, thanks!

Best regards,
Romain

Quoted 3 lines

Regards,

#9 lore raw

PATCH v2 3/3 rust: new package

In reply to Eric Le Bihan

This new package provides the compiler for the Rust programming language.

Currently, only the host variant is built.

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 build.

The Rust compiler uses LLVM as its backend, compiled with support for x86, ARM, PowerPC and MIPS architectures.

To properly build the standard library for the target, two files are needed:

- the target configuration: a Makefile fragment telling the build system about the cross-compiler and such.
- the target specification: a JSON file describing the target architecture to the LLVM backend.

These files are generated with a Python script which takes info from the Buildroot configuration: rust-target-gen.

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.

---
 package/Config.in.host                             |   1 +
 ...monize-use-of-CROSS_PREFIX_-in-mk-cfg-.mk.patch |  53 ++++
 .../0002-Expand-CC-to-gcc-in-x86-mk-cfg-.cfg.patch |  71 +++++
 ...eclaration-in-mipsel-unknown-linux-gnu.mk.patch |  26 ++
 package/rust/Config.in.host                        |   7 +
 package/rust/rust-target-gen                       | 315 +++++++++++++++++++++
 package/rust/rust.hash                             |   2 +
 package/rust/rust.mk                               |  67 +++++
 8 files changed, 542 insertions(+)
 create mode 100644 package/rust/0001-Harmonize-use-of-CROSS_PREFIX_-in-mk-cfg-.mk.patch
 create mode 100644 package/rust/0002-Expand-CC-to-gcc-in-x86-mk-cfg-.cfg.patch
 create mode 100644 package/rust/0003-Fix-CPP-declaration-in-mipsel-unknown-linux-gnu.mk.patch
 create mode 100644 package/rust/Config.in.host
 create mode 100755 package/rust/rust-target-gen
 create mode 100644 package/rust/rust.hash
 create mode 100644 package/rust/rust.mk
package/Config.in.host +1 -0
index 04b7f19..5d3df08 100644
@@ -30,6 +30,7 @@ menu "Host utilities"
 	source "package/patchelf/Config.in.host"
 	source "package/pwgen/Config.in.host"
 	source "package/qemu/Config.in.host"
+	source "package/rust/Config.in.host"
 	source "package/sam-ba/Config.in.host"
 	source "package/squashfs/Config.in.host"
 	source "package/sunxi-tools/Config.in.host"
package/rust/0001-Harmonize-use-of-CROSS_PREFIX_-in-mk-cfg-.mk.patch new file +53 -0

53 lines not on this page · raw message

package/rust/0002-Expand-CC-to-gcc-in-x86-mk-cfg-.cfg.patch new file +71 -0

71 lines not on this page · raw message

package/rust/0003-Fix-CPP-declaration-in-mipsel-unknown-linux-gnu.mk.patch new file +26 -0
new file mode 100644
index 0000000..00d338f
@@ -0,0 +1,26 @@
+From f6d8c8f6dcdbabead3a06ed8f592143afaad16ba Mon Sep 17 00:00:00 2001
+From: Eric Le Bihan <[email protected]>
+Date: Tue, 19 Apr 2016 12:57:24 +0200
+Subject: [PATCH 3/3] Fix CPP declaration in mipsel-unknown-linux-gnu.mk
+
+Signed-off-by: Eric Le Bihan <[email protected]>
+---
+ mk/cfg/mipsel-unknown-linux-gnu.mk | 2 +-
+ 1 file changed, 1 insertion(+), 1 deletion(-)
+
+diff --git a/mk/cfg/mipsel-unknown-linux-gnu.mk b/mk/cfg/mipsel-unknown-linux-gnu.mk
+index 9340c46..aaa18c2 100644
+--- a/mk/cfg/mipsel-unknown-linux-gnu.mk
++++ b/mk/cfg/mipsel-unknown-linux-gnu.mk
+@@ -2,7 +2,7 @@
+ CROSS_PREFIX_mipsel-unknown-linux-gnu=mipsel-linux-gnu-
+ CC_mipsel-unknown-linux-gnu=gcc
+ CXX_mipsel-unknown-linux-gnu=g++
+-CPP_mipsel-unknown-linux-gnu=gcc
++CPP_mipsel-unknown-linux-gnu=gcc -E
+ AR_mipsel-unknown-linux-gnu=ar
+ CFG_LIB_NAME_mipsel-unknown-linux-gnu=lib$(1).so
+ CFG_STATIC_LIB_NAME_mipsel-unknown-linux-gnu=lib$(1).a
+--
+2.1.4
+
package/rust/Config.in.host new file +7 -0
new file mode 100644
index 0000000..138e74e
@@ -0,0 +1,7 @@
+config BR2_PACKAGE_HOST_RUST_ARCH_SUPPORTS
+	bool
+	default y
+	depends on BR2_HOSTARCH = "x86_64" || BR2_HOSTARCH = "x86"
+	depends on BR2_arm  || BR2_aarch64 || BR2_i386 \
+		|| BR2_mips || BR2_mipsel  || BR2_x86_64
+	depends on !BR2_ARM_CPU_ARMV4 && !BR2_ARM_CPU_ARMV5
package/rust/rust-target-gen new file +315 -0

315 lines not on this page · raw message

package/rust/rust.hash new file +2 -0
new file mode 100644
index 0000000..da2006b
@@ -0,0 +1,2 @@
+# Locally calculated
+sha256 b19b21193d7d36039debeaaa1f61cbf98787e0ce94bd85c5cbe2a59462d7cfcd rustc-1.9.0-src.tar.gz
package/rust/rust.mk new file +67 -0

67 lines not on this page · raw message

Signature · 1 line
2.4.11
#10 lore raw

PATCH v2 3/3 rust: new package

Hi Eric,

Le 24/06/2016 ? 21:46, Eric Le Bihan a ?crit :

Quoted 6 lines

This new package provides the compiler for the Rust programming language.

Currently, only the host variant is built.

The internal build process is as follows:

Quoted 8 lines

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 build.

The Rust compiler uses LLVM as its backend, compiled with support for x86, ARM, PowerPC and MIPS architectures.

rust build it's own bundled copy of llvm if it's not available on the host. If host-rust require a llvm compiler we need to add llvm support in Buildroot first.

I have some WIP patches about llvm/clang, if you want to take a look:
https://github.com/RomainNaour/buildroot/tree/clang-llvm

Best regards,
Romain

Quoted 631 lines

To properly build the standard library for the target, two files are needed:

- the target configuration: a Makefile fragment telling the build system about the cross-compiler and such.
- the target specification: a JSON file describing the target architecture to the LLVM backend.

These files are generated with a Python script which takes info from the Buildroot configuration: rust-target-gen.

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.

---
 package/Config.in.host                             |   1 +
 ...monize-use-of-CROSS_PREFIX_-in-mk-cfg-.mk.patch |  53 ++++
 .../0002-Expand-CC-to-gcc-in-x86-mk-cfg-.cfg.patch |  71 +++++
 ...eclaration-in-mipsel-unknown-linux-gnu.mk.patch |  26 ++
 package/rust/Config.in.host                        |   7 +
 package/rust/rust-target-gen                       | 315 +++++++++++++++++++++
 package/rust/rust.hash                             |   2 +
 package/rust/rust.mk                               |  67 +++++
 8 files changed, 542 insertions(+)
 create mode 100644 package/rust/0001-Harmonize-use-of-CROSS_PREFIX_-in-mk-cfg-.mk.patch
 create mode 100644 package/rust/0002-Expand-CC-to-gcc-in-x86-mk-cfg-.cfg.patch
 create mode 100644 package/rust/0003-Fix-CPP-declaration-in-mipsel-unknown-linux-gnu.mk.patch
 create mode 100644 package/rust/Config.in.host
 create mode 100755 package/rust/rust-target-gen
 create mode 100644 package/rust/rust.hash
 create mode 100644 package/rust/rust.mk
package/Config.in.host +1 -0
index 04b7f19..5d3df08 100644
@@ -30,6 +30,7 @@ menu "Host utilities"
 	source "package/patchelf/Config.in.host"
 	source "package/pwgen/Config.in.host"
 	source "package/qemu/Config.in.host"
+	source "package/rust/Config.in.host"
 	source "package/sam-ba/Config.in.host"
 	source "package/squashfs/Config.in.host"
 	source "package/sunxi-tools/Config.in.host"
package/rust/0001-Harmonize-use-of-CROSS_PREFIX_-in-mk-cfg-.mk.patch new file +53 -0
new file mode 100644
index 0000000..6c09495
@@ -0,0 +1,53 @@
+From 23d9dbfb3ad4a8d5d5997738e8b1436d076898e9 Mon Sep 17 00:00:00 2001
+From: Eric Le Bihan <[email protected]>
+Date: Tue, 19 Apr 2016 10:49:20 +0200
+Subject: [PATCH 1/3] Harmonize use of CROSS_PREFIX_* in mk/cfg/*.mk
+
+Use CROSS_PREFIX_ in Makefile fragments for cross-compiling on Linux
+wherever possible.
+
+Signed-off-by: Eric Le Bihan <[email protected]>
+---
+ mk/cfg/mips-unknown-linux-gnu.mk   | 9 +++++----
+ mk/cfg/mipsel-unknown-linux-gnu.mk | 9 +++++----
+ 2 files changed, 10 insertions(+), 8 deletions(-)
+
+diff --git a/mk/cfg/mips-unknown-linux-gnu.mk b/mk/cfg/mips-unknown-linux-gnu.mk
+index 65b0877..0fe95de 100644
+--- a/mk/cfg/mips-unknown-linux-gnu.mk
++++ b/mk/cfg/mips-unknown-linux-gnu.mk
+@@ -1,8 +1,9 @@
+ # mips-unknown-linux-gnu configuration
+-CC_mips-unknown-linux-gnu=mips-linux-gnu-gcc
+-CXX_mips-unknown-linux-gnu=mips-linux-gnu-g++
+-CPP_mips-unknown-linux-gnu=mips-linux-gnu-gcc -E
+-AR_mips-unknown-linux-gnu=mips-linux-gnu-ar
++CROSS_PREFIX_mips-unknown-linux-gnu=mips-linux-gnu-
++CC_mips-unknown-linux-gnu=gcc
++CXX_mips-unknown-linux-gnu=g++
++CPP_mips-unknown-linux-gnu=gcc -E
++AR_mips-unknown-linux-gnu=ar
+ CFG_LIB_NAME_mips-unknown-linux-gnu=lib$(1).so
+ CFG_STATIC_LIB_NAME_mips-unknown-linux-gnu=lib$(1).a
+ CFG_LIB_GLOB_mips-unknown-linux-gnu=lib$(1)-*.so
+diff --git a/mk/cfg/mipsel-unknown-linux-gnu.mk b/mk/cfg/mipsel-unknown-linux-gnu.mk
+index 4dadfc2..9340c46 100644
+--- a/mk/cfg/mipsel-unknown-linux-gnu.mk
++++ b/mk/cfg/mipsel-unknown-linux-gnu.mk
+@@ -1,8 +1,9 @@
+ # mipsel-unknown-linux-gnu configuration
+-CC_mipsel-unknown-linux-gnu=mipsel-linux-gnu-gcc
+-CXX_mipsel-unknown-linux-gnu=mipsel-linux-gnu-g++
+-CPP_mipsel-unknown-linux-gnu=mipsel-linux-gnu-gcc
+-AR_mipsel-unknown-linux-gnu=mipsel-linux-gnu-ar
++CROSS_PREFIX_mipsel-unknown-linux-gnu=mipsel-linux-gnu-
++CC_mipsel-unknown-linux-gnu=gcc
++CXX_mipsel-unknown-linux-gnu=g++
++CPP_mipsel-unknown-linux-gnu=gcc
++AR_mipsel-unknown-linux-gnu=ar
+ CFG_LIB_NAME_mipsel-unknown-linux-gnu=lib$(1).so
+ CFG_STATIC_LIB_NAME_mipsel-unknown-linux-gnu=lib$(1).a
+ CFG_LIB_GLOB_mipsel-unknown-linux-gnu=lib$(1)-*.so
+--
+2.1.4
+
package/rust/0002-Expand-CC-to-gcc-in-x86-mk-cfg-.cfg.patch new file +71 -0
new file mode 100644
index 0000000..e473e18
@@ -0,0 +1,71 @@
+From a371eb06fef803dcf9894fa0ad6941341887d2d8 Mon Sep 17 00:00:00 2001
+From: Eric Le Bihan <[email protected]>
+Date: Tue, 19 Apr 2016 12:51:29 +0200
+Subject: [PATCH 2/3] Expand $(CC) to gcc in x86 mk/cfg/*.cfg
+
+Expand $(CC) and friends to gcc and introduce empty CROSS_PREFIX_ in
+Makefile fragments for cross-compilation of i586, i686 and x86_64 Linux
+platforms to allow use of Sourcery CodeBench toolchains.
+---
+ mk/cfg/i586-unknown-linux-gnu.mk   | 9 +++++----
+ mk/cfg/i686-unknown-linux-gnu.mk   | 9 +++++----
+ mk/cfg/x86_64-unknown-linux-gnu.mk | 9 +++++----
+ 3 files changed, 15 insertions(+), 12 deletions(-)
+
+diff --git a/mk/cfg/i586-unknown-linux-gnu.mk b/mk/cfg/i586-unknown-linux-gnu.mk
+index 0609f36..45af3b8 100644
+--- a/mk/cfg/i586-unknown-linux-gnu.mk
++++ b/mk/cfg/i586-unknown-linux-gnu.mk
+@@ -1,8 +1,9 @@
+ # i586-unknown-linux-gnu configuration
+-CC_i586-unknown-linux-gnu=$(CC)
+-CXX_i586-unknown-linux-gnu=$(CXX)
+-CPP_i586-unknown-linux-gnu=$(CPP)
+-AR_i586-unknown-linux-gnu=$(AR)
++CROSS_PREFIX_i686-unknown-linux-gnu=
++CC_i586-unknown-linux-gnu=gcc
++CXX_i586-unknown-linux-gnu=g++
++CPP_i586-unknown-linux-gnu=gcc -E
++AR_i586-unknown-linux-gnu=ar
+ CFG_LIB_NAME_i586-unknown-linux-gnu=lib$(1).so
+ CFG_STATIC_LIB_NAME_i586-unknown-linux-gnu=lib$(1).a
+ CFG_LIB_GLOB_i586-unknown-linux-gnu=lib$(1)-*.so
+diff --git a/mk/cfg/i686-unknown-linux-gnu.mk b/mk/cfg/i686-unknown-linux-gnu.mk
+index 88c0907..aa4ce42 100644
+--- a/mk/cfg/i686-unknown-linux-gnu.mk
++++ b/mk/cfg/i686-unknown-linux-gnu.mk
+@@ -1,8 +1,9 @@
+ # i686-unknown-linux-gnu configuration
+-CC_i686-unknown-linux-gnu=$(CC)
+-CXX_i686-unknown-linux-gnu=$(CXX)
+-CPP_i686-unknown-linux-gnu=$(CPP)
+-AR_i686-unknown-linux-gnu=$(AR)
++CROSS_PREFIX_i686-unknown-linux-gnu=
++CC_i686-unknown-linux-gnu=gcc
++CXX_i686-unknown-linux-gnu=g++
++CPP_i686-unknown-linux-gnu=gcc -E
++AR_i686-unknown-linux-gnu=ar
+ CFG_LIB_NAME_i686-unknown-linux-gnu=lib$(1).so
+ CFG_STATIC_LIB_NAME_i686-unknown-linux-gnu=lib$(1).a
+ CFG_LIB_GLOB_i686-unknown-linux-gnu=lib$(1)-*.so
+diff --git a/mk/cfg/x86_64-unknown-linux-gnu.mk b/mk/cfg/x86_64-unknown-linux-gnu.mk
+index 044c687..bdd88cd 100644
+--- a/mk/cfg/x86_64-unknown-linux-gnu.mk
++++ b/mk/cfg/x86_64-unknown-linux-gnu.mk
+@@ -1,8 +1,9 @@
+ # x86_64-unknown-linux-gnu configuration
+-CC_x86_64-unknown-linux-gnu=$(CC)
+-CXX_x86_64-unknown-linux-gnu=$(CXX)
+-CPP_x86_64-unknown-linux-gnu=$(CPP)
+-AR_x86_64-unknown-linux-gnu=$(AR)
++CROSS_PREFIX_x86_64-unknown-linux-gnu=
++CC_x86_64-unknown-linux-gnu=gcc
++CXX_x86_64-unknown-linux-gnu=g++
++CPP_x86_64-unknown-linux-gnu=gcc -E
++AR_x86_64-unknown-linux-gnu=ar
+ CFG_LIB_NAME_x86_64-unknown-linux-gnu=lib$(1).so
+ CFG_STATIC_LIB_NAME_x86_64-unknown-linux-gnu=lib$(1).a
+ CFG_LIB_GLOB_x86_64-unknown-linux-gnu=lib$(1)-*.so
+--
+2.1.4
+
package/rust/0003-Fix-CPP-declaration-in-mipsel-unknown-linux-gnu.mk.patch new file +26 -0
new file mode 100644
index 0000000..00d338f
@@ -0,0 +1,26 @@
+From f6d8c8f6dcdbabead3a06ed8f592143afaad16ba Mon Sep 17 00:00:00 2001
+From: Eric Le Bihan <[email protected]>
+Date: Tue, 19 Apr 2016 12:57:24 +0200
+Subject: [PATCH 3/3] Fix CPP declaration in mipsel-unknown-linux-gnu.mk
+
+Signed-off-by: Eric Le Bihan <[email protected]>
+---
+ mk/cfg/mipsel-unknown-linux-gnu.mk | 2 +-
+ 1 file changed, 1 insertion(+), 1 deletion(-)
+
+diff --git a/mk/cfg/mipsel-unknown-linux-gnu.mk b/mk/cfg/mipsel-unknown-linux-gnu.mk
+index 9340c46..aaa18c2 100644
+--- a/mk/cfg/mipsel-unknown-linux-gnu.mk
++++ b/mk/cfg/mipsel-unknown-linux-gnu.mk
+@@ -2,7 +2,7 @@
+ CROSS_PREFIX_mipsel-unknown-linux-gnu=mipsel-linux-gnu-
+ CC_mipsel-unknown-linux-gnu=gcc
+ CXX_mipsel-unknown-linux-gnu=g++
+-CPP_mipsel-unknown-linux-gnu=gcc
++CPP_mipsel-unknown-linux-gnu=gcc -E
+ AR_mipsel-unknown-linux-gnu=ar
+ CFG_LIB_NAME_mipsel-unknown-linux-gnu=lib$(1).so
+ CFG_STATIC_LIB_NAME_mipsel-unknown-linux-gnu=lib$(1).a
+--
+2.1.4
+
package/rust/Config.in.host new file +7 -0
new file mode 100644
index 0000000..138e74e
@@ -0,0 +1,7 @@
+config BR2_PACKAGE_HOST_RUST_ARCH_SUPPORTS
+	bool
+	default y
+	depends on BR2_HOSTARCH = "x86_64" || BR2_HOSTARCH = "x86"
+	depends on BR2_arm  || BR2_aarch64 || BR2_i386 \
+		|| BR2_mips || BR2_mipsel  || BR2_x86_64
+	depends on !BR2_ARM_CPU_ARMV4 && !BR2_ARM_CPU_ARMV5
package/rust/rust-target-gen new file +315 -0
new file mode 100755
index 0000000..b34b72a
@@ -0,0 +1,315 @@
+#!/usr/bin/env python2.7
+# -*- coding: utf-8 -*-
+#
+# Copyright (C) 2016 Eric Le Bihan <[email protected]>
+#
+# This program is free software: you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation, either version 2 of the License, or
+# (at your option) any later version.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program. If not, see <http://www.gnu.org/licenses/>.
+#
+
+"""
+`rust-target-gen ` generates the target configuration or the specification
+file for the Rust compiler.
+
+These files will be used when cross-compiling the standard library or any
+program.
+
+The name of the target is to be formatted in one of the following schemes:
+
+- <cpu>-<vendor>-<os>-<system>
+- <cpu>-<os>-<system>
+
+By default, the contents of the configuration file is generated and printed to
+standard output. Add *-m spec* to the command line to generate the contents of
+the specification file. Add *-o FILE* to write contents to file FILE.
+
+It is possible to explicitly set the type of CPU using the *--cpu* option. To
+set one or more additional LLVM attributes (a.k.a. "features"), add as many as
+*--feature* options as needed.
+
+"""
+
+import os
+import re
+import sys
+import csv
+import StringIO
+import argparse
+
+__version__ = "0.1.1"
+
+
+class GenerationError(Exception):
+    """Error raised when generating file contents"""
+
+
+class Target:
+    """Store information about a target"""
+    def __init__(self, name):
+        match = re.match(r'([\w]+)(?:-([\w]+))?-linux-([\w]+)', name)
+        if not match:
+            raise ValueError("Invalid target name")
+        self.cpu = match.group(1)
+        self.vendor = match.group(2) or 'unknown'
+        self.system = match.group(3)
+        self.name = name
+        self.prefix = name + "-"
+
+    def to_pattern(self):
+        """Format the target name as search pattern"""
+        if self.vendor == 'unknown':
+            pattern = "{0.cpu}-[\w]+-linux-{0.system}"
+        else:
+            pattern = "{0.cpu}-(?!{0.vendor})[\w]+-linux-{0.system}"
+        return pattern.format(self)
+
+    @property
+    def canonical_name(self):
+        """Return the canonical name of the target"""
+        return "{0.cpu}-{0.vendor}-linux-{0.system}".format(self)
+
+
+#: Default list of pre-link-args
+DEFAULT_PRE_LINK_ARGS = ["-Wl,--as-needed", "-Wl,-z,noexecstack"]
+
+#: Template for the target specifiation JSON file
+SPEC_TEMPLATE = """{{
+      "llvm-target": "{name}",
+      "target-endian": "{endianness}",
+      "target-pointer-width": "{ptr-width}",
+      "data-layout": "{data-layout}",
+      "target-env": "{environment}",
+      "target-vendor": "{vendor}",
+      "arch": "{arch}",
+      "os": "linux",
+      "cpu": "{cpu}",
+      "features": "{features}",
+      "dynamic-linking": true,
+      "executables": true,
+      "morestack": true,
+      "linker-is-gnu": true,
+      "has-rpath": true,
+      "pre-link-args": [
+          {pre-link-args}
+       ],
+      "position-independent-executables": true,
+      "archive-format": "gnu"
+}}
+"""
+
+#: Contents of the target specifiation database.
+#: The information has been extracted from the Rust source code
+#: (src/libbrust_back/target/*.rs) and formatted as CSV.
+#: The first line is the header of the file, listing the fields of the table.
+SPEC_DATABASE_CONTENTS = """name;arch;endianness;ptr-width;data-layout;cpu;features;pre-link-args
+aarch64-unknown-linux-gnu;aarch64;little;64;e-m:e-i64:64-i128:128-n32:64-S128;;;;
+arm-unknown-linux-gnueabihf;arm;little;32;e-m:e-p:32:32-i64:64-v128:64:128-a:0:32-n32-S64;;+v6,+vfp2;;
+arm-unknown-linux-gnueabi;arm;little;32;e-m:e-p:32:32-i64:64-v128:64:128-a:0:32-n32-S64;;+v6;;
+i586-unknown-linux-gnu;x86;little;32;e-m:e-p:32:32-f64:32:64-f80:32-n8:16:32-S128;pentium;;-m32
+i686-unknown-linux-gnu;x86;little;32;e-m:e-p:32:32-f64:32:64-f80:32-n8:16:32-S128;pentium4;;-m32
+mips-unknown-linux-gnu;mips;big;32;E-m:m-p:32:32-i8:8:32-i16:16:32-i64:64-n32-S64;;+mips32r2,+soft-float;;
+mipsel-unknown-linux-gnu;mips;little;32;e-m:m-p:32:32-i8:8:32-i16:16:32-i64:64-n32-S64;;+mips32;;
+x86_64-unknown-linux-gnu;x86_64;little;64;e-m:e-i64:64-f80:128-n8:16:32:64-S128;;;-m64
+"""
+
+
+def join_quoted(strings, delimiter=','):
+    """Quote strings and join them as a single string, using a delimiter.
+
+    :param strings: list of strings
+    :type strings: list
+
+    :param delimiter: optional delimiter
+    :type delimiter: Optional[str]
+
+    :return: a new string
+    :rtype: str
+    """
+    return delimiter.join(["\"{}\"".format(s) for s in strings])
+
+
+def find_similar_spec(target):
+    """Find a target specification similar to a given one.
+
+    :param target: target to be created
+    :type target: Target
+
+    :return: the reference target specification as a dict
+    :rtype: dict of str to str
+    """
+    expr = re.compile(target.to_pattern() + '$')
+    f = StringIO.StringIO(SPEC_DATABASE_CONTENTS)
+    reader = csv.DictReader(f, delimiter=';', quotechar='"')
+    for row in reader:
+        if expr.match(row['name']):
+            spec = dict(row)
+            fields = spec['name'].split('-')
+            spec['vendor'] = fields[1]
+            spec['environment'] = fields[3]
+            pre_links_args = DEFAULT_PRE_LINK_ARGS + spec['pre-link-args'].split()
+            spec['pre-link-args'] = join_quoted(pre_links_args, ', ')
+            spec['cpu'] = spec['cpu'] or 'generic'
+            return spec
+
+    raise GenerationError("Can not find matching specification")
+
+
+def gen_spec(target, cpu=None, features=[]):
+    """Generate target specification file.
+
+    :param target: target to be created
+    :type target: Target
+
+    :param cpu: optional CPU type
+    :type cpu: Optional[str]
+
+    :param features: optional list of additional LLVM features
+    :type features: Optional[list]
+
+    :return: contents of the configuration file
+    :rtype: str
+    """
+    spec = find_similar_spec(target)
+    spec['name'] = target.name
+    spec['vendor'] = target.vendor
+    if features:
+        spec['features'] += ',' + ','.join(features)
+    spec['cpu'] = cpu or spec['cpu']
+    return SPEC_TEMPLATE.format(**spec)
+
+
+def gen_conf_from(target, filename):
+    """Generate target configuration file from an existing one.
+
+    :param target: target to be created
+    :type target: Target
+
+    :param filename: path to an existing configuration file
+    :type str:
+
+    :return: contents of the new configuration file
+    :rtype: str
+    """
+    (name, e) = os.path.splitext(os.path.basename(filename))
+    expr = re.compile(r'CROSS_PREFIX_[-\w]+=(?:[-\w]+)?\n')
+    with open(filename) as input:
+        contents = input.read()
+        contents = contents.replace(name, target.name)
+        line = "CROSS_PREFIX_{}={}\n".format(target.name, target.prefix)
+        if expr.search(contents):
+            contents = expr.sub(line, contents)
+        else:
+            contents += line
+
+    return contents
+
+
+def find_similar_conf(target, srcdir):
+    """Find a configuration file similar to a given target.
+
+    :param target: target to be created
+    :type target: Target
+
+    :param srcdir: path to Rust source code
+    :type srcdir: str
+
+    :return: path to the matching configuration file
+    :rtype: str
+    """
+    cfgdir = os.path.join(srcdir, 'mk', 'cfg')
+    expr = re.compile(target.to_pattern() + '.mk')
+    candidates = filter(lambda f: expr.match(f), os.listdir(cfgdir))
+    if len(candidates) != 1:
+        raise GenerationError("Can not find matching configuration")
+    return os.path.join(cfgdir, candidates[0])
+
+
+def gen_conf(target, srcdir):
+    """Generate target configuration file.
+
+    :param target: target to be created
+    :type target: Target
+
+    :param srcdir: path to Rust source code
+    :type srcdir: str
+
+    :return: contents of the configuration file
+    :rtype: str
+    """
+    reference = find_similar_conf(target, srcdir)
+    return gen_conf_from(target, reference)
+
+
+def save_to_file(filename, text):
+    """Save text to a file.
+
+    :param filename: path to the destination filename
+    :type filename: str
+
+    :param text: contents of the file
+    :type text: str
+    """
+    dstdir = os.path.dirname(filename)
+    if not os.path.exists(dstdir):
+        os.makedirs(dstdir)
+    with open(filename, 'w') as f:
+        f.write(contents)
+
+
+if __name__ == '__main__':
+    parser = argparse.ArgumentParser()
+    parser.add_argument('-v', '--version',
+                        action='version',
+                        version=__version__)
+    parser.add_argument('-c', '--cpu',
+                        help='Set CPU type')
+    parser.add_argument('-f', '--feature',
+                        action='append',
+                        metavar='FEATURE',
+                        dest='features',
+                        default=[],
+                        help='Add new LLVM feature')
+    parser.add_argument('-i', '--input',
+                        dest='srcdir',
+                        metavar='DIR',
+                        default=os.getcwd(),
+                        help='set the path to Rust source code')
+    parser.add_argument('-p', '--prefix',
+                        help='set the cross-compiler prefix')
+    parser.add_argument('-m', '--mode',
+                        choices=('conf', 'spec'),
+                        default='conf',
+                        help='set the operating mode')
+    parser.add_argument('-o', '--output',
+                        metavar='FILE',
+                        help='write generated contents to FILE')
+    parser.add_argument('target',
+                        help='target name ("<cpu>-<vendor>-<os>-<system>")')
+
+    args = parser.parse_args()
+
+    target = Target(args.target)
+    if args.prefix:
+        target.prefix = args.prefix
+
+    if args.mode == 'conf':
+        contents = gen_conf(target, args.srcdir)
+    else:
+        contents = gen_spec(target, args.cpu, args.features)
+
+    if not args.output:
+        sys.stdout.write(contents)
+    else:
+        save_to_file(args.output, contents)
+
+# vim: ts=4 sw=4 sts=4 et ai
package/rust/rust.hash new file +2 -0
new file mode 100644
index 0000000..da2006b
@@ -0,0 +1,2 @@
+# Locally calculated
+sha256 b19b21193d7d36039debeaaa1f61cbf98787e0ce94bd85c5cbe2a59462d7cfcd rustc-1.9.0-src.tar.gz
package/rust/rust.mk new file +67 -0
new file mode 100644
index 0000000..adb980a
@@ -0,0 +1,67 @@
+################################################################################
+#
+# rust
+#
+################################################################################
+
+RUST_VERSION = 1.9.0
+RUST_SOURCE = rustc-$(RUST_VERSION)-src.tar.gz
+RUST_SITE = https://static.rust-lang.org/dist
+RUST_LICENSE = Apache-2.0, MIT
+RUST_LICENSE_FILES = LICENSE-APACHE LICENSE-MIT
+
+HOST_RUST_DEPENDENCIES = host-rust-bootstrap host-python toolchain host-jemalloc
+
+define HOST_RUST_GEN_CONF
+	package/rust/rust-target-gen \
+		--mode conf \
+		--prefix=$(notdir $(TARGET_CROSS)) \
+		--input $(@D) \
+		--output $(@D)/mk/cfg/$(GNU_TARGET_NAME).mk \
+		$(GNU_TARGET_NAME)
+endef
+
+define HOST_RUST_GEN_SPEC
+	package/rust/rust-target-gen \
+		--mode spec \
+		--input $(@D) \
+		--output $(HOST_DIR)/etc/rustc/$(GNU_TARGET_NAME).json \
+		$(GNU_TARGET_NAME)
+endef
+
+HOST_RUST_PRE_CONFIGURE_HOOKS += \
+	HOST_RUST_GEN_CONF \
+	HOST_RUST_GEN_SPEC
+
+HOST_RUST_MAKE_ENV = RUST_TARGET_PATH=$(HOST_DIR)/etc/rustc
+HOST_RUST_MAKE_OPTS = $(if $(VERBOSE),VERBOSE=1)
+
+# Though not using autotools, Rust follows the ./configure convention, in its
+# own way...
+define HOST_RUST_CONFIGURE_CMDS
+	(cd $(@D); $(HOST_CONFIGURE_OPTS) \
+		./configure \
+		--target=$(GNU_TARGET_NAME) \
+		--prefix="$(HOST_DIR)/usr" \
+		--jemalloc-root="$(HOST_DIR)/usr/lib" \
+		--enable-local-rust \
+		--local-rust-root="$(HOST_RUST_BOOTSTRAP_DIR)" \
+		--disable-docs \
+		--disable-manage-submodules \
+		--sysconfdir="$(HOST_DIR)/etc" \
+		--localstatedir="$(HOST_DIR)/var/lib" \
+		--datadir="$(HOST_DIR)/usr/share" \
+		--infodir="$(HOST_DIR)/usr/share/info")
+endef
+
+define HOST_RUST_BUILD_CMDS
+	$(HOST_MAKE_ENV) $(HOST_RUST_MAKE_ENV) $(MAKE) \
+		$(HOST_RUST_MAKE_OPTS) -C $(@D)
+endef
+
+define HOST_RUST_INSTALL_CMDS
+	$(HOST_MAKE_ENV) $(HOST_RUST_MAKE_ENV) $(MAKE) \
+		$(HOST_RUST_MAKE_OPTS) -C $(@D) install
+endef
+
+$(eval $(host-generic-package))
#11 lore raw

PATCH v2 3/3 rust: new package

Hi!

Le Tue, 5 Jul 2016 12:11:13 +0200,
Romain Naour <[email protected]> a ?crit :

Quoted 17 lines

Le 24/06/2016 ? 21:46, Eric Le Bihan a ?crit :

Quoted 7 lines

This new package provides the compiler for the Rust programming language.

Currently, only the host variant is built.

The internal build process is as follows:

Quoted 8 lines

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 build.

The Rust compiler uses LLVM as its backend, compiled with support for x86, ARM, PowerPC and MIPS architectures.

Quoted 6 lines

rust build it's own bundled copy of llvm if it's not available on the host. If host-rust require a llvm compiler we need to add llvm support in Buildroot first.

I have some WIP patches about llvm/clang, if you want to take a look:
https://github.com/RomainNaour/buildroot/tree/clang-llvm

Indeed, having host-rust depends on host-llvm may be added later. AFAIK, the copy of LLVM bundled in Rust only contains optimizations. In any case, a version of LLVM/clang will have to be built and this takes a very long time... Maybe disabling support for some architectures will speed it up (I haven't checked). I'll try your patch.

Regards,

Signature · 1 line
ELB
#12 lore raw

PATCH v2 3/3 rust: new package

Hi Eric,

Le 09/07/2016 ? 14:25, Eric Le Bihan a ?crit :

Quoted 22 lines

Hi!

Le Tue, 5 Jul 2016 12:11:13 +0200,
Romain Naour <[email protected]> a ?crit :

Quoted 17 lines

Le 24/06/2016 ? 21:46, Eric Le Bihan a ?crit :

Quoted 15 lines

This new package provides the compiler for the Rust programming language.

Currently, only the host variant is built.

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 build.

The Rust compiler uses LLVM as its backend, compiled with support for x86, ARM, PowerPC and MIPS architectures.

Quoted 8 lines
Quoted 6 lines

rust build it's own bundled copy of llvm if it's not available on the host. If host-rust require a llvm compiler we need to add llvm support in Buildroot first.

I have some WIP patches about llvm/clang, if you want to take a look:
https://github.com/RomainNaour/buildroot/tree/clang-llvm

Indeed, having host-rust depends on host-llvm may be added later.

I don't think it's a good idea to use the LLVM bundled in Rust since the dependency on Rust and LLVM will be mixed in the rust package. It will be difficult to maintain the package in the future.

For example, LLVM needs to be build with gcc >= 4.7 on the host, so the rust package must depends on BR2_HOST_GCC_AT_LEAST_4_7.

Quoted 1 line

AFAIK, the copy of LLVM bundled in Rust only contains optimizations.

Do you know if there is some custom patch in LLVM bundled by Rust and if an external LLVM compiler can be used ?

Quoted 3 lines

In any case, a version of LLVM/clang will have to be built and this takes a very long time... Maybe disabling support for some architectures will speed it up (I haven't checked). I'll try your patch.

This is the responsibility to the host-llvm package to enable the required optimizations on which host-rust must depends on. Also it would be possible to build LLVM only for the architecture selected in Buildroot.

In the end, I think LLVM should be part of the toolchain package, that way it would be possible to use a prebuild toolchain and only rebuild rust.

Best regards,
Romain

Quoted 3 lines

Regards,