]> git.ipfire.org Git - thirdparty/samba.git/commitdiff
Vendor the rust sources for CI tests
authorDavid Mulder <dmulder@samba.org>
Tue, 13 Aug 2024 14:53:33 +0000 (08:53 -0600)
committerDavid Mulder <dmulder@samba.org>
Wed, 23 Oct 2024 14:21:34 +0000 (14:21 +0000)
Signed-off-by: David Mulder <dmulder@samba.org>
Reviewed-by: Alexander Bokovoy <ab@samba.org>
buildtools/wafsamba/samba_rust.py
rust/.cargo/config.toml [new file with mode: 0644]
rust/wscript_build

index e7e7ff7bf60ae9e032a8e2a3260ad45cd9b43c45..fc4094b530e3eaf155aa2af9d6a1f529bb0b9b44 100644 (file)
@@ -7,6 +7,36 @@ def SAMBA_CHECK_RUST(conf):
     conf.find_program('cargo', var='CARGO',
                       mandatory=not conf.env.disable_rust)
 
+def vendor_sources(bld, 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
+
+    # Determine the vendor directory
+    vendor = bld.path.find_or_declare('./vendor')
+    # WAF dependencies can only be explicit files, not directories, so we touch
+    # a file to indicate vendoring has been completed.
+    vendor_exists = '%s.exists' % vendor
+    # Locate the source manifest file
+    source_manifest = bld.path.find_or_declare('../../../rust/Cargo.toml')
+
+    rule = ['${CARGO}', 'vendor',
+            '--manifest-path=${SRC[0].abspath(env)}',
+            '%s' % vendor,
+            '&& touch %s' % vendor_exists]
+    bld.SAMBA_GENERATOR('vendor.exists',
+                        ' '.join(rule),
+                        source=source_manifest,
+                        target=vendor_exists,
+                        group='final',
+                        enabled=enabled)
+Build.BuildContext.vendor_sources = vendor_sources
+
 def find_sources(source_dir, dep_crate):
     sources = []
     for root, dirs, files in os.walk(os.path.join(source_dir, dep_crate)):
@@ -50,7 +80,8 @@ def SAMBA_RUST(bld, rust_subdir, target_name, dep_crates=[], enabled=True):
             release_flag]
     bld.SAMBA_GENERATOR(target_name,
                         ' '.join(rule),
-                        source='%s/Cargo.toml %s' % (rust_subdir, ' '.join(sources)),
+                        source='%s/Cargo.toml vendor.exists %s' % \
+                                (rust_subdir, ' '.join(sources)),
                         target=target,
                         group='final',
                         enabled=enabled)
diff --git a/rust/.cargo/config.toml b/rust/.cargo/config.toml
new file mode 100644 (file)
index 0000000..29bbcaf
--- /dev/null
@@ -0,0 +1,5 @@
+[source.crates-io]
+replace-with = "vendored-sources"
+
+[source.vendored-sources]
+directory = "../bin/default/rust/vendor"
index f6e639576c18aaa333ba8c82f5099e0cada662ff..5e08c299f18a398ad999e05cbf267eed22b8b6a0 100644 (file)
@@ -1,5 +1,7 @@
 #!/usr/bin/env python
 
+bld.vendor_sources()
+
 if conf.env.enable_himmelblau:
     bld.SAMBA_RUST_BINARY('himmelblaud', 'himmelblaud',
                           ['param',