From 94be411a94b60249badcc9cb81b31030c72806aa Mon Sep 17 00:00:00 2001 From: David Mulder Date: Fri, 5 Jul 2024 14:23:09 -0600 Subject: [PATCH] Add simple WAF commands for building Rust bininaries Signed-off-by: David Mulder Reviewed-by: Alexander Bokovoy --- .gitlab-ci-main.yml | 2 +- bootstrap/config.py | 1 + .../generated-dists/centos9s/bootstrap.sh | 1 + .../generated-dists/centos9s/packages.yml | 1 + .../debian11-32bit/bootstrap.sh | 1 + .../debian11-32bit/packages.yml | 1 + .../generated-dists/debian11/bootstrap.sh | 1 + .../generated-dists/debian11/packages.yml | 1 + .../debian12-32bit/bootstrap.sh | 1 + .../debian12-32bit/packages.yml | 1 + .../generated-dists/debian12/bootstrap.sh | 1 + .../generated-dists/debian12/packages.yml | 1 + .../generated-dists/fedora40/bootstrap.sh | 1 + .../generated-dists/fedora40/packages.yml | 1 + .../generated-dists/opensuse155/bootstrap.sh | 1 + .../generated-dists/opensuse155/packages.yml | 1 + bootstrap/generated-dists/rocky8/bootstrap.sh | 1 + bootstrap/generated-dists/rocky8/packages.yml | 1 + .../ubuntu1804-32bit/bootstrap.sh | 1 + .../ubuntu1804-32bit/packages.yml | 1 + .../generated-dists/ubuntu1804/bootstrap.sh | 1 + .../generated-dists/ubuntu1804/packages.yml | 1 + .../generated-dists/ubuntu2004/bootstrap.sh | 1 + .../generated-dists/ubuntu2004/packages.yml | 1 + .../generated-dists/ubuntu2204/bootstrap.sh | 1 + .../generated-dists/ubuntu2204/packages.yml | 1 + bootstrap/sha1sum.txt | 2 +- buildtools/wafsamba/samba_rust.py | 38 +++++++++++++++++++ buildtools/wafsamba/wafsamba.py | 1 + buildtools/wafsamba/wscript | 4 ++ wscript | 5 +++ 31 files changed, 75 insertions(+), 2 deletions(-) create mode 100644 buildtools/wafsamba/samba_rust.py diff --git a/.gitlab-ci-main.yml b/.gitlab-ci-main.yml index 660cb6e9735..52d50f1c58b 100644 --- a/.gitlab-ci-main.yml +++ b/.gitlab-ci-main.yml @@ -47,7 +47,7 @@ variables: # Set this to the contents of bootstrap/sha1sum.txt # which is generated by bootstrap/template.py --render # - SAMBA_CI_CONTAINER_TAG: d1ce7e10953d16253a34b8e58077fd32c1dbd59c + SAMBA_CI_CONTAINER_TAG: 8845099b492ab9888181df3e094e00ae8916ddb7 # # We use the ubuntu2204 image as default as # it matches what we have on atb-devel-224 diff --git a/bootstrap/config.py b/bootstrap/config.py index 7e6c0f47d67..1f0eba24b0b 100644 --- a/bootstrap/config.py +++ b/bootstrap/config.py @@ -64,6 +64,7 @@ COMMON = [ 'tar', 'tree', 'wget', + 'cargo', ] diff --git a/bootstrap/generated-dists/centos9s/bootstrap.sh b/bootstrap/generated-dists/centos9s/bootstrap.sh index 40894b3f3ac..d4684e9cf47 100755 --- a/bootstrap/generated-dists/centos9s/bootstrap.sh +++ b/bootstrap/generated-dists/centos9s/bootstrap.sh @@ -27,6 +27,7 @@ dnf install -y \ bind-utils \ binutils \ bison \ + cargo \ ccache \ chrpath \ crypto-policies-scripts \ diff --git a/bootstrap/generated-dists/centos9s/packages.yml b/bootstrap/generated-dists/centos9s/packages.yml index 19b480e67e1..22f79700ddf 100644 --- a/bootstrap/generated-dists/centos9s/packages.yml +++ b/bootstrap/generated-dists/centos9s/packages.yml @@ -8,6 +8,7 @@ packages: - bind-utils - binutils - bison + - cargo - ccache - chrpath - crypto-policies-scripts diff --git a/bootstrap/generated-dists/debian11-32bit/bootstrap.sh b/bootstrap/generated-dists/debian11-32bit/bootstrap.sh index 82d2705c092..db982ada067 100755 --- a/bootstrap/generated-dists/debian11-32bit/bootstrap.sh +++ b/bootstrap/generated-dists/debian11-32bit/bootstrap.sh @@ -19,6 +19,7 @@ apt-get -y install \ binutils \ bison \ build-essential \ + cargo \ ccache \ chrpath \ codespell \ diff --git a/bootstrap/generated-dists/debian11-32bit/packages.yml b/bootstrap/generated-dists/debian11-32bit/packages.yml index dab6a93e10c..492344da465 100644 --- a/bootstrap/generated-dists/debian11-32bit/packages.yml +++ b/bootstrap/generated-dists/debian11-32bit/packages.yml @@ -8,6 +8,7 @@ packages: - binutils - bison - build-essential + - cargo - ccache - chrpath - codespell diff --git a/bootstrap/generated-dists/debian11/bootstrap.sh b/bootstrap/generated-dists/debian11/bootstrap.sh index 82d2705c092..db982ada067 100755 --- a/bootstrap/generated-dists/debian11/bootstrap.sh +++ b/bootstrap/generated-dists/debian11/bootstrap.sh @@ -19,6 +19,7 @@ apt-get -y install \ binutils \ bison \ build-essential \ + cargo \ ccache \ chrpath \ codespell \ diff --git a/bootstrap/generated-dists/debian11/packages.yml b/bootstrap/generated-dists/debian11/packages.yml index dab6a93e10c..492344da465 100644 --- a/bootstrap/generated-dists/debian11/packages.yml +++ b/bootstrap/generated-dists/debian11/packages.yml @@ -8,6 +8,7 @@ packages: - binutils - bison - build-essential + - cargo - ccache - chrpath - codespell diff --git a/bootstrap/generated-dists/debian12-32bit/bootstrap.sh b/bootstrap/generated-dists/debian12-32bit/bootstrap.sh index 033061ad7e6..e85b15d6692 100755 --- a/bootstrap/generated-dists/debian12-32bit/bootstrap.sh +++ b/bootstrap/generated-dists/debian12-32bit/bootstrap.sh @@ -19,6 +19,7 @@ apt-get -y install \ binutils \ bison \ build-essential \ + cargo \ ccache \ chrpath \ codespell \ diff --git a/bootstrap/generated-dists/debian12-32bit/packages.yml b/bootstrap/generated-dists/debian12-32bit/packages.yml index bd9a558ffbb..b2a027541f1 100644 --- a/bootstrap/generated-dists/debian12-32bit/packages.yml +++ b/bootstrap/generated-dists/debian12-32bit/packages.yml @@ -8,6 +8,7 @@ packages: - binutils - bison - build-essential + - cargo - ccache - chrpath - codespell diff --git a/bootstrap/generated-dists/debian12/bootstrap.sh b/bootstrap/generated-dists/debian12/bootstrap.sh index 033061ad7e6..e85b15d6692 100755 --- a/bootstrap/generated-dists/debian12/bootstrap.sh +++ b/bootstrap/generated-dists/debian12/bootstrap.sh @@ -19,6 +19,7 @@ apt-get -y install \ binutils \ bison \ build-essential \ + cargo \ ccache \ chrpath \ codespell \ diff --git a/bootstrap/generated-dists/debian12/packages.yml b/bootstrap/generated-dists/debian12/packages.yml index bd9a558ffbb..b2a027541f1 100644 --- a/bootstrap/generated-dists/debian12/packages.yml +++ b/bootstrap/generated-dists/debian12/packages.yml @@ -8,6 +8,7 @@ packages: - binutils - bison - build-essential + - cargo - ccache - chrpath - codespell diff --git a/bootstrap/generated-dists/fedora40/bootstrap.sh b/bootstrap/generated-dists/fedora40/bootstrap.sh index e3b36468ca5..99aad7c8c27 100755 --- a/bootstrap/generated-dists/fedora40/bootstrap.sh +++ b/bootstrap/generated-dists/fedora40/bootstrap.sh @@ -20,6 +20,7 @@ dnf install -y \ bind-utils \ binutils \ bison \ + cargo \ ccache \ chrpath \ codespell \ diff --git a/bootstrap/generated-dists/fedora40/packages.yml b/bootstrap/generated-dists/fedora40/packages.yml index 1fbe3988e07..7bdb86e11b4 100644 --- a/bootstrap/generated-dists/fedora40/packages.yml +++ b/bootstrap/generated-dists/fedora40/packages.yml @@ -9,6 +9,7 @@ packages: - bind-utils - binutils - bison + - cargo - ccache - chrpath - codespell diff --git a/bootstrap/generated-dists/opensuse155/bootstrap.sh b/bootstrap/generated-dists/opensuse155/bootstrap.sh index 45d11ef6c4b..687f30ff7be 100755 --- a/bootstrap/generated-dists/opensuse155/bootstrap.sh +++ b/bootstrap/generated-dists/opensuse155/bootstrap.sh @@ -20,6 +20,7 @@ zypper --non-interactive install \ bind-utils \ binutils \ bison \ + cargo \ ccache \ chrpath \ codespell \ diff --git a/bootstrap/generated-dists/opensuse155/packages.yml b/bootstrap/generated-dists/opensuse155/packages.yml index 519b62c33a9..ca1a96efebd 100644 --- a/bootstrap/generated-dists/opensuse155/packages.yml +++ b/bootstrap/generated-dists/opensuse155/packages.yml @@ -8,6 +8,7 @@ packages: - bind-utils - binutils - bison + - cargo - ccache - chrpath - codespell diff --git a/bootstrap/generated-dists/rocky8/bootstrap.sh b/bootstrap/generated-dists/rocky8/bootstrap.sh index 4b2c62c66d9..639ab513ecd 100755 --- a/bootstrap/generated-dists/rocky8/bootstrap.sh +++ b/bootstrap/generated-dists/rocky8/bootstrap.sh @@ -26,6 +26,7 @@ yum install -y \ bind-utils \ binutils \ bison \ + cargo \ ccache \ chrpath \ crypto-policies-scripts \ diff --git a/bootstrap/generated-dists/rocky8/packages.yml b/bootstrap/generated-dists/rocky8/packages.yml index f416dea4f5e..bc34825f9ac 100644 --- a/bootstrap/generated-dists/rocky8/packages.yml +++ b/bootstrap/generated-dists/rocky8/packages.yml @@ -8,6 +8,7 @@ packages: - bind-utils - binutils - bison + - cargo - ccache - chrpath - crypto-policies-scripts diff --git a/bootstrap/generated-dists/ubuntu1804-32bit/bootstrap.sh b/bootstrap/generated-dists/ubuntu1804-32bit/bootstrap.sh index da249a8724c..b74a5e0e7e1 100755 --- a/bootstrap/generated-dists/ubuntu1804-32bit/bootstrap.sh +++ b/bootstrap/generated-dists/ubuntu1804-32bit/bootstrap.sh @@ -19,6 +19,7 @@ apt-get -y install \ binutils \ bison \ build-essential \ + cargo \ ccache \ chrpath \ codespell \ diff --git a/bootstrap/generated-dists/ubuntu1804-32bit/packages.yml b/bootstrap/generated-dists/ubuntu1804-32bit/packages.yml index 94957fc07b2..bca52528f6b 100644 --- a/bootstrap/generated-dists/ubuntu1804-32bit/packages.yml +++ b/bootstrap/generated-dists/ubuntu1804-32bit/packages.yml @@ -8,6 +8,7 @@ packages: - binutils - bison - build-essential + - cargo - ccache - chrpath - codespell diff --git a/bootstrap/generated-dists/ubuntu1804/bootstrap.sh b/bootstrap/generated-dists/ubuntu1804/bootstrap.sh index da249a8724c..b74a5e0e7e1 100755 --- a/bootstrap/generated-dists/ubuntu1804/bootstrap.sh +++ b/bootstrap/generated-dists/ubuntu1804/bootstrap.sh @@ -19,6 +19,7 @@ apt-get -y install \ binutils \ bison \ build-essential \ + cargo \ ccache \ chrpath \ codespell \ diff --git a/bootstrap/generated-dists/ubuntu1804/packages.yml b/bootstrap/generated-dists/ubuntu1804/packages.yml index 94957fc07b2..bca52528f6b 100644 --- a/bootstrap/generated-dists/ubuntu1804/packages.yml +++ b/bootstrap/generated-dists/ubuntu1804/packages.yml @@ -8,6 +8,7 @@ packages: - binutils - bison - build-essential + - cargo - ccache - chrpath - codespell diff --git a/bootstrap/generated-dists/ubuntu2004/bootstrap.sh b/bootstrap/generated-dists/ubuntu2004/bootstrap.sh index da249a8724c..b74a5e0e7e1 100755 --- a/bootstrap/generated-dists/ubuntu2004/bootstrap.sh +++ b/bootstrap/generated-dists/ubuntu2004/bootstrap.sh @@ -19,6 +19,7 @@ apt-get -y install \ binutils \ bison \ build-essential \ + cargo \ ccache \ chrpath \ codespell \ diff --git a/bootstrap/generated-dists/ubuntu2004/packages.yml b/bootstrap/generated-dists/ubuntu2004/packages.yml index 94957fc07b2..bca52528f6b 100644 --- a/bootstrap/generated-dists/ubuntu2004/packages.yml +++ b/bootstrap/generated-dists/ubuntu2004/packages.yml @@ -8,6 +8,7 @@ packages: - binutils - bison - build-essential + - cargo - ccache - chrpath - codespell diff --git a/bootstrap/generated-dists/ubuntu2204/bootstrap.sh b/bootstrap/generated-dists/ubuntu2204/bootstrap.sh index 1a3c3b14efb..72802d40cf1 100755 --- a/bootstrap/generated-dists/ubuntu2204/bootstrap.sh +++ b/bootstrap/generated-dists/ubuntu2204/bootstrap.sh @@ -19,6 +19,7 @@ apt-get -y install \ binutils \ bison \ build-essential \ + cargo \ ccache \ chrpath \ codespell \ diff --git a/bootstrap/generated-dists/ubuntu2204/packages.yml b/bootstrap/generated-dists/ubuntu2204/packages.yml index c3b741fbc69..c58b08f9174 100644 --- a/bootstrap/generated-dists/ubuntu2204/packages.yml +++ b/bootstrap/generated-dists/ubuntu2204/packages.yml @@ -8,6 +8,7 @@ packages: - binutils - bison - build-essential + - cargo - ccache - chrpath - codespell diff --git a/bootstrap/sha1sum.txt b/bootstrap/sha1sum.txt index e71a040595b..cdb48c41715 100644 --- a/bootstrap/sha1sum.txt +++ b/bootstrap/sha1sum.txt @@ -1 +1 @@ -d1ce7e10953d16253a34b8e58077fd32c1dbd59c +8845099b492ab9888181df3e094e00ae8916ddb7 diff --git a/buildtools/wafsamba/samba_rust.py b/buildtools/wafsamba/samba_rust.py new file mode 100644 index 00000000000..c58bf89428a --- /dev/null +++ b/buildtools/wafsamba/samba_rust.py @@ -0,0 +1,38 @@ +from waflib.Configure import conf +from waflib import Build +import os.path + +@conf +def SAMBA_CHECK_RUST(conf): + conf.find_program('cargo', var='CARGO', + mandatory=not conf.env.disable_rust) + +def SAMBA_RUST(bld, name, source, enabled=True): + # force-disable when we can't build rust modules, so + # every single call doesn't need to pass this in. + if bld.env.disable_rust: + enabled = False + + # Save time, no need to build rust when fuzzing + if bld.env.enable_fuzzing: + enabled = False + + release_flag = '' + if bld.env.debug or bld.env.developer: + target = os.path.join('debug', name) + else: + release_flag = '--release' + target = os.path.join('release', name) + target = bld.path.find_or_declare(target) + rust_vars = 'CARGO_TARGET_DIR=%s' % bld.path.find_or_declare('./') + + rule = [rust_vars, '${CARGO}', 'build', + '--manifest-path=${SRC[0].abspath(env)}', release_flag] + bld.SAMBA_GENERATOR(name, + ' '.join(rule), + source='Cargo.toml %s' % source, + target=target, + group='final', + enabled=enabled) +Build.BuildContext.SAMBA_RUST_LIBRARY = SAMBA_RUST +Build.BuildContext.SAMBA_RUST_BINARY = SAMBA_RUST diff --git a/buildtools/wafsamba/wafsamba.py b/buildtools/wafsamba/wafsamba.py index 250da072c50..1a4943d6c5c 100644 --- a/buildtools/wafsamba/wafsamba.py +++ b/buildtools/wafsamba/wafsamba.py @@ -19,6 +19,7 @@ from samba_autoproto import * from samba_python import * from samba_perl import * from samba_deps import * +from samba_rust import * from samba_bundled import * from samba_third_party import * import samba_cross diff --git a/buildtools/wafsamba/wscript b/buildtools/wafsamba/wscript index e18bc4fd741..505e77a5ca7 100644 --- a/buildtools/wafsamba/wscript +++ b/buildtools/wafsamba/wscript @@ -288,6 +288,9 @@ Currently the only tested value is 'smbtorture,smbd/smbd' for Samba'''), opt.add_option('--disable-python', help='do not generate python modules', action='store_true', dest='disable_python', default=False) + opt.add_option('--disable-rust', + help='do not build rust modules', + action='store_true', dest='disable_rust', default=False) @Utils.run_once @@ -351,6 +354,7 @@ def configure(conf): conf.env.AUTOCONF_PROGRAM_PREFIX = Options.options.AUTOCONF_PROGRAM_PREFIX conf.env.disable_python = Options.options.disable_python + conf.env.disable_rust = Options.options.disable_rust if (conf.env.AUTOCONF_HOST and conf.env.AUTOCONF_BUILD and diff --git a/wscript b/wscript index 8dd6599cdd7..62e5107f00d 100644 --- a/wscript +++ b/wscript @@ -218,6 +218,8 @@ def configure(conf): conf.SAMBA_CHECK_PYTHON() conf.SAMBA_CHECK_PYTHON_HEADERS() + conf.SAMBA_CHECK_RUST() + if sys.platform == 'darwin' and not conf.env['HAVE_ENVIRON_DECL']: # Mac OSX needs to have this and it's also needed that the python is compiled with this # otherwise you face errors about common symbols @@ -502,6 +504,9 @@ def configure(conf): if Options.options.with_smb1server is not False: conf.DEFINE('WITH_SMB1SERVER', '1') + conf.env.debug = Options.options.debug + conf.env.developer = Options.options.developer + # # FreeBSD is broken. It doesn't include 'extern char **environ' # in any shared library, but statically inside crt0.o. -- 2.47.3