Skip to content

Commit

Permalink
deploy: 1834827
Browse files Browse the repository at this point in the history
  • Loading branch information
theduke committed Sep 26, 2024
1 parent 0c4a98a commit 7757c00
Show file tree
Hide file tree
Showing 79 changed files with 423 additions and 209 deletions.
2 changes: 1 addition & 1 deletion crates/doc/implementors/core/convert/trait.From.js

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion crates/doc/implementors/core/default/trait.Default.js

Large diffs are not rendered by default.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion crates/doc/search-index.js

Large diffs are not rendered by default.

6 changes: 3 additions & 3 deletions crates/doc/src/wasmer_wasix/runners/wasi.rs.html
Original file line number Diff line number Diff line change
Expand Up @@ -1023,7 +1023,7 @@

<span class="kw">let </span>fs = <span class="kw-2">&amp;</span>init.state.fs.root_fs;

fs.read_dir(<span class="kw-2">&amp;</span>std::path::Path::new(<span class="string">&quot;/host&quot;</span>)).unwrap();
fs.read_dir(std::path::Path::new(<span class="string">&quot;/host&quot;</span>)).unwrap();
}

<span class="attr">#[cfg(all(feature = <span class="string">&quot;host-fs&quot;</span>, feature = <span class="string">&quot;sys&quot;</span>))]
Expand Down Expand Up @@ -1076,8 +1076,8 @@

<span class="kw">let </span>fs = <span class="kw-2">&amp;</span>init.state.fs.root_fs;

fs.read_dir(<span class="kw-2">&amp;</span>std::path::Path::new(<span class="string">&quot;/host&quot;</span>)).unwrap();
fs.read_dir(<span class="kw-2">&amp;</span>std::path::Path::new(<span class="string">&quot;/settings&quot;</span>)).unwrap();
fs.read_dir(std::path::Path::new(<span class="string">&quot;/host&quot;</span>)).unwrap();
fs.read_dir(std::path::Path::new(<span class="string">&quot;/settings&quot;</span>)).unwrap();
}
}
</code></pre></div></section></main></body></html>
Original file line number Diff line number Diff line change
Expand Up @@ -1430,7 +1430,7 @@
<span class="kw">let </span>path = dir.path();

<span class="kw">let </span>contents = <span class="string">&quot;fail&quot;</span>;
<span class="kw">let </span>correct_hash = WebcHash::sha256(<span class="kw-2">&amp;</span>contents);
<span class="kw">let </span>correct_hash = WebcHash::sha256(contents);
<span class="kw">let </span>used_hash =
WebcHash::parse_hex(<span class="string">&quot;0000a28ea38a000f3a3328cb7fabe330638d3258affe1a869e3f92986222d997&quot;</span>)
.unwrap();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -230,6 +230,28 @@
<a href="#230" id="230">230</a>
<a href="#231" id="231">231</a>
<a href="#232" id="232">232</a>
<a href="#233" id="233">233</a>
<a href="#234" id="234">234</a>
<a href="#235" id="235">235</a>
<a href="#236" id="236">236</a>
<a href="#237" id="237">237</a>
<a href="#238" id="238">238</a>
<a href="#239" id="239">239</a>
<a href="#240" id="240">240</a>
<a href="#241" id="241">241</a>
<a href="#242" id="242">242</a>
<a href="#243" id="243">243</a>
<a href="#244" id="244">244</a>
<a href="#245" id="245">245</a>
<a href="#246" id="246">246</a>
<a href="#247" id="247">247</a>
<a href="#248" id="248">248</a>
<a href="#249" id="249">249</a>
<a href="#250" id="250">250</a>
<a href="#251" id="251">251</a>
<a href="#252" id="252">252</a>
<a href="#253" id="253">253</a>
<a href="#254" id="254">254</a>
</pre></div><pre class="rust"><code><span class="kw">use </span>std::{
collections::{BTreeMap, HashMap, VecDeque},
fs::File,
Expand Down Expand Up @@ -300,10 +322,21 @@
}

<span class="doccomment">/// Add a new [`PackageSummary`] to the [`InMemorySource`].
///
/// Named packages are also made accessible by their hash.
</span><span class="kw">pub fn </span>add(<span class="kw-2">&amp;mut </span><span class="self">self</span>, summary: PackageSummary) {
<span class="kw">match </span>summary.pkg.id.clone() {
PackageId::Named(ident) =&gt; {
<span class="kw">let </span>summaries = <span class="self">self
<span class="comment">// Also add the package as a hashed package.
</span><span class="kw">let </span>pkg_hash = PackageHash::Sha256(wasmer_config::hash::Sha256Hash(
summary.dist.webc_sha256.as_bytes(),
));
<span class="self">self</span>.hash_packages
.entry(pkg_hash)
.or_insert_with(|| summary.clone());

<span class="comment">// Add the named package.
</span><span class="kw">let </span>summaries = <span class="self">self
</span>.named_packages
.entry(ident.full_name.clone())
.or_default();
Expand Down Expand Up @@ -339,6 +372,17 @@
PackageId::Hash(hash) =&gt; <span class="self">self</span>.hash_packages.get(hash),
}
}

<span class="kw">pub fn </span>is_empty(<span class="kw-2">&amp;</span><span class="self">self</span>) -&gt; bool {
<span class="self">self</span>.named_packages.is_empty() &amp;&amp; <span class="self">self</span>.hash_packages.is_empty()
}

<span class="doccomment">/// Returns the number of packages in the source.
</span><span class="kw">pub fn </span>len(<span class="kw-2">&amp;</span><span class="self">self</span>) -&gt; usize {
<span class="comment">// Only need to count the hash packages,
// as the named packages are also always added as hashed.
</span><span class="self">self</span>.hash_packages.len()
}
}

<span class="attr">#[async_trait::async_trait]
Expand Down
182 changes: 171 additions & 11 deletions crates/doc/src/wasmer_wasix/runtime/resolver/multi_source.rs.html
Original file line number Diff line number Diff line change
Expand Up @@ -103,6 +103,86 @@
<a href="#103" id="103">103</a>
<a href="#104" id="104">104</a>
<a href="#105" id="105">105</a>
<a href="#106" id="106">106</a>
<a href="#107" id="107">107</a>
<a href="#108" id="108">108</a>
<a href="#109" id="109">109</a>
<a href="#110" id="110">110</a>
<a href="#111" id="111">111</a>
<a href="#112" id="112">112</a>
<a href="#113" id="113">113</a>
<a href="#114" id="114">114</a>
<a href="#115" id="115">115</a>
<a href="#116" id="116">116</a>
<a href="#117" id="117">117</a>
<a href="#118" id="118">118</a>
<a href="#119" id="119">119</a>
<a href="#120" id="120">120</a>
<a href="#121" id="121">121</a>
<a href="#122" id="122">122</a>
<a href="#123" id="123">123</a>
<a href="#124" id="124">124</a>
<a href="#125" id="125">125</a>
<a href="#126" id="126">126</a>
<a href="#127" id="127">127</a>
<a href="#128" id="128">128</a>
<a href="#129" id="129">129</a>
<a href="#130" id="130">130</a>
<a href="#131" id="131">131</a>
<a href="#132" id="132">132</a>
<a href="#133" id="133">133</a>
<a href="#134" id="134">134</a>
<a href="#135" id="135">135</a>
<a href="#136" id="136">136</a>
<a href="#137" id="137">137</a>
<a href="#138" id="138">138</a>
<a href="#139" id="139">139</a>
<a href="#140" id="140">140</a>
<a href="#141" id="141">141</a>
<a href="#142" id="142">142</a>
<a href="#143" id="143">143</a>
<a href="#144" id="144">144</a>
<a href="#145" id="145">145</a>
<a href="#146" id="146">146</a>
<a href="#147" id="147">147</a>
<a href="#148" id="148">148</a>
<a href="#149" id="149">149</a>
<a href="#150" id="150">150</a>
<a href="#151" id="151">151</a>
<a href="#152" id="152">152</a>
<a href="#153" id="153">153</a>
<a href="#154" id="154">154</a>
<a href="#155" id="155">155</a>
<a href="#156" id="156">156</a>
<a href="#157" id="157">157</a>
<a href="#158" id="158">158</a>
<a href="#159" id="159">159</a>
<a href="#160" id="160">160</a>
<a href="#161" id="161">161</a>
<a href="#162" id="162">162</a>
<a href="#163" id="163">163</a>
<a href="#164" id="164">164</a>
<a href="#165" id="165">165</a>
<a href="#166" id="166">166</a>
<a href="#167" id="167">167</a>
<a href="#168" id="168">168</a>
<a href="#169" id="169">169</a>
<a href="#170" id="170">170</a>
<a href="#171" id="171">171</a>
<a href="#172" id="172">172</a>
<a href="#173" id="173">173</a>
<a href="#174" id="174">174</a>
<a href="#175" id="175">175</a>
<a href="#176" id="176">176</a>
<a href="#177" id="177">177</a>
<a href="#178" id="178">178</a>
<a href="#179" id="179">179</a>
<a href="#180" id="180">180</a>
<a href="#181" id="181">181</a>
<a href="#182" id="182">182</a>
<a href="#183" id="183">183</a>
<a href="#184" id="184">184</a>
<a href="#185" id="185">185</a>
</pre></div><pre class="rust"><code><span class="kw">use </span>std::sync::Arc;

<span class="kw">use </span>wasmer_config::package::PackageSource;
Expand All @@ -129,8 +209,14 @@
strategy: MultiSourceStrategy,
}

<span class="kw">impl </span>Default <span class="kw">for </span>MultiSource {
<span class="kw">fn </span>default() -&gt; <span class="self">Self </span>{
<span class="self">Self</span>::new()
}
}

<span class="kw">impl </span>MultiSource {
<span class="kw">pub const fn </span>new() -&gt; <span class="self">Self </span>{
<span class="kw">pub fn </span>new() -&gt; <span class="self">Self </span>{
MultiSource {
sources: Vec::new(),
strategy: MultiSourceStrategy::default(),
Expand All @@ -156,19 +242,47 @@
</span><span class="kw">impl </span>Source <span class="kw">for </span>MultiSource {
<span class="attr">#[tracing::instrument(level = <span class="string">&quot;debug&quot;</span>, skip_all, fields(%package))]
</span><span class="kw">async fn </span>query(<span class="kw-2">&amp;</span><span class="self">self</span>, package: <span class="kw-2">&amp;</span>PackageSource) -&gt; <span class="prelude-ty">Result</span>&lt;Vec&lt;PackageSummary&gt;, QueryError&gt; {
<span class="kw">let </span><span class="kw-2">mut </span>output = Vec::&lt;PackageSummary&gt;::new();

<span class="kw">for </span>source <span class="kw">in </span><span class="kw-2">&amp;</span><span class="self">self</span>.sources {
<span class="kw">match </span>source.query(package).<span class="kw">await </span>{
<span class="prelude-val">Ok</span>(summaries) =&gt; <span class="kw">return </span><span class="prelude-val">Ok</span>(summaries),
<span class="prelude-val">Err</span>(QueryError::Unsupported) <span class="kw">if </span><span class="self">self</span>.strategy.continue_if_unsupported =&gt; <span class="kw">continue</span>,
<span class="prelude-val">Err</span>(QueryError::NotFound) <span class="kw">if </span><span class="self">self</span>.strategy.continue_if_not_found =&gt; <span class="kw">continue</span>,
<span class="prelude-val">Err</span>(QueryError::NoMatches { .. }) <span class="kw">if </span><span class="self">self</span>.strategy.continue_if_no_matches =&gt; {
<span class="prelude-val">Ok</span>(<span class="kw-2">mut </span>summaries) =&gt; {
<span class="kw">if </span><span class="self">self</span>.strategy.merge_results {
<span class="comment">// Extend matches, but skip already found versions.
</span>summaries.retain(|new| {
!output.iter().any(|existing| new.pkg.id == existing.pkg.id)
});
output.extend(summaries);
} <span class="kw">else </span>{
<span class="kw">return </span><span class="prelude-val">Ok</span>(summaries);
}
}
<span class="prelude-val">Err</span>(QueryError::Unsupported)
<span class="kw">if </span><span class="self">self</span>.strategy.continue_if_unsupported || <span class="self">self</span>.strategy.merge_results =&gt;
{
<span class="kw">continue
</span>}
<span class="prelude-val">Err</span>(QueryError::NotFound)
<span class="kw">if </span><span class="self">self</span>.strategy.continue_if_not_found || <span class="self">self</span>.strategy.merge_results =&gt;
{
<span class="kw">continue
</span>}
<span class="prelude-val">Err</span>(QueryError::NoMatches { .. })
<span class="kw">if </span><span class="self">self</span>.strategy.continue_if_no_matches || <span class="self">self</span>.strategy.merge_results =&gt;
{
<span class="kw">continue
</span>}
<span class="prelude-val">Err</span>(e) =&gt; <span class="kw">return </span><span class="prelude-val">Err</span>(e),
}
}

<span class="prelude-val">Err</span>(QueryError::NotFound)
<span class="kw">if </span>!output.is_empty() {
output.sort_by(|a, b| a.pkg.id.cmp(<span class="kw-2">&amp;</span>b.pkg.id));

<span class="prelude-val">Ok</span>(output)
} <span class="kw">else </span>{
<span class="prelude-val">Err</span>(QueryError::NotFound)
}
}
}

Expand All @@ -191,21 +305,67 @@
///
/// This flag is **disabled** by default.
</span><span class="kw">pub </span>continue_if_no_matches: bool,

<span class="doccomment">/// Merge results from all sources into a single result.
///
/// True by default.
</span><span class="kw">pub </span>merge_results: bool,
}

<span class="kw">impl </span>MultiSourceStrategy {
<span class="kw">pub const fn </span>default() -&gt; <span class="self">Self </span>{
<span class="kw">impl </span>Default <span class="kw">for </span>MultiSourceStrategy {
<span class="kw">fn </span>default() -&gt; <span class="self">Self </span>{
MultiSourceStrategy {
continue_if_unsupported: <span class="bool-val">true</span>,
continue_if_not_found: <span class="bool-val">true</span>,
continue_if_no_matches: <span class="bool-val">true</span>,
merge_results: <span class="bool-val">true</span>,
}
}
}

<span class="kw">impl </span>Default <span class="kw">for </span>MultiSourceStrategy {
<span class="kw">fn </span>default() -&gt; <span class="self">Self </span>{
MultiSourceStrategy::default()
<span class="attr">#[cfg(test)]
</span><span class="kw">mod </span>tests {
<span class="kw">use </span>wasmer_config::package::PackageId;

<span class="kw">use </span><span class="kw">super</span>::<span class="kw">super</span>::{DistributionInfo, InMemorySource, PackageInfo, WebcHash};
<span class="kw">use super</span>::<span class="kw-2">*</span>;

<span class="doccomment">/// Test that the `MultiSource` can merge results from multiple sources.
</span><span class="attr">#[tokio::test]
</span><span class="kw">async fn </span>test_multi_source_merge() {
<span class="kw">let </span>id1 = PackageId::new_named(<span class="string">&quot;ns/pkg&quot;</span>, <span class="string">&quot;0.0.1&quot;</span>.parse().unwrap());
<span class="kw">let </span>pkg1 = PackageSummary {
pkg: PackageInfo {
id: id1.clone(),
commands: Vec::new(),
entrypoint: <span class="prelude-val">None</span>,
dependencies: Vec::new(),
filesystem: Vec::new(),
},
dist: DistributionInfo {
webc: <span class="string">&quot;https://example.com/ns/pkg/0.0.1&quot;</span>.parse().unwrap(),
webc_sha256: WebcHash([<span class="number">0u8</span>; <span class="number">32</span>]),
},
};

<span class="kw">let </span>id2 = PackageId::new_named(<span class="string">&quot;ns/pkg&quot;</span>, <span class="string">&quot;0.0.2&quot;</span>.parse().unwrap());
<span class="kw">let </span><span class="kw-2">mut </span>pkg2 = pkg1.clone();
pkg2.pkg.id = id2.clone();

<span class="kw">let </span><span class="kw-2">mut </span>mem1 = InMemorySource::new();
mem1.add(pkg1);

<span class="kw">let </span><span class="kw-2">mut </span>mem2 = InMemorySource::new();
mem2.add(pkg2);

<span class="kw">let </span><span class="kw-2">mut </span>multi = MultiSource::new();
multi.add_source(mem1);
multi.add_source(mem2);

<span class="kw">let </span>summaries = multi.query(<span class="kw-2">&amp;</span><span class="string">&quot;ns/pkg&quot;</span>.parse().unwrap()).<span class="kw">await</span>.unwrap();
<span class="macro">assert_eq!</span>(summaries.len(), <span class="number">2</span>);
<span class="macro">assert_eq!</span>(summaries[<span class="number">0</span>].pkg.id, id1);
<span class="macro">assert_eq!</span>(summaries[<span class="number">1</span>].pkg.id, id2);
}
}
</code></pre></div></section></main></body></html>
Loading

0 comments on commit 7757c00

Please sign in to comment.