Skip to content
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

Add Flatpak build system and support #12006

Merged
merged 58 commits into from
May 28, 2024
Merged
Show file tree
Hide file tree
Changes from 10 commits
Commits
Show all changes
58 commits
Select commit Hold shift + click to select a range
75f2251
Copy metainfo from old PR
someone13574 May 17, 2024
a5da0f4
Add `flatpak-cargo-generator.py`
someone13574 May 17, 2024
5bb1664
Replace git checkout with git reset in flatpak-cargo-generator.py
someone13574 May 17, 2024
3c9e57f
Hard-code file names in flatpak-cargo-generator.py
someone13574 May 17, 2024
4a1de36
Package cli
someone13574 May 17, 2024
1cda1b3
Breaking through the flatpak sandbox
someone13574 May 18, 2024
2361acd
Add docs
someone13574 May 18, 2024
fed0e5c
Add screenshots to metainfo file
someone13574 May 18, 2024
ff52c99
Fix type
someone13574 May 18, 2024
c8ecd16
Fix mac build (didn't change to P: AsRef<Path>)
someone13574 May 18, 2024
c2cded1
Fix dead screenshot links
someone13574 May 18, 2024
ccbc897
Replace session bus access with specific talk name
someone13574 May 18, 2024
9ffc5bb
Add python modules to flatpak deps and use --user
someone13574 May 18, 2024
672de4c
Run cli outside of sandbox as well.
someone13574 May 18, 2024
aaad2c7
Use flatpak XDG home dirs
someone13574 May 18, 2024
fd880c6
Fix CI
someone13574 May 18, 2024
e8fa32e
Remove conditional compilation
someone13574 May 18, 2024
3c707df
Disable auto-update
someone13574 May 18, 2024
8ade10e
Flatpak release note drafter
someone13574 May 18, 2024
23ed3e5
Use list for features section of metainfo
someone13574 May 18, 2024
5713658
Remove manifest
someone13574 May 19, 2024
36756fd
Add utility category to desktop entry (extended from TextEditor)
someone13574 May 19, 2024
f8ebac0
Add scripts for generating manifests for different channels
someone13574 May 19, 2024
339673b
Add option to copy binaries from `target`
someone13574 May 19, 2024
d2b6116
Add icon warning for copy mode to generate-manifest
someone13574 May 19, 2024
42b7bb0
Set branding colors per-channel
someone13574 May 19, 2024
976b2f1
Add note for how to build cli in docs
someone13574 May 19, 2024
d4cf74d
Only use flatpak's xdg dir for our own files
someone13574 May 19, 2024
32c1bd8
Fix StartupNotify problem
someone13574 May 19, 2024
d0277ce
Per channel release info
someone13574 May 20, 2024
4baa04c
Merge branch 'zed-industries:main' into flatpak-2
someone13574 May 20, 2024
fedcc7b
Meson build system
someone13574 May 20, 2024
ecf5c1a
Use dictionary in `generate-manifest`
someone13574 May 20, 2024
03efeb8
Revert "Meson build system"
someone13574 May 21, 2024
7df2c7f
Remove screenshots
someone13574 May 21, 2024
06bc476
Revert `draft-release-notes`
someone13574 May 21, 2024
bf0edd8
Rename `template.metainfo.xml`
someone13574 May 21, 2024
6145151
Stub screenshot links
someone13574 May 21, 2024
5e91d40
Release notes markdown to xml script
someone13574 May 21, 2024
9e5b621
Fix generate-manifest file broken by bad revert
someone13574 May 21, 2024
9510692
Simplify build process
someone13574 May 22, 2024
e47183b
Remove old linux builds from target
someone13574 May 22, 2024
fbf9b8a
Add missing newlines to files
maxdeviant May 22, 2024
c2e71d2
Re-add screenshots
someone13574 May 22, 2024
9eeebdd
Bundle shared libs
someone13574 May 22, 2024
40b8f63
Cleanup `convert-release-notes.py`
someone13574 May 22, 2024
0a89a9d
Merge branch 'zed-industries:main' into flatpak-2
someone13574 May 22, 2024
326a285
Make closing code fence have code formatting
someone13574 May 23, 2024
607d7e5
Don't remove indentation in code blocks.
someone13574 May 23, 2024
fab9e2f
Fix old tar removal
someone13574 May 23, 2024
6fc2713
Remove `-pre` suffix from appstream version
someone13574 May 23, 2024
8496faa
Merge branch 'zed-industries:main' into flatpak-2
someone13574 May 23, 2024
c1eff6b
Adjust flatpak documentation to clarify how Zed works with the sandbox
mikayla-maki May 24, 2024
7e2f9ba
Capitalization
mikayla-maki May 24, 2024
a7a2aa7
Check if flatpak id is correct before exiting sandbox
someone13574 May 25, 2024
167de69
Add env variable to disable sandbox escape
someone13574 May 26, 2024
f3bd59f
Fix for none x86_64 archs
someone13574 May 27, 2024
630a11c
Remove leaveover deps
someone13574 May 27, 2024
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -25,3 +25,5 @@ DerivedData/
.blob_store
.vscode
.wrangler
.flatpak-builder
flatpak-cargo-sources.json
3 changes: 3 additions & 0 deletions crates/cli/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,9 @@ doctest = false
name = "cli"
path = "src/main.rs"

[features]
flatpak = []

[dependencies]
anyhow.workspace = true
clap.workspace = true
Expand Down
72 changes: 57 additions & 15 deletions crates/cli/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@ struct Args {
/// Run zed in the foreground (useful for debugging)
#[arg(long)]
foreground: bool,
#[cfg(not(feature = "flatpak"))]
/// Custom path to Zed.app or the zed binary
#[arg(long)]
zed: Option<PathBuf>,
Expand Down Expand Up @@ -72,7 +73,12 @@ fn main() -> Result<()> {
}
let args = Args::parse();

let app = Detect::detect(args.zed.as_deref()).context("Bundle detection")?;
#[cfg(feature = "flatpak")]
let binary_path = Some("/app/bin/zed-app");
#[cfg(not(feature = "flatpak"))]
let binary_path = args.zed;

let app = Detect::detect(binary_path).context("Bundle detection")?;

if args.version {
println!("{}", app.zed_version_string());
Expand Down Expand Up @@ -174,9 +180,9 @@ mod linux {
struct App(PathBuf);

impl Detect {
pub fn detect(path: Option<&Path>) -> anyhow::Result<impl InstalledApp> {
pub fn detect<P: AsRef<Path>>(path: Option<P>) -> anyhow::Result<impl InstalledApp> {
let path = if let Some(path) = path {
path.to_path_buf().canonicalize()
path.as_ref().to_path_buf().canonicalize()
} else {
let cli = env::current_exe()?;
let dir = cli
Expand Down Expand Up @@ -226,15 +232,29 @@ mod linux {
}

fn run_foreground(&self, ipc_url: String) -> io::Result<ExitStatus> {
std::process::Command::new(self.0.clone())
.arg(ipc_url)
.status()
#[cfg(not(feature = "flatpak"))]
let program = self.0.clone();
#[cfg(feature = "flatpak")]
let program = "/usr/bin/flatpak-spawn";

let args = vec![OsString::from(ipc_url)];
#[cfg(feature = "flatpak")]
let args = flatpak_spawn_args(args);

std::process::Command::new(program).args(args).status()
}
}

impl App {
fn boot_background(&self, ipc_url: String) -> anyhow::Result<()> {
let path = &self.0;
#[cfg(not(feature = "flatpak"))]
let program = self.0.clone();
#[cfg(feature = "flatpak")]
let program = "/usr/bin/flatpak-spawn";

let args = vec![OsString::from(&program), OsString::from(ipc_url)];
#[cfg(feature = "flatpak")]
let args = flatpak_spawn_args(args);

match fork::fork() {
Ok(Fork::Parent(_)) => Ok(()),
Expand All @@ -249,10 +269,9 @@ mod linux {
eprintln!("failed to close_fd: {}", std::io::Error::last_os_error());
}
}
let error =
exec::execvp(path.clone(), &[path.as_os_str(), &OsString::from(ipc_url)]);
let error = exec::execvp(&program, args);
// if exec succeeded, we never get here.
eprintln!("failed to exec {:?}: {}", path, error);
eprintln!("failed to exec {:?}: {}", program, error);
process::exit(1)
}
Err(_) => Err(anyhow!(io::Error::last_os_error())),
Expand All @@ -273,6 +292,26 @@ mod linux {
sock.connect_addr(&sock_addr)
}
}

#[cfg(feature = "flatpak")]
fn flatpak_spawn_args(mut args: Vec<OsString>) -> Vec<OsString> {
// When running flatpak-spawn with --host, we no longer have access to /app/bin, so we need to find the location on the host system
let install_dir = std::process::Command::new("/usr/bin/flatpak-spawn")
.arg("--host")
.arg("flatpak")
.arg("info")
.arg("--show-location")
.arg(env::var("FLATPAK_ID").unwrap())
.output()
.unwrap();
let install_dir = PathBuf::from(String::from_utf8(install_dir.stdout).unwrap().trim());
let app_cmd = install_dir.join("files").join("bin").join("zed-app");

let mut out_args = vec!["--host".into()];
out_args.push(app_cmd.into());
out_args.append(&mut args);
out_args
}
}

// todo("windows")
Expand All @@ -297,7 +336,7 @@ mod windows {
}

impl Detect {
pub fn detect(_path: Option<&Path>) -> anyhow::Result<impl InstalledApp> {
pub fn detect<P: AsRef<Path>>(_path: Option<P>) -> anyhow::Result<impl InstalledApp> {
Ok(App)
}
}
Expand Down Expand Up @@ -354,11 +393,14 @@ mod mac_os {
}

impl Detect {
pub fn detect(path: Option<&Path>) -> anyhow::Result<impl InstalledApp> {
pub fn detect<P: AsRef<Path>>(path: Option<P>) -> anyhow::Result<impl InstalledApp> {
let bundle_path = if let Some(bundle_path) = path {
bundle_path
.canonicalize()
.with_context(|| format!("Args bundle path {bundle_path:?} canonicalization"))?
bundle_path.as_ref().canonicalize().with_context(|| {
format!(
"Args bundle path {:?} canonicalization",
bundle_path.as_ref()
)
})?
} else {
locate_bundle().context("bundle autodiscovery")?
};
Expand Down
82 changes: 82 additions & 0 deletions crates/zed/resources/flatpak/dev.zed.Zed.metainfo.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,82 @@
<?xml version="1.0" encoding="UTF-8"?>
<component type="desktop-application">
<id>dev.zed.Zed</id>
<metadata_license>MIT</metadata_license>
<project_license>AGPL-3.0-or-later and Apache-2.0 and GPL-3.0-or-later</project_license>

<name>Zed</name>
<summary>High-performance, multiplayer code editor</summary>
<developer id="dev.zed">
<name translate="no">Zed Industries, Inc.</name>
</developer>
<description>
<p>
Productive coding starts with a tool that stays out of your way. Zed blends the power of an IDE with the speed of a lightweight editor for productivity you can feel under your fingertips.
</p>
<p>Features:</p>
<p>
Performance: Efficiently uses every CPU core and your GPU for instant startup, quick file loading, and responsive keystrokes.
</p>
<p>
Language-aware: Maintains a syntax tree for precise highlighting, and auto-indent, with LSP support for autocompletion and refactoring.
</p>
<p>
Collaboration: Real-time editing and navigation for multiple developers in a shared workspace.
</p>
<p>
AI Integration: Integrates GitHub Copilot and GPT-4 for natural language code generation.
</p>
</description>

<launchable type="desktop-id">dev.zed.Zed.desktop</launchable>

<branding>
<color type="primary" scheme_preference="light">#99c1f1</color>
<color type="primary" scheme_preference="dark">#3180df</color>
</branding>

<content_rating type="oars-1.1">
<content_attribute id="social-chat">intense</content_attribute>
<content_attribute id="social-audio">intense</content_attribute>
</content_rating>

<url type="homepage">https://zed.dev</url>
<url type="bugtracker">https://github.com/zed-industries/zed/issues</url>
<url type="faq">https://zed.dev/faq</url>
<url type="help">https://zed.dev/docs/getting-started</url>
<url type="contact">https://zed.dev/docs/feedback-and-support</url>
<url type="vcs-browser">https://github.com/zed-industries/zed</url>
<url type="contribute">https://github.com/zed-industries/zed/blob/main/CONTRIBUTING.md</url>

<supports>
<internet>offline-only</internet>
</supports>
<recommends>
<control>pointing</control>
<control>keyboard</control>
<display_length compare="ge">768</display_length>
</recommends>

<screenshots>
<screenshot type="default">
<caption>Zed with a large project open, showing language server and gitblame support</caption>
<image type="source" width="1122" height="859" xml:lang="en">https://raw.githubusercontent.com/someone13574/zed/flatpak/crates/zed/resources/flatpak/screenshots/screenshot-0.png</image>
someone13574 marked this conversation as resolved.
Show resolved Hide resolved
</screenshot>
<screenshot>
<caption>Zed with a file open and a channel message thread in the right sidebar</caption>
<image type="source" width="1122" height="859" xml:lang="en">https://raw.githubusercontent.com/someone13574/zed/flatpak/crates/zed/resources/flatpak/screenshots/screenshot-1.png</image>
</screenshot>
<screenshot>
<caption>Example of a channel's shared document</caption>
<image type="source" width="1122" height="859" xml:lang="en">https://raw.githubusercontent.com/someone13574/zed/flatpak/crates/zed/resources/flatpak/screenshots/screenshot-2.png</image>
</screenshot>
<screenshot>
<caption>Zed's extension list</caption>
<image type="source" width="1122" height="859" xml:lang="en">https://raw.githubusercontent.com/someone13574/zed/flatpak/crates/zed/resources/flatpak/screenshots/screenshot-3.png</image>
</screenshot>
<screenshot>
<caption>Theme switcher UI and example theme</caption>
<image type="source" width="1122" height="859" xml:lang="en">https://raw.githubusercontent.com/someone13574/zed/flatpak/crates/zed/resources/flatpak/screenshots/screenshot-4.png</image>
</screenshot>
</screenshots>
</component>
someone13574 marked this conversation as resolved.
Show resolved Hide resolved
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
64 changes: 64 additions & 0 deletions dev.zed.Zed.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
{
"id": "dev.zed.Zed",
"runtime": "org.freedesktop.Platform",
"runtime-version": "23.08",
"sdk": "org.freedesktop.Sdk",
"sdk-extensions": [
"org.freedesktop.Sdk.Extension.rust-stable"
],
"command": "zed",
"finish-args": [
"--socket=session-bus"
],
"build-options": {
"append-path": "/usr/lib/sdk/rust-stable/bin"
},
"modules": [
{
"name": "zed-app",
"buildsystem": "simple",
"build-options": {
"env": {
"CARGO_HOME": "/run/build/zed-app/cargo"
}
},
"build-commands": [
"cargo --offline fetch --manifest-path Cargo.toml",
"cargo --offline build --release",
"install -Dm755 ./target/release/Zed /app/bin/zed-app"
],
"sources": [
{
"type": "dir",
"path": "."
},
"flatpak-cargo-sources.json"
]
},
{
"name": "zed",
"buildsystem": "simple",
"build-options": {
"env": {
"CARGO_HOME": "/run/build/zed/cargo"
}
},
"build-commands": [
"cargo --offline fetch --manifest-path Cargo.toml",
"cargo --offline build --release --package cli --features flatpak",
"install -Dm755 ./target/release/cli /app/bin/zed",
"install -Dm644 crates/zed/resources/zed.desktop /app/share/applications/${FLATPAK_ID}.desktop",
"install -Dm644 crates/zed/resources/flatpak/${FLATPAK_ID}.metainfo.xml -t /app/share/metainfo",
"install -Dm644 crates/zed/resources/app-icon.png /app/share/icons/hicolor/512x512/apps/${FLATPAK_ID}.png",
"sed -i 's|Icon=zed|Icon=dev.zed.Zed|g' /app/share/applications/${FLATPAK_ID}.desktop"
],
"sources": [
{
"type": "dir",
"path": "."
},
"flatpak-cargo-sources.json"
]
}
]
}
10 changes: 10 additions & 0 deletions docs/src/development/linux.md
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,16 @@ cargo test --workspace

Zed has basic support for both modes. The mode is selected at runtime. If you're on wayland and want to run in X11 mode, you can set `WAYLAND_DISPLAY='' cargo run` to do so.

## Flatpak

To build & install the flatpak package locally follow the steps below:

1. Install flatpak for your distribution as outlined [here](https://flathub.org/setup).
2. Run the `script/flatpak` script to install the Freedesktop Platform and SDK.
3. Generate the sources file by running `python script/flatpak-cargo-generator.py` *from the project root directory*. This will need to be re-run if any cargo dependencies are changed (you will know to re-run when the build starts failing).
someone13574 marked this conversation as resolved.
Show resolved Hide resolved
4. Now you are ready to build & install the flatpak. Run `flatpak-builder --user --install --force-clean build dev.zed.Zed.json` from the root directory.
5. To start the application, run `flatpak run dev.zed.Zed` or locate the program in your menu.

## Troubleshooting

### Can't compile zed
Expand Down
9 changes: 9 additions & 0 deletions script/flatpak
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
#!/bin/sh

flatpak remote-add --if-not-exists flathub https://dl.flathub.org/repo/flathub.flatpakrepo
someone13574 marked this conversation as resolved.
Show resolved Hide resolved

arch=$(arch)
fd_version=23.08
flatpak install -y org.freedesktop.Platform/${arch}/${fd_version}
flatpak install -y org.freedesktop.Sdk/${arch}/${fd_version}
flatpak install -y org.freedesktop.Sdk.Extension.rust-stable/${arch}/${fd_version}
Loading
Loading