Skip to content

Commit

Permalink
Update build scripts to adapt to sim-server build pipeline changes (#674
Browse files Browse the repository at this point in the history
)

In sim-server repo, we're updating the build pipleine to distribute
linux binaries. Because of that, we're adaping a new naming scheme,
where each binary gets platform specific suffix (simulator-server-macos,
simulator-server-windows.exe and simulator-server-linux). Along with
those changes we are making some housekeeping tasks related to build
scripts like removing the need for passing debug/release config as we
already migrated to a process where release builds are only made on CI
while the local builds are scoped to development only.

With the changes made, we will no longer require people to manually
download simulator server binaries as now the dev build script can fetch
them from the releases page.

As part of this PR we're also removing code that'd copy binaries during
extension initialization. It is no longer necessary because when
installing the VSIX file, the binary file permission no longer occurs.

What this PR is not solving (but we didn't have a way of doing that
before anyway) is to give ability to use simulator-server versions
updated in between IDE releases. Now, users are only able to use
binaries that are included in IDE release, but if some code change that
is in main requires updated simulator-server, there's no way in the
current flow to publish that and let the people use it.

### How Has This Been Tested: 
1. Build release package and test it with cursor and vscode
2. Clone new repo w/o sim-server and test development builds
3. Test dev builds in normal environment

---------

Co-authored-by: Jakub Baliński <[email protected]>
  • Loading branch information
kmagiera and balins authored Oct 30, 2024
1 parent efe6b34 commit e1de19f
Show file tree
Hide file tree
Showing 8 changed files with 42 additions and 76 deletions.
18 changes: 6 additions & 12 deletions packages/docs/docs/development.md
Original file line number Diff line number Diff line change
Expand Up @@ -36,23 +36,17 @@ npm install
### 3. Prepare simulator server build

Simulator server repository is not open sourced but we have a pre-build binaries published on the GitHub releases page.
First, you need to navigate to the [releases page on GitHub](https://github.com/software-mansion/radon-ide/releases), open the recent release, and download the sim-server file from "Assets" section (the filename contains a git hash for build consistency):

<img width="825" alt="download-sim-server" src="/img/docs/download_sim_server.png"/>

Next, place the downloaded file under `packages/vscode-extension/dist`.

Finally, run the following script inside `packages/vscode-extension` directory:
There's a script that fetches the latest version of the binaries from the [releases page on GitHub](https://github.com/software-mansion/radon-ide/releases) – you can run it using the following command:

```bash
npm run build:sim-server-debug
```

In case of any errors, please read the output of this command before proceeding.
Note that some changes in the extension may depend on changes made to the simulator server, so you occasionally may need to re-run this script, for example when switching git branches.

### 4. Open extension project in Visual Studio Code

It is necessary that you open that exact folder rather than the whole repository, as it contains project specific run configuration for launching the extension in development mode.
It is necessary that you open exactly the main extension folder rather than the whole repository, as it contains project specific run configuration for launching the extension in development mode.
You can do it by opening new window in Visual Studio Code and using `File > Open Folder` option, then select `packages/vscode-extension`, or if you have vscode's command line tool installed you can open it using command:

```sh
Expand Down Expand Up @@ -97,7 +91,7 @@ depend on `expo-router` and `expo-icons`.

To use them in the app:
1. Add npm command in test app package.json
- for expo-router apps: `"copy-shared": "../shared/copy.sh expo-router ./shared"`.
- for expo-router apps: `"copy-shared": "../shared/copy.sh expo-router ./shared"`.
- for RN apps: `"copy-shared": "../shared/copy.sh bare ./shared"`.
2. Run it: `npm run copy-shared`. This copies shared components to `./shared`.
3. For RN apps, replace `App.tsx` with the `./shared/MainScreen.tsx` component.
Expand All @@ -124,9 +118,9 @@ To use them in the app:

You can also use other components in `shared` (e.g. `Text`, `Button`,
`useScheme`) to theme the app.

After updating shared components you need to copy them again by running
`npm run copy-shared` in every test app.
`npm run copy-shared` in every test app.

`shared/copy.sh bare|expo-router DEST` script works by copying shared directory to `DEST`
and removing `navigation` directory if `bare` argument is used.
Binary file not shown.
2 changes: 1 addition & 1 deletion packages/simulator-server
2 changes: 1 addition & 1 deletion packages/vscode-extension/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -432,7 +432,7 @@
"build:extension-code": "esbuild ./src/extension.ts --bundle --outfile=dist/extension.js --external:vscode --format=cjs --platform=node --minify && cp ./node_modules/source-map/lib/mappings.wasm dist/.",
"build:expo-fingerprint": "esbuild ./node_modules/@expo/fingerprint/build/sourcer/ExpoConfigLoader.js --bundle --format=cjs --outfile=dist/ExpoConfigLoader.js --platform=node --minify",
"build:webview": "vite build --mode production && cp ./node_modules/@vscode/codicons/dist/codicon.* dist/.",
"build:sim-server-debug": "bash ./scripts/build-sim-server.sh dist Debug",
"build:sim-server-debug": "bash ./scripts/build-sim-server-debug.sh dist",
"build:sim-server": "bash ./scripts/install-sim-server-release-build.sh dist",
"build:debug": "npm run build:extension-debug && npm run build:sim-server-debug",
"build:dist": "npm run build:extension && npm run build:sim-server && npm run build:webview",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,36 +6,42 @@ cd "$(dirname "$0")/.."
# take output directory from first argument or default to out - relative to the vscode-extension package location
output_dir="${1:-out}"

# take configuration from second argument or default to Debug
configuration=${2:-Debug}

submodule_status=$(git submodule status ../simulator-server)


if [[ $submodule_status == -* ]]; then # submodule is not initialized

submodule_hash=$(git ls-tree HEAD ../simulator-server | awk '{print $3}')
# get version of npm module
latest_tag=$(git describe --tags --abbrev=0)
download_base_url="https://github.com/software-mansion/radon-ide/releases/download/${latest_tag}/"

if [[ "$OSTYPE" == "msys" || "$OSTYPE" == "cygwin" ]]; then
product_path="$output_dir/sim-server-Release-${submodule_hash}.exe"
product_path="$output_dir/simulator-server-${latest_tag}-windows.exe"
download_url="${download_base_url}simulator-server-windows.exe"
elif [[ "$OSTYPE" == "darwin"* ]]; then
product_path="$output_dir/simulator-server-${latest_tag}-macos"
download_url="${download_base_url}simulator-server-macos"
else
product_path="$output_dir/sim-server-Release-${submodule_hash}"
product_path="$output_dir/simulator-server-${latest_tag}-linux"
download_url="${download_base_url}simulator-server-linux"
fi

# if the binary is not present, print instructions to download it from releases page:
# if the binary is not present, download it from Radon IDE releases page
if [[ ! -f "$product_path" ]]; then
echo "Simulator server binary not found: $product_path"
echo ""
echo "Make sure to follow development setup instructions: https://ide.swmansion.com/docs/development"
echo "You can download the binary from the releases page on GitHub: https://github.com/software-mansion/radon-ide/releases"
echo "Downloading the binary from the Radon IDE releases page..."
echo ""
curl -L "$download_url" -o "$product_path" -f -# --create-dirs
fi

if [[ ! -f "$product_path" ]]; then
echo "Failed to download the binary. Aborting."
exit 1
fi

else # submodule is initialized

# For release builds we always make sure that submodule is up to date
if [[ $configuration == "Release" ]]; then
git submodule update --init -- ../simulator-server
fi

if [[ $submodule_status == +* ]]; then # submodule is not up-to-date
echo "Submodule has changes. Continue? [y/n]"
# read answer or abort if no input is provided in 5 seconds
Expand All @@ -47,7 +53,7 @@ fi

# execute the build from the simulator-server package
# the build product location is printed by the build script as the very last line
product_path=$("../simulator-server/scripts/build.sh" "$configuration" | tail -n 1)
product_path=$("../simulator-server/scripts/build-extension-dev.sh" | tail -n 1)

# Check if the build was successful
if [[ $? -ne 0 ]]; then
Expand All @@ -60,17 +66,17 @@ fi # submodule check

# Create the target directory if it doesn't exist
mkdir -p "$output_dir"
target_location="$output_dir/sim-server"

if [[ "$OSTYPE" == "msys" || "$OSTYPE" == "cygwin" ]]; then # rename to *.exe on Windows
mv "$product_path" "$target_location-executable.exe"
exit 0
if [[ "$OSTYPE" == "msys" || "$OSTYPE" == "cygwin" ]]; then
target_location="$output_dir/simulator-server-windows.exe"
elif [[ "$OSTYPE" == "darwin"* ]]; then
target_location="$output_dir/simulator-server-macos"
else
target_location="$output_dir/simulator-server-linux"
fi

# Check if a file was found and copy it
if [[ -n $product_path ]]; then
# copy it using dd to avoid permission issues
dd if="$product_path" of="$target_location" 2> /dev/null
cp "$product_path" "$target_location"
# add execution permissions
chmod +x "$target_location"
else
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,13 +34,8 @@ mkdir -p "$output_dir"
# Get tag of simulator-server submodule
sim_server_tag=$(git -C ../simulator-server describe --tags)

echo "Downloading sim-server binaries for tag $sim_server_tag"
echo "Downloading simulator-server binaries for tag $sim_server_tag"

# Download Mac and Windows binaries using gh CLI and place them in the correcto location
mac_binary_path="$output_dir/sim-server"
gh release download $sim_server_tag -R software-mansion-labs/simulator-server -p simulator-server -O "$mac_binary_path"
chmod +x "$mac_binary_path"

win_binary_path="$output_dir/sim-server-executable.exe"
gh release download $sim_server_tag -R software-mansion-labs/simulator-server -p simulator-server.exe -O "$win_binary_path"
chmod +x "$win_binary_path"
# Download simulator-server binaries using gh CLI and place them in the output directory with correct file mode
gh release download $sim_server_tag -R software-mansion-labs/simulator-server -p "simulator-server*" -D "$output_dir"
chmod +x "$output_dir"/simulator-server*
2 changes: 1 addition & 1 deletion packages/vscode-extension/src/devices/preview.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ export class Preview implements Disposable {
const simControllerBinary = path.join(
extensionContext.extensionPath,
"dist",
Platform.select({ macos: "sim-server-executable", windows: "sim-server-executable.exe" })
Platform.select({ macos: "simulator-server-macos", windows: "simulator-server-windows.exe" })
);

Logger.debug(`Launch preview ${simControllerBinary} ${this.args}`);
Expand Down
31 changes: 1 addition & 30 deletions packages/vscode-extension/src/extension.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ import {
setAppRootFolder,
setExtensionContext,
} from "./utilities/extensionContext";
import { command, setupPathEnv } from "./utilities/subprocess";
import { setupPathEnv } from "./utilities/subprocess";
import { SidePanelViewProvider } from "./panels/SidepanelViewProvider";
import { PanelLocation } from "./common/WorkspaceConfig";
import { getLaunchConfiguration } from "./utilities/launchConfiguration";
Expand Down Expand Up @@ -75,14 +75,6 @@ export async function activate(context: ExtensionContext) {

migrateOldConfiguration();

if (Platform.OS === "macos") {
try {
await fixMacosBinary(context);
} catch (error) {
Logger.error("Error when processing simulator-server binaries", error);
// we let the activation continue, as otherwise the diagnostics command would fail
}
}
commands.executeCommand("setContext", "RNIDE.sidePanelIsClosed", false);

async function showIDEPanel(fileName?: string, lineNumber?: number) {
Expand Down Expand Up @@ -461,24 +453,3 @@ function migrateOldConfiguration() {
Logger.error("Error when migrating old configuration", e);
}
}

async function fixMacosBinary(context: ExtensionContext) {
// MacOS prevents binary files from being executed when downloaded from the internet.
// It requires notarization ticket to be available in the package where the binary was distributed
// with. Apparently Apple does not allow for individual binary files to be notarized and only .app/.pkg and .dmg
// files are allowed. To prevent the binary from being quarantined, we clone using byte-copy (with dd). This way the
// quarantine attribute is removed. We try to do it only when the binary has been modified or for the new installation,
// we detect that based on the modification date of the binary file.
const buildBinPath = Uri.file(context.asAbsolutePath("dist/sim-server"));
const exeBinPath = Uri.file(context.asAbsolutePath("dist/sim-server-executable"));

// if build and exe binaries don't match, we need to clone the build binary – we always want the exe one to the exact
// copy of the build binary:
try {
await command(`diff -q ${buildBinPath.fsPath} ${exeBinPath.fsPath}`);
} catch (error) {
// if binaries are different, diff will return non-zero code and we will land in catch clouse
await command(`dd if=${buildBinPath.fsPath} of=${exeBinPath.fsPath}`);
}
await fs.promises.chmod(exeBinPath.fsPath, 0o755);
}

0 comments on commit e1de19f

Please sign in to comment.