-
Notifications
You must be signed in to change notification settings - Fork 69
1719: Rust Integration #1913
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
laert-ll
wants to merge
28
commits into
devonfw:main
Choose a base branch
from
laert-ll:feature/1719-rust-integration
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
1719: Rust Integration #1913
Changes from all commits
Commits
Show all changes
28 commits
Select commit
Hold shift + click to select a range
06832b9
Add Rust URL updater using rustup script
tmukh 844d8dd
Add Rust commandlet installer with Windows MSVC setup
tmukh fca354a
#1719: Change Rust MSVC Name
tmukh 58f45de
Added Rust commandlet properties
tmukh e9a55a7
Apply suggestions from code review
hohwille 2342b92
fix installDependencies
hohwille c2e1c7d
do not mock commandlet
hohwille 65fe33e
#1719: Refactor LocalToolCommandlet and Rust.java
laert-ll 99e7bd4
#1719: Add getDownloadedToolFile method
laert-ll 4facfe8
#1719: More refactoring
laert-ll 325c3f3
#1719: Revert unnecessary docstring change
laert-ll 0094c8a
#1719: Cleanup
laert-ll d9c6f7d
#1719: Cleanup
laert-ll 7f44635
#1719: Rename of RustGithubUrlTagUpdaterTest
laert-ll 4ab5e21
#1719: Revert rename of RustGithubUrlTagUpdaterTest
laert-ll 6ba349b
#1719: Removed installDependencies method
laert-ll eeede76
#1719: MSVC url updater and installation with dependencies.json
laert-ll 91a346a
#1719: MSVC download link
laert-ll 4d34c41
#1719: Fixing MSVC commandlet
laert-ll ba3671a
#1719: Fix MSVC commandlet
laert-ll ba5d98f
#1719: Refactor MSVC commandlet
laert-ll 302a4cc
#1719: Add MSVC help message
laert-ll 48e915c
#1719: Temporary tests fix
laert-ll bd951d4
#1719: Extend RustTest.java
laert-ll 7fb9752
#1719: Remove unnecessary RustGithubUrlTagUpdaterTest.java
laert-ll 342d5d1
#1719: Add License, tiny Msvc.java tweaks
laert-ll decc25f
#1719: Cleanup
laert-ll 5271024
Merge branch 'main' into feature/1719-rust-integration
laert-ll File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
46 changes: 46 additions & 0 deletions
46
cli/src/main/java/com/devonfw/tools/ide/tool/msvc/Msvc.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,46 @@ | ||
| package com.devonfw.tools.ide.tool.msvc; | ||
|
|
||
| import java.nio.file.Path; | ||
| import java.util.Set; | ||
|
|
||
| import com.devonfw.tools.ide.cli.CliException; | ||
| import com.devonfw.tools.ide.common.Tag; | ||
| import com.devonfw.tools.ide.context.IdeContext; | ||
| import com.devonfw.tools.ide.process.ProcessErrorHandling; | ||
| import com.devonfw.tools.ide.tool.LocalToolCommandlet; | ||
| import com.devonfw.tools.ide.tool.ToolInstallRequest; | ||
|
|
||
| public class Msvc extends LocalToolCommandlet { | ||
|
|
||
| private static final String MSVC_SETUP_URL = "https://aka.ms/vs/17/release/vs_BuildTools.exe"; | ||
|
|
||
| public Msvc(IdeContext context) { | ||
| super(context, "msvc", Set.of(Tag.BUILD, Tag.CPP)); | ||
| } | ||
|
|
||
| @Override | ||
| protected void performToolInstallation(ToolInstallRequest request, Path installationPath) { | ||
|
laert-ll marked this conversation as resolved.
|
||
|
|
||
| if (!this.context.getSystemInfo().isWindows()) { | ||
| throw new CliException("The tool 'msvc' is only available on Windows."); | ||
| } | ||
|
|
||
| this.context.getFileAccess().mkdirs(installationPath); | ||
|
|
||
| Path installer = this.context.getDownloadPath().resolve("vs_BuildTools.exe"); | ||
| this.context.newProcess().errorHandling(ProcessErrorHandling.THROW_CLI) | ||
| .executable("curl.exe") | ||
| .addArgs("-fSL", "-o", installer.toString(), MSVC_SETUP_URL) | ||
| .run(); | ||
|
|
||
| this.context.writeVersionFile(request.getRequested().getResolvedVersion(), installationPath); | ||
|
|
||
| this.context.newProcess().errorHandling(ProcessErrorHandling.THROW_CLI) | ||
| .executable(installer) | ||
| .withExitCodeAcceptor(code -> (code == 0) || (code == 3010)) | ||
| .addArgs("--installPath", installationPath.toString(), | ||
| "--add", "Microsoft.VisualStudio.Workload.VCTools", | ||
| "--quiet", "--wait", "--norestart", "--nocache") | ||
| .run(); | ||
| } | ||
| } | ||
97 changes: 97 additions & 0 deletions
97
cli/src/main/java/com/devonfw/tools/ide/tool/rust/Rust.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,97 @@ | ||
| package com.devonfw.tools.ide.tool.rust; | ||
|
|
||
| import java.nio.file.Files; | ||
| import java.nio.file.LinkOption; | ||
| import java.nio.file.Path; | ||
| import java.util.List; | ||
| import java.util.Set; | ||
|
|
||
| import com.devonfw.tools.ide.common.Tag; | ||
| import com.devonfw.tools.ide.context.IdeContext; | ||
| import com.devonfw.tools.ide.io.FileAccess; | ||
| import com.devonfw.tools.ide.process.EnvironmentContext; | ||
| import com.devonfw.tools.ide.process.ProcessContext; | ||
| import com.devonfw.tools.ide.process.ProcessErrorHandling; | ||
| import com.devonfw.tools.ide.tool.LocalToolCommandlet; | ||
| import com.devonfw.tools.ide.tool.ToolInstallRequest; | ||
| import com.devonfw.tools.ide.tool.ToolInstallation; | ||
| import com.devonfw.tools.ide.version.VersionIdentifier; | ||
|
|
||
| /** | ||
| * {@link LocalToolCommandlet} for <a href="https://www.rust-lang.org/">Rust</a>. | ||
| */ | ||
| public class Rust extends LocalToolCommandlet { | ||
|
|
||
| /** | ||
| * The constructor. | ||
| * | ||
| * @param context the {@link IdeContext}. | ||
| */ | ||
| public Rust(IdeContext context) { | ||
|
|
||
| super(context, "rust", Set.of(Tag.RUST)); | ||
| } | ||
|
|
||
| @Override | ||
| public String getBinaryName() { | ||
|
|
||
| return "rustc"; | ||
| } | ||
|
|
||
| @Override | ||
| public String getToolHelpArguments() { | ||
|
|
||
| return "--help"; | ||
| } | ||
|
|
||
| @Override | ||
| protected boolean isExtract() { | ||
|
|
||
| // The rustup installer script is an executable script and must not be extracted. | ||
| return false; | ||
| } | ||
|
|
||
| @Override | ||
| protected void installDownloadedToolPayload(ToolInstallRequest request, Path installationPath, Path installerScript) { | ||
|
|
||
| VersionIdentifier resolvedVersion = request.getRequested().getResolvedVersion(); | ||
| FileAccess fileAccess = this.context.getFileAccess(); | ||
|
|
||
| Path cargoHome = installationPath.resolve(".cargo"); | ||
| Path rustupHome = installationPath.resolve(".rustup"); | ||
| fileAccess.mkdirs(cargoHome); | ||
| fileAccess.mkdirs(rustupHome); | ||
|
|
||
| if (Files.isDirectory(installerScript)) { | ||
| // ToolRepositoryMock may provide an unpacked folder instead of a single download file. | ||
| installerScript = installerScript.resolve("content.sh"); | ||
| } | ||
|
|
||
| ProcessContext process = request.getProcessContext().createChild().errorHandling(ProcessErrorHandling.THROW_CLI).directory(installationPath) | ||
| .withEnvVar("CARGO_HOME", cargoHome.toString()).withEnvVar("RUSTUP_HOME", rustupHome.toString()); | ||
|
|
||
| List<String> installerArgs = List.of("-y", "--no-modify-path", "--profile", "default", "--default-toolchain", resolvedVersion.toString()); | ||
|
|
||
| process.executable(this.context.findBashRequired()).addArgs(installerScript.toAbsolutePath().toString()).addArgs(installerArgs); | ||
| process.run(); | ||
|
|
||
| Path cargoBin = cargoHome.resolve("bin"); | ||
| Path toolBin = installationPath.resolve("bin"); | ||
| if (Files.exists(toolBin, LinkOption.NOFOLLOW_LINKS)) { | ||
| fileAccess.delete(toolBin); | ||
| } | ||
| if (Files.isDirectory(cargoBin)) { | ||
| fileAccess.symlink(cargoBin, toolBin); | ||
| } | ||
| } | ||
|
|
||
| @Override | ||
| public void setEnvironment(EnvironmentContext environmentContext, ToolInstallation toolInstallation, boolean additionalInstallation) { | ||
|
|
||
| super.setEnvironment(environmentContext, toolInstallation, additionalInstallation); | ||
| Path rootDir = toolInstallation.rootDir(); | ||
| environmentContext.withEnvVar("CARGO_HOME", rootDir.resolve(".cargo").toString()); | ||
| environmentContext.withEnvVar("RUSTUP_HOME", rootDir.resolve(".rustup").toString()); | ||
| } | ||
|
|
||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
52 changes: 52 additions & 0 deletions
52
cli/src/test/java/com/devonfw/tools/ide/tool/rust/RustTest.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,52 @@ | ||
| package com.devonfw.tools.ide.tool.rust; | ||
|
|
||
| import java.nio.file.Path; | ||
|
|
||
| import org.junit.jupiter.api.Test; | ||
|
|
||
| import com.devonfw.tools.ide.context.AbstractIdeContextTest; | ||
| import com.devonfw.tools.ide.context.IdeTestContext; | ||
|
|
||
| /** | ||
| * Test of {@link Rust}. | ||
| */ | ||
| class RustTest extends AbstractIdeContextTest { | ||
|
|
||
| private static final String PROJECT_RUST = "rust"; | ||
|
|
||
| private static final String RUST_VERSION = "1.80.1"; | ||
|
|
||
| @Test | ||
| void testRustInstallViaRustupScript() { | ||
|
|
||
| // arrange | ||
| IdeTestContext context = newContext(PROJECT_RUST); | ||
| Rust rust = new Rust(context); | ||
|
|
||
| // act | ||
| rust.install(); | ||
|
|
||
| // assert | ||
| assertThat(context.getSoftwarePath().resolve("rust/.ide.software.version")).exists().hasContent(RUST_VERSION); | ||
| assertThat(context).logAtSuccess().hasMessageContaining("Successfully installed rust in version " + RUST_VERSION); | ||
| } | ||
|
|
||
| @Test | ||
| void testRustInstallProducesCargoLayoutAndBinLink() { | ||
|
|
||
| // arrange | ||
| IdeTestContext context = newContext(PROJECT_RUST); | ||
| Rust rust = new Rust(context); | ||
| String rustcName = context.getSystemInfo().isWindows() ? "rustc.cmd" : "rustc"; | ||
|
|
||
| // act | ||
| rust.install(); | ||
|
|
||
| // assert | ||
| Path softwareRust = context.getSoftwarePath().resolve("rust"); | ||
| assertThat(softwareRust.resolve(".cargo")).exists(); | ||
| assertThat(softwareRust.resolve(".rustup")).exists(); | ||
| assertThat(softwareRust.resolve(".cargo/bin").resolve(rustcName)).exists(); | ||
| assertThat(softwareRust.resolve("bin").resolve(rustcName)).exists(); | ||
| } | ||
| } |
2 changes: 2 additions & 0 deletions
2
cli/src/test/resources/ide-projects/rust/_ide/urls/rust/rust/1.80.1/urls
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,2 @@ | ||
| https://sh.rustup.rs | ||
|
|
Empty file.
Empty file.
17 changes: 17 additions & 0 deletions
17
cli/src/test/resources/ide-projects/rust/repository/rust/rust/default/content.sh
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,17 @@ | ||
| #!/usr/bin/env bash | ||
| set -eu | ||
|
|
||
| mkdir -p "${CARGO_HOME}/bin" | ||
| mkdir -p "${RUSTUP_HOME}" | ||
|
|
||
| cat > "${CARGO_HOME}/bin/rustc" <<'EOF' | ||
| #!/usr/bin/env bash | ||
| echo rustc "$@" | ||
| EOF | ||
| chmod +x "${CARGO_HOME}/bin/rustc" | ||
|
|
||
| cat > "${CARGO_HOME}/bin/rustc.cmd" <<'EOF' | ||
| @echo off | ||
| echo rustc %* | ||
| EOF | ||
|
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Regarding
installDownloadedToolPayload, I'm not exactly sure what to name this new hook, given that there are already a lot of methods in this file containing the wordinstallin it.